Reputation: 96
I am developing an application in Codeigniter, My registration process involves users filling in there details which include an email address where after successful validation the user will be sent a verification code. This process works well but the only problem is when the user finishes the form and press register it loads and redirects to the login page without informing a user the code has been sent when it redirects to the login, how can I implement this? the below code is what I have so far
Auth .php
// 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('encryption');
$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 {
}
}
}
Upvotes: 0
Views: 131
Reputation: 324
In your Register method before redirect to login
$this->session->set_flashdata('notify', 'Your code is sent');
redirect('auth/login');
in your login view - You can use Javascript with notifyJS or Bootstrap Notification to make design
if($this->session->flashdata('notify')){
echo $this->session->flashdata('notify');
}
Upvotes: 1