diff --git a/application/config/routes.php b/application/config/routes.php index 990761d..3b91ad3 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -3,6 +3,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); $route['forms'] = 'Form_controller/index'; -$route['default_controller'] = 'welcome'; +$route['default_controller'] = 'home/index2'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; +$route['start'] = 'home/index'; + + diff --git a/application/controllers/Home.php b/application/controllers/Home.php new file mode 100644 index 0000000..bc84a1f --- /dev/null +++ b/application/controllers/Home.php @@ -0,0 +1,40 @@ +load->view('templates/header'); + $this->load->view('templates/footer'); + + } + + public function index1() + { + $this->load->view('templates/header'); + $this->load->view('pages/about'); + $this->load->view('templates/footer'); + + + } + public function index2() + { + $this->load->view('templates/header'); + $this->load->view('pages/formspage'); + $this->load->view('templates/footer'); + + + } + public function index3() + { + $this->load->view('templates/header'); + $this->load->view('pages/homepage'); + $this->load->view('templates/footer'); +} + +public function create_form(){ + $this->load->view('templates/forms_ui'); +} +} \ No newline at end of file diff --git a/application/controllers/Users.php b/application/controllers/Users.php new file mode 100644 index 0000000..8571e81 --- /dev/null +++ b/application/controllers/Users.php @@ -0,0 +1,122 @@ +form_validation->set_rules('username', 'Username', 'required|callback_check_username_exists'); + $this->form_validation->set_rules('email', 'Email', 'required|callback_check_email_exists'); + $this->form_validation->set_rules('password', 'Password', 'required'); + $this->form_validation->set_rules('password2', 'Confirm Passsword', 'matches[password]'); + + if ($this->form_validation->run() === FALSE) { + $this->load->view('templates/header'); + $this->load->view('users/register', $data); + $this->load->view('templates/footer'); + } else { + $enc_password = md5($this->input->post('password')); + $this->load->model('user_model'); + + $this->user_model->register($enc_password); + // $this->user_model->register(); + + + $this->session->set_flashdata('user_registered', 'You are now registered and can log in'); + redirect('start'); + } + + } + //login user + + public function login() + { + $data['title'] = 'Sign In'; + + $this->form_validation->set_rules('username', 'Username', 'required'); + $this->form_validation->set_rules('password', 'Password', 'required'); + + if ($this->form_validation->run() === FALSE) { + $this->load->view('templates/header'); + $this->load->view('users/login', $data); + $this->load->view('templates/footer'); + } else { + + // Get username + $username = $this->input->post('username'); + // Get and encrypt the password + $password = md5($this->input->post('password')); + $this->load->model('user_model'); + // Login user + $user_id = $this->user_model->login($username, $password); + + if ($user_id) { + // Create session + $user_data = array( + 'user_id' => $user_id, + 'username' => $username, + 'logged_in' => true + ); + + $this->session->set_userdata($user_data); + + // Set message + $this->session->set_flashdata('user_loggedin', 'You are now logged in'); + + redirect('start'); + } else { + // Set message + $this->session->set_flashdata('login_failed', 'Login is invalid'); + + redirect('users/login'); + } + } + } + public function logout() + { + $this->session->unset_userdata('logged_in'); + $this->session->unset_userdata('user_id'); + $this->session->unset_userdata('username'); + + $this->session->set_flashdata('user_loggedout', 'You are now logged out'); + redirect('users/login'); + + } + // check if username exists + public function check_username_exists($username) + { + $this->form_validation->set_message('check_username_exists', 'The username is taken.Please choose a different one'); + $this->load->model('user_model'); + if ($this->user_model->check_username_exists($username)) { + return true; + } else { + return false; + } + } + + public function check_email_exists($email) + { + $this->form_validation->set_message('check_email_exists', 'The email is taken.Please choose a different one'); + $this->load->model('user_model'); + + if ($this->user_model->check_email_exists($email)) { + return true; + } else { + return false; + } + } + // public function callback_user_id_exists($id) + // { + // $this->form_validation->set_message('user_id_exists', 'The ID is taken.Please choose a different one'); + // $this->load->model('user_model'); + + // if ($this->user_model->user_id_exists($id)) { + // return true; + // } else { + // return false; + // } + // } +} + + +?> \ No newline at end of file diff --git a/application/models/User_model.php b/application/models/User_model.php new file mode 100644 index 0000000..8dc3a00 --- /dev/null +++ b/application/models/User_model.php @@ -0,0 +1,49 @@ + $this->input->post('email'), +'username'=> $this->input->post('username'), +'password'=> $enc_password +); + +return $this->db->insert('users', $data); + + } + + public function login($username,$password){ + $this->db->where('username',$username); + $this->db->where('password',$password); + + $result = $this->db->get('users'); + if($result->num_rows()==1){ + return $result->row(0)->id; + } + else{ + return false; + } + } + +public function check_username_exists($username){ + $query = $this->db->get_where('users',array('username'=>$username)); + if(empty($query->row_array())){ + return true; + } +else{ + return false; +} +} + +public function check_email_exists($email){ + $query = $this->db->get_where('users',array('email'=>$email)); + if(empty($query->row_array())){ + return true; + } +else{ + return false; +} +} + +} + +?> diff --git a/application/views/pages/about.php b/application/views/pages/about.php new file mode 100644 index 0000000..e7b5546 --- /dev/null +++ b/application/views/pages/about.php @@ -0,0 +1 @@ +

This is about page

\ No newline at end of file diff --git a/application/views/pages/formspage.php b/application/views/pages/formspage.php new file mode 100644 index 0000000..f89719a --- /dev/null +++ b/application/views/pages/formspage.php @@ -0,0 +1 @@ +

Welcome to Google Forms !

\ No newline at end of file diff --git a/application/views/pages/homepage.php b/application/views/pages/homepage.php new file mode 100644 index 0000000..3efadb8 --- /dev/null +++ b/application/views/pages/homepage.php @@ -0,0 +1 @@ +

This is the home page

\ No newline at end of file diff --git a/application/views/templates/footer.php b/application/views/templates/footer.php new file mode 100644 index 0000000..ce7a3e9 --- /dev/null +++ b/application/views/templates/footer.php @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/application/views/templates/forms_ui.php b/application/views/templates/forms_ui.php index 778f189..95c4a13 100644 --- a/application/views/templates/forms_ui.php +++ b/application/views/templates/forms_ui.php @@ -1,15 +1,56 @@ + Google Form Clone - - + + - + + + + +
@@ -17,6 +58,9 @@
+ + +
@@ -24,4 +68,5 @@ + diff --git a/application/views/templates/header.php b/application/views/templates/header.php new file mode 100644 index 0000000..5aa2869 --- /dev/null +++ b/application/views/templates/header.php @@ -0,0 +1,62 @@ + + + + + + + + Blog App + + + + + + + +
+ session->flashdata('user_registered')): ?> + ' . $this->session->flashdata('user_registered') . '

