Create a Full Featured Registration and Login Module in CodeIgniter
Registration and Login is one of the primary module in any data management system. In this tutorial, we will explain how to create user Registration authentication and user Login system using the CodeIgniter with activation process. Once active the user can login, a reset option is available to reset the password and etc. Also Using
password_hash()
and password_verify()
algorithm.Features of Registration and Login Module
- Registration form
- Login form
- Forgot password
- Logout feature
- password_hash() algorithm
- password_verify() algorithm
- Change Password feature
- Email authentication for registration process
- Using SMTP (Simple Mail Transfer Protocol)
- Forms validations on login and registration panel
- On success the module redirects to the user profile page
Step 1: Create Database
For this tutorial, you need a MySQL database with the following table:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php //Table structure for table import CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key', `first_name` varchar(100) NOT NULL COMMENT 'First Name', `last_name` varchar(100) NOT NULL COMMENT 'Last Name', `user_name` varchar(100) NOT NULL COMMENT 'Last Name', `email` varchar(255) NOT NULL COMMENT 'Email Address', `contact_no` VARCHAR(16) NOT NULL COMMENT 'Contact No', `password` varchar(255) NOT NULL COMMENT 'Password', `address` TEXT NOT NULL COMMENT 'Address', `dob` varchar(15) NOT NULL COMMENT 'Date Of Birth', `verification_code` varchar(255) NOT NULL COMMENT 'verification Code', `created_date` varchar(12) NOT NULL COMMENT 'created timestamp', `modified_date` varchar(12) NOT NULL COMMENT 'modified timestamp', `status` char(1) NOT NULL COMMENT '0=pending, 1=active, 2=delete', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='datatable demo table' AUTO_INCREMENT=1; ?> |
Step 2: Configure Database access
Update the file
application/config/database.php
in your CodeIgniter installation with your database info:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php // configure database $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'XXXX', // Your username if required. 'password' => 'XXXX', // Your password if any. 'database' => 'XXXX_DB', // Your database name. 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE ); ?> |
Step 3: Update routes file
Add code the file
application/config/routes.php
in your CodeIgniter installation with you controller’s name.
1 2 3 4 5 6 7 8 9 |
<?php // create routes path $route['signup'] = 'auth/register'; $route['signin'] = 'auth/login'; $route['profile'] = 'auth/index'; $route['setting'] = 'auth/changepwd'; $route['profile/edit'] = 'auth/edit'; $route['forgotpwd'] = 'auth/forgotpassword'; ?> |
Step 4: Update autoload file
In the file
application/config/autoload.php
you can configure the default libraries you want to load in all your controllers. For our case, we’ll load the database and session libraries, since we want to handle user sessions, and also the URL helper for internal link generation.
1 2 3 4 5 6 |
<?php // load libraries $autoload['libraries'] = array('database', 'session', 'table', 'upload'); // load helper $autoload['helper'] = array('url', 'form', 'html', 'date'); ?> |
Step 5: Create Model
Create a model file named
Auth_model.php
inside “application/models”
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
<?php /* * *** * Version: V1.0.1 * * Description of Auth model * * @author TechArise Team * * @email info@techarise.com * * *** */ if (!defined('BASEPATH')) exit('No direct script access allowed'); class Auth_model extends CI_Model { // Declaration of a variables private $_userID; private $_userName; private $_firstName; private $_lastName; private $_email; private $_password; private $_contactNo; private $_address; private $_dob; private $_verificationCode; private $_timeStamp; private $_status; //Declaration of a methods public function setUserID($userID) { $this->_userID = $userID; } public function setUserName($userName) { $this->_userName = $userName; } public function setFirstname($firstName) { $this->_firstName = $firstName; } public function setLastName($lastName) { $this->_lastName = $lastName; } public function setEmail($email) { $this->_email = $email; } public function setContactNo($contactNo) { $this->_contactNo = $contactNo; } public function setPassword($password) { $this->_password = $password; } public function setAddress($address) { $this->_address = $address; } public function setDOB($dob) { $this->_dob = $dob; } public function setVerificationCode($verificationCode) { $this->_verificationCode = $verificationCode; } public function setTimeStamp($timeStamp) { $this->_timeStamp = $timeStamp; } public function setStatus($status) { $this->_status = $status; } //create new user public function create() { $hash = $this->hash($this->_password); $data = array( 'user_name' => $this->_userName, 'first_name' => $this->_firstName, 'last_name' => $this->_lastName, 'email' => $this->_email, 'password' => $hash, 'contact_no' => $this->_contactNo, 'address' => $this->_address, 'dob' => $this->_dob, 'verification_code' => $this->_verificationCode, 'created_date' => $this->_timeStamp, 'modified_date' => $this->_timeStamp, 'status' => $this->_status ); $this->db->insert('users', $data); if (!empty($this->db->insert_id()) && $this->db->insert_id() > 0) { return TRUE; } else { return FALSE; } } // login method and password verify function login() { $this->db->select('id as user_id, user_name, email, password'); $this->db->from('users'); $this->db->where('email', $this->_userName); $this->db->where('verification_code', 1); $this->db->where('status', 1); //{OR} $this->db->or_where('user_name', $this->_userName); $this->db->where('verification_code', 1); $this->db->where('status', 1); $this->db->limit(1); $query = $this->db->get(); if ($query->num_rows() == 1) { $result = $query->result(); foreach ($result as $row) { if ($this->verifyHash($this->_password, $row->password) == TRUE) { return $result; } else { return FALSE; } } } else { return FALSE; } } //update user public function update() { $data = array( 'first_name' => $this->_firstName, 'last_name' => $this->_lastName, 'contact_no' => $this->_contactNo, 'address' => $this->_address, 'dob' => $this->_dob, 'modified_date' => $this->_timeStamp, ); $this->db->where('id', $this->_userID); $msg = $this->db->update('users', $data); if ($msg == 1) { return TRUE; } else { return FALSE; } } //change password public function changePassword() { $hash = $this->hash($this->_password); $data = array( 'password' => $hash, ); $this->db->where('id', $this->_userID); $msg = $this->db->update('users', $data); if ($msg == 1) { return TRUE; } else { return FALSE; } } // get User Detail public function getUserDetails() { $this->db->select(array('m.id as user_id', 'CONCAT(m.first_name, " ", m.last_name) as full_name', 'm.first_name', 'm.last_name', 'm.email', 'm.contact_no', 'm.address', 'm.dob')); $this->db->from('users as m'); $this->db->where('m.id', $this->_userID); $query = $this->db->get(); if ($query->num_rows() > 0) { return $query->row_array(); } else { return FALSE; } } // update Forgot Password public function updateForgotPassword() { $hash = $this->hash($this->_password); $data = array( 'password' => $hash, ); $this->db->where('email', $this->_email); $msg = $this->db->update('users', $data); if ($msg > 0) { return TRUE; } else { return FALSE; } } // get Email Address public function activate() { $data = array( 'status' => 1, 'verification_code' => 1, ); $this->db->where('verification_code', $this->_verificationCode); $msg = $this->db->update('users', $data); if ($msg == 1) { return TRUE; } else { return FALSE; } } // password hash public function hash($password) { $hash = password_hash($password, PASSWORD_DEFAULT); return $hash; } // password verify public function verifyHash($password, $vpassword) { if (password_verify($password, $vpassword)) { return TRUE; } else { return FALSE; } } } ?> |
Step 6: Create controllers
Create a controllers file named
Auth.php
inside “application/controllers”
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
<?php /* * *** * Version: V1.0.1 * * Description of Auth Controller * * @author TechArise Team * * @email info@techarise.com * * *** */ if (!defined('BASEPATH')) exit('No direct script access allowed'); class Auth extends MY_Controller { public function __construct() { parent::__construct(); //load model $this->load->model('Auth_model', 'auth'); $this->load->model('Mail', 'mail'); $this->load->library('form_validation'); } // user profile public function index() { if ($this->session->userdata('ci_session_key_generate') == FALSE) { redirect('signin'); // the user is not logged in, redirect them! } else { $data = array(); $data['metaDescription'] = 'User Profile'; $data['metaKeywords'] = 'User Profile'; $data['title'] = "User Profile - TechArise"; $data['breadcrumbs'] = array('Profile' => '#'); $sessionArray = $this->session->userdata('ci_seesion_key'); $this->auth->setUserID($sessionArray['user_id']); $data['userInfo'] = $this->auth->getUserDetails(); $this->page_construct('auth/index', $data); } } // registration method public function register() { $data = array(); $data['metaDescription'] = 'New User Registration'; $data['metaKeywords'] = 'New User Registration'; $data['title'] = "Registration - TechArise"; $data['breadcrumbs'] = array('Registration' => '#'); $this->page_construct('auth/register', $data); } // edit method public function edit() { if ($this->session->userdata('ci_session_key_generate') == FALSE) { redirect('signin'); // the user is not logged in, redirect them! } else { $data = array(); $data['metaDescription'] = 'Update Profile'; $data['metaKeywords'] = 'Update Profile'; $data['title'] = "Update Profile - TechArise"; $data['breadcrumbs'] = array('Update Profile' => '#'); $sessionArray = $this->session->userdata('ci_seesion_key'); $this->auth->setUserID($sessionArray['user_id']); $data['userInfo'] = $this->auth->getUserDetails(); $this->page_construct('auth/edit', $data); } } // login method public function login() { if (!empty($this->input->get('usid'))) { $verificationCode = urldecode(base64_decode($this->input->get('usid'))); $this->auth->setVerificationCode($verificationCode); $this->auth->activate(); } $data = array(); $data['metaDescription'] = 'Login'; $data['metaKeywords'] = 'Login'; $data['title'] = "Login - TechArise"; $data['breadcrumbs'] = array('Login' => '#'); $this->page_construct('auth/login', $data); } // edit method public function changepwd() { if ($this->session->userdata('ci_session_key_generate') == FALSE) { redirect('signin'); // the user is not logged in, redirect them! } else { $data = array(); $data['metaDescription'] = 'New User Registration'; $data['metaKeywords'] = 'Change Password'; $data['title'] = "Change Password - TechArise"; $data['breadcrumbs'] = array('Change Password' => '#'); $this->page_construct('auth/changepwd', $data); } } //forgot password method public function forgotpassword() { if ($this->session->userdata('ci_session_key_generate') == TRUE) { redirect('profile'); // the user is logged in, redirect them! } else { $data['metaDescription'] = 'Forgot Password'; $data['metaKeywords'] = 'Member, forgot password'; $data['title'] = "Forgot Password - SoOLEGAL"; $data['breadcrumbs'] = array('Forgot Password' => '#'); $this->page_construct('auth/forgotpwd', $data); } } // action create user method public function actionCreate() { $this->form_validation->set_rules('first_name', 'First Name', 'required'); $this->form_validation->set_rules('last_name', 'Last Name', 'required'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]'); $this->form_validation->set_rules('contact_no', 'Contact No', 'required|regex_match[/^[0-9]{10}$/]'); $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[8]'); $this->form_validation->set_rules('confirm_password', 'Password Confirmation', 'trim|required|matches[password]'); $this->form_validation->set_rules('address', 'Address', 'required'); $this->form_validation->set_rules('dob', 'Date of Birth(DD-MM-YYYY)', 'required'); if ($this->form_validation->run() == FALSE) { $this->register(); } else { $firstName = $this->input->post('first_name'); $lastName = $this->input->post('last_name'); $email = $this->input->post('email'); $password = $this->input->post('password'); $contactNo = $this->input->post('contact_no'); $dob = $this->input->post('dob'); $address = $this->input->post('address'); $timeStamp = time(); $status = 0; $verificationCode = uniqid(); $verificationLink = site_url() . 'signin?usid=' . urlencode(base64_encode($verificationCode)); $userName = $this->mail->generateUnique('users', trim($firstName . $lastName), 'user_name', NULL, NULL); $this->auth->setUserName($userName); $this->auth->setFirstName(trim($firstName)); $this->auth->setLastName(trim($lastName)); $this->auth->setEmail($email); $this->auth->setPassword($password); $this->auth->setContactNo($contactNo); $this->auth->setAddress($address); $this->auth->setDOB($dob); $this->auth->setVerificationCode($verificationCode); $this->auth->setTimeStamp($timeStamp); $this->auth->setStatus($status); $chk = $this->auth->create(); if ($chk === TRUE) { $this->load->library('encrypt'); $mailData = array('topMsg' => 'Hi', 'bodyMsg' => 'Congratulations, Your registration has been successfully submitted.', 'thanksMsg' => SITE_DELIMETER_MSG, 'delimeter' => SITE_DELIMETER, 'verificationLink' => $verificationLink); $this->mail->setMailTo($email); $this->mail->setMailFrom(MAIL_FROM); $this->mail->setMailSubject('User Registeration!'); $this->mail->setMailContent($mailData); $this->mail->setTemplateName('verification'); $this->mail->setTemplatePath('mailTemplate/'); $chkStatus = $this->mail->sendMail(MAILING_SERVICE_PROVIDER); if ($chkStatus === TRUE) { redirect('signin'); } else { echo 'Error'; } } else { } } } // action update user public function editUser() { $this->form_validation->set_rules('first_name', 'First Name', 'required'); $this->form_validation->set_rules('last_name', 'Last Name', 'required'); $this->form_validation->set_rules('contact_no', 'Contact No', 'required|regex_match[/^[0-9]{10}$/]'); $this->form_validation->set_rules('address', 'Address', 'required'); $this->form_validation->set_rules('dob', 'Date of Birth(DD-MM-YYYY)', 'required'); if ($this->form_validation->run() == FALSE) { $this->edit(); } else { $firstName = $this->input->post('first_name'); $lastName = $this->input->post('last_name'); $contactNo = $this->input->post('contact_no'); $dob = $this->input->post('dob'); $address = $this->input->post('address'); $timeStamp = time(); $sessionArray = $this->session->userdata('ci_seesion_key'); $this->auth->setUserID($sessionArray['user_id']); $this->auth->setFirstName(trim($firstName)); $this->auth->setLastName(trim($lastName)); $this->auth->setContactNo($contactNo); $this->auth->setAddress($address); $this->auth->setDOB($dob); $this->auth->setTimeStamp($timeStamp); $status = $this->auth->update(); if ($status == TRUE) { redirect('profile'); } } } // action login method function doLogin() { // Check form validation $this->load->library('form_validation'); $this->form_validation->set_rules('user_name', 'User Name/Email', 'trim|required'); $this->form_validation->set_rules('password', 'Password', 'trim|required'); if ($this->form_validation->run() == FALSE) { //Field validation failed. User redirected to login page $this->login; } else { $sessArray = array(); //Field validation succeeded. Validate against database $username = $this->input->post('user_name'); $password = $this->input->post('password'); $this->auth->setUserName($username); $this->auth->setPassword($password); //query the database $result = $this->auth->login(); if (!empty($result) && count($result) > 0) { foreach ($result as $row) { $authArray = array( 'user_id' => $row->user_id, 'user_name' => $row->user_name, 'email' => $row->email ); $this->session->set_userdata('ci_session_key_generate', TRUE); $this->session->set_userdata('ci_seesion_key', $authArray); } redirect('profile'); } else { redirect('signin?msg=1'); } } } public function actionChangePwd() { $this->form_validation->set_rules('change_pwd_password', 'Password', 'trim|required|min_length[8]'); $this->form_validation->set_rules('change_pwd_confirm_password', 'Password Confirmation', 'trim|required|matches[change_pwd_password]'); if ($this->form_validation->run() == FALSE) { $this->changepwd(); } else { $change_pwd_password = $this->input->post('change_pwd_password'); $sessionArray = $this->session->userdata('ci_seesion_key'); $this->auth->setUserID($sessionArray['user_id']); $this->auth->setPassword($change_pwd_password); $status = $this->auth->changePassword(); if ($status == TRUE) { redirect('profile'); } } } //action forgot password method public function actionForgotPassword() { $this->form_validation->set_rules('forgot_email', 'Your Email', 'trim|required|valid_email'); if ($this->form_validation->run() == FALSE) { //Field validation failed. User redirected to Forgot Password page $this->forgotpassword(); } else { $login = site_url() . 'signin'; $email = $this->input->post('forgot_email'); $this->auth->setEmail($email); $pass = $this->generateRandomPassword(8); $this->auth->setPassword($pass); $status = $this->auth->updateForgotPassword(); if ($status == TRUE) { $this->load->library('encrypt'); $mailData = array('topMsg' => 'Hi', 'bodyMsg' => 'Your password has been reset successfully!.', 'thanksMsg' => SITE_DELIMETER_MSG, 'delimeter' => SITE_DELIMETER, 'loginLink' => $login, 'pwd' => $pass, 'username' => $email); $this->mail->setMailTo($email); $this->mail->setMailFrom(MAIL_FROM); $this->mail->setMailSubject('Forgot Password!'); $this->mail->setMailContent($mailData); $this->mail->setTemplateName('sendpwd'); $this->mail->setTemplatePath('mailTemplate/'); $chkStatus = $this->mail->sendMail(MAILING_SERVICE_PROVIDER); if ($chkStatus === TRUE) { redirect('forgotpwd?msg=2'); } else { redirect('forgotpwd?msg=1'); } } else { redirect('forgotpwd?msg=1'); } } } //generate random password public function generateRandomPassword($length = 10) { $alphabets = range('a', 'z'); $numbers = range('0', '9'); $final_array = array_merge($alphabets, $numbers); $password = ''; while ($length--) { $key = array_rand($final_array); $password .= $final_array[$key]; } return $password; } //logout method public function logout() { $this->session->unset_userdata('ci_seesion_key'); $this->session->unset_userdata('ci_session_key_generate'); $this->session->sess_destroy(); $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0"); $this->output->set_header("Pragma: no-cache"); redirect('signin'); } } ?> |
Step 7: Create mailing class with
SMTP
(Simple Mail Transfer Protocol) functionalityCreate a model file named
"Mail.php"
inside “application/models”
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
<?php /* * *** * Version: V1.0.1 * * Description of Mail model * * @author TechArise Team * * @email info@techarise.com * * *** */ if (!defined('BASEPATH')) exit('No direct script access allowed'); class Mail extends CI_Model { // Declaration of a variables private $_mailTo; private $_mailFrom; private $_mailSubject; private $_mailContent; private $_templateName; private $_templatePath; //Declaration of a methods public function setMailTo($mailTo) { $this->_mailTo = $mailTo; } public function setMailFrom($mailFrom) { $this->_mailFrom = $mailFrom; } public function setMailSubject($mailSubject) { $this->_mailSubject = $mailSubject; } public function setMailContent($mailContent) { $this->_mailContent = $mailContent; } public function setTemplateName($templateName) { $this->_templateName = $templateName; } public function setTemplatePath($templatePath) { $this->_templatePath = $templatePath; } // smtpMail public function sendMail($data) { //Load email library $this->load->library('email'); if (!empty($data) && $data == 'smtp') { //SMTP & mail configuration $config = array( 'protocol' => PROTOCOL, 'smtp_host' => SMTP_HOST, 'smtp_port' => SMTP_PORT, 'smtp_user' => SMTP_USER, 'smtp_pass' => SMTP_PASS, 'mailtype' => MAILTYPE, 'charset' => CHARSET, ); $fullPath = $this->_templatePath . $this->_templateName; $this->email->initialize($config); $this->email->set_mailtype(MAILTYPE); $this->email->set_newline("\r\n"); //Email content $mailMessage = $this->load->view($fullPath, $this->_mailContent, TRUE); $this->email->to($this->_mailTo); $this->email->from($this->_mailFrom, FROM_TEXT); $this->email->subject($this->_mailSubject); $this->email->message($mailMessage); //Send email if ($this->email->send()) { return TRUE; } else { return FALSE; } } } // generate Unique UserName public function generateUnique($tableName, $string, $field, $key = NULL, $value = NULL) { $slug = preg_replace('/[^A-Za-z0-9-]+/', '', strtolower($string)); $i = 0; $params = array(); $params[$field] = $slug; if ($key) $params["$key !="] = $value; while ($this->db->where($params)->get($tableName)->num_rows()) { if (!preg_match('/-{1}[0-9]+$/', $slug)) $slug .= '-' . ++$i; else $slug = preg_replace('/[0-9]+$/', ++$i, $slug); $params [$field] = $slug; } return $slug; } } ?> |
Step 8: Create views for registration
Create a views file named
register.php
inside “application/views/auth”
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
<div class="row page-content"> <div class="col-lg-12"> <h2>Register Form</h2> <?php if (validation_errors()) { ?> <div class="alert alert-danger"> <?php echo validation_errors(); ?> </div> <?php } ?> <?php echo form_open('auth/actionCreate'); ?> <div class="row"> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-user-o"></i> </span> <input type="text" name="first_name" class="form-control" id="first-name" placeholder="First Name"> </div> </div> </div> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-user-o"></i> </span> <input type="text" name="last_name" class="form-control" id="last-name" placeholder="Last Name"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-envelope"></i> </span> <input type="text" name="email" class="form-control" id="email" placeholder="Email"> </div> </div> </div> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-phone"></i> </span> <input type="text" name="contact_no" class="form-control" id="contact-no" placeholder="Contact No"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-lock"></i> </span> <input type="password" name="password" class="form-control" id="password" placeholder="Password"> </div> </div> </div> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-lock"></i> </span> <input type="password" name="confirm_password" class="form-control" id="confirm-password" placeholder="Confirm Password"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-map-marker"></i> </span> <input type="text" name="address" class="form-control" id="address" placeholder="Address"> </div> </div> </div> <div class='col-lg-6'> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-calendar"></i> </span> <input type='text' class="form-control" name="dob" id="dob" placeholder="DOB: DD-MM-YYYY"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="form-group pull-right"> <span class="small ">Already Registered User?</span> <a href="<?php print site_url(); ?>signin" class="small">Click here to login</a> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="form-group pull-right"> <button type="submit" id="register" class="btn btn-info">Register</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> |
Step 9: Create views for login
Create a views file named
login.php
inside “application/views/auth”
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
<div class="row page-content"> <div class="col-lg-12"> <h2>Login Form</h2> <?php if (validation_errors()) { ?> <div class="alert alert-danger"> <?php echo validation_errors(); ?> </div> <?php } ?> <?php if (!empty($this->input->get('msg')) && $this->input->get('msg') == 1) { ?> <div class="alert alert-danger"> Please Enter Your Valid Information. </div> <?php } ?> <?php echo form_open('auth/doLogin'); ?> <div class="row"> <div class="col-lg-12"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-user"></i> </span> <input type="text" name="user_name" class="form-control" id="username" placeholder="User Name/Email"> </div> </div> </div> <div class="col-lg-12"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-lock"></i> </span> <input type="password" name="password" class="form-control" id="password" placeholder="Password"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="form-group"> <span class="small pull-left">Not a user yet? </span><a href="<?php print site_url(); ?>signup" class="small pull-left"> Register Now</a> <a href="<?php print site_url(); ?>forgotpwd" class="small pull-right">Forgot password?</a> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="form-group pull-right"> <button type="submit" id="login" class="btn btn-info">Login</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> |
Step 10: Create views for Forgot Password
Create a views file named
forgotpwd.php
inside “application/views/auth”
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<div class="row page-content"> <div class="col-lg-12"> <h2>Forgot Password</h2> <?php if (validation_errors()) { ?> <div class="alert alert-danger"> <?php echo validation_errors(); ?> </div> <?php } ?> <?php if (!empty($this->input->get('msg')) && $this->input->get('msg') == 1) { ?> <div class="alert alert-danger"> Please Enter Your Valid Information. </div> <?php } elseif (!empty($this->input->get('msg')) && $this->input->get('msg') == 2) { ?> <div class="alert alert-success"> Your password has been reset successfully. Please check your email. </div> <?php } ?> <?php echo form_open('auth/actionForgotPassword'); ?> <div class="row"> <div class="col-lg-12"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-envelope"></i> </span> <input type="text" name="forgot_email" class="form-control" id="email-forgot-pwd" placeholder="Email"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="form-group pull-right"> <span class="small pull-left">Not a user yet? </span><a href="<?php print site_url(); ?>signup" class="small pull-left"> Register Now</a> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="form-group pull-right"> <button type="submit" id="login" class="btn btn-info">Send</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> |
Step 11: Create views for profile page
Create a views file named
index.php
inside “application/views/auth”
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<div class="row page-content"> <div class="col-lg-12 text-right"> <a class="btn btn-info btn-xs" href="<?php print site_url() ?>profile/edit"><i class="fa fa-user"></i> Edit</a> <a class="btn btn-warning btn-xs" href="<?php print site_url() ?>setting"><i class="fa fa-gear"></i> Settings</a> <a class="btn btn-danger btn-xs" href="<?php print site_url() ?>auth/logout"><i class="fa fa-power-off"></i> Log Out</a> <div class="row"> <div class="col-lg-12 col-sm-12"> <div class="card hovercard"> <div class="cardheader"> <div class="avatar"> <img alt="<?php print $this->session->userdata('user_name'); ?>" src="<?php print HTTP_IMAGES_PATH; ?>user-default.jpg"> </div> </div> <div class="card-body info"> <div class="title"> <a href="<?php print site_url() ?>profile"><?php print $userInfo['full_name']; ?></a> </div> <div class="desc"> <a target="_blank" rel="noopener">"><?php PRINT APPLICATION_NAME; ?></a></div> <div class="desc"><?php print $userInfo['email']; ?>, <?php print $userInfo['contact_no']; ?></div> <div class="desc"><?php print $userInfo['address']; ?></div> </div> <div class="card-footer bottom"> <a class="btn btn-primary btn-twitter btn-sm" href="<?php print site_url(); ?>"> <i class="fa fa-twitter"></i> </a> <a class="btn btn-danger btn-sm" rel="publisher" href="<?php print site_url(); ?>"> <i class="fa fa-google-plus"></i> </a> <a class="btn btn-primary btn-sm" rel="publisher" href="<?php print site_url(); ?>"> <i class="fa fa-facebook"></i> </a> </div> </div> </div> </div> </div> </div> |
Step 12: Create views for edit profile page
Create a views file named
edit.php
inside “application/views/auth”
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
<div class="row page-content"> <div class="col-lg-12"> <h2>Profile</h2> <?php if (validation_errors()) { ?> <div class="alert alert-danger"> <?php echo validation_errors(); ?> </div> <?php } ?> <?php echo form_open('auth/editUser'); ?> <div class="row"> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-user-o"></i> </span> <input type="text" name="first_name" class="form-control" id="first-name" placeholder="First Name" value="<?php print $userInfo['first_name']; ?>"> </div> </div> </div> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-user-o"></i> </span> <input type="text" name="last_name" class="form-control" id="last-name" placeholder="Last Name" value="<?php print $userInfo['last_name']; ?>"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-envelope"></i> </span> <input type="text" disabled="disabled" name="email" class="form-control" id="email" placeholder="Email" value="<?php print $userInfo['email']; ?>"> </div> </div> </div> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-phone"></i> </span> <input type="text" name="contact_no" class="form-control" id="contact-no" placeholder="Contact No" value="<?php print $userInfo['contact_no']; ?>"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-map-marker"></i> </span> <input type="text" name="address" class="form-control" id="address" placeholder="Address" value="<?php print $userInfo['address']; ?>"> </div> </div> </div> <div class='col-lg-6'> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-calendar"></i> </span> <input type='text' class="form-control" name="dob" id="dob" placeholder="DOB: DD-MM-YYYY" value="<?php print $userInfo['dob']; ?>"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="form-group pull-right"> <button type="submit" id="register" class="btn btn-info">Register</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> |
Step 13: Create views for change password page
Create a views file named
changepwd.php
inside “application/views/auth”
folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<div class="row page-content"> <div class="col-lg-12"> <h2>Setting</h2> <?php if (validation_errors()) { ?> <div class="alert alert-danger"> <?php echo validation_errors(); ?> </div> <?php } ?> <?php if (!empty($this->input->get('msg')) && $this->input->get('msg') == 1) { ?> <div class="alert alert-danger"> Please Enter Your Valid Information. </div> <?php } ?> <?php echo form_open('auth/actionChangePwd'); ?> <div class="row"> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-lock"></i> </span> <input type="password" name="change_pwd_password" class="form-control" id="change-pwd-password" placeholder="Password"> </div> </div> </div> <div class="col-lg-6"> <div class="form-group"> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-lock"></i> </span> <input type="password" name="change_pwd_confirm_password" class="form-control" id="change-pwd-confirm-password" placeholder="Confirm Password"> </div> </div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="form-group pull-right"> <button type="submit" id="chnage-pwd" class="btn btn-warning">Save</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> |