'; ?> + + + + session->flashdata('login_failed')): ?> + ' . $this->session->flashdata('login_failed') . '

'; ?> + + + session->flashdata('user_loggedin')): ?> + ' . $this->session->flashdata('user_loggedin') . '

'; ?> + + + session->flashdata('user_loggedout')): ?> + ' . $this->session->flashdata('user_loggedout') . '

'; ?> + + + + +
+
\ No newline at end of file diff --git a/application/views/users/login.php b/application/views/users/login.php new file mode 100644 index 0000000..d3b1807 --- /dev/null +++ b/application/views/users/login.php @@ -0,0 +1,19 @@ + +
+
+

+ +

+
+ + +
+
+ + +
+ +
+
+ + diff --git a/application/views/users/register.php b/application/views/users/register.php new file mode 100644 index 0000000..408a2a4 --- /dev/null +++ b/application/views/users/register.php @@ -0,0 +1,27 @@ + + +
+
+

+ +
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+ +
+
+ \ No newline at end of file diff --git a/assets/css/header_styles.css b/assets/css/header_styles.css new file mode 100644 index 0000000..84c46ef --- /dev/null +++ b/assets/css/header_styles.css @@ -0,0 +1,30 @@ + +.post-date{ + background: #f4f4f4; + padding: 4px; + margin:3px 0; + display: block; +} +.post-thumb{ + width: 100%; +} +.pagination-link{ + margin:30px 0; +} + +.pagination-links strong{ + padding: 8px 13px; + margin:5px; + background: #f4f4f4; + border: 1px #ccc solid; +} + +a.pagination-link{ + padding: 8px 13px; + margin:5px; + background: #f4f4f4; + border: 1px #ccc solid; +} +.cat-delete{ + display:inline; +} \ No newline at end of file diff --git a/assets/css/styles.css b/assets/css/styles.css index 44b573a..4ddd236 100644 --- a/assets/css/styles.css +++ b/assets/css/styles.css @@ -1,5 +1,4 @@ - body { background-color: rgb(240, 235, 248); font-family: Arial, sans-serif;