[eluser]zulubanslee[/eluser]
No problem. I appreciate you guys taking the time to help me with this. the createaccount function seems to be working fine.
Code:
<?php
class Login extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('loginview');
}
function createaccount()
{
$this->load->library('email');
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|alpha_numeric|xss_clean');
$this->form_validation->set_rules('username', 'Username', 'callback_username_check');
$this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email');
$this->form_validation->set_rules('emailrepeat', 'Repeat Email', 'trim|required|xss_clean|valid_email|matches[email]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|matches[passwordrepeat]');
$this->form_validation->set_rules('passwordrepeat', 'Repeat password', 'trim|required|xss_clean');
if($this->form_validation->run() == FALSE)
{
$this->load->view('/loginview');
}
else
{
$username = $this->input->post('username');
$email = $this->input->post('email');
$emailrepeat = $this->input->post('emailrepeat');
$password = $this->input->post('password');
$paswordrepeat = $this->input->post('passwordrepeat');
$user_info = array($username, $email, $password);
$this->load->model('usersmodel');
//$rc is either fail message or security string to put into verification url
$rc = $this->usersmodel->createaccount($user_info);
if($rc == 'FAIL')
{
$data['status'] = $rc;
$this->load->view('verifyaccountview', TRUE);
}
else
{
$this->email->from('[email protected]', 'Your Webmaster');
$this->email->to($email);
$this->email->subject('Verify your account with examples.com');
$this->email->message("Please click this link to verify your account: http://example.com/login/verifyaccount/$rc");
//$this->email->message("Please click this link to verify your account: http://example.com/login/verifyaccount?username=$username&security;_code=$rc");
$email_rc = $this->email->send();
if($email_rc)
{
$data['status'] = 'You should be receiving an email in your inbox for verification. ';
$this->load->view('verifyaccountview', $data);
}
else
{
$data['status'] = 'Your registration was not successful';
$this->load->view('verifyaccountview', $data);
}
}
}
function verifyaccount($security_code)
{
$this->load->model('usersmodel');
$status = $this->usersmodel->verifyaccount($security_code);
$data['status'] = $status;
$this->load->view('verifyaccountview', $data);
}
}
function username_check($username)
{
$sql_verify_username = $this->db->query("SELECT username FROM users WHERE username = '$username'");
if ($sql_verify_username->num_rows() > 0)
{
$this->form_validation->set_message('username_check', 'This username is already in use.');
return FALSE;
}
else
{
return TRUE;
}
}
function loginuser()
{
/* $username = $this->input->post('username');
$password = $this->input->post('userpassword');
$this->load->model('usersmodel');
$rc = $this->usersmodel->loginuser($username, $password);
if($rc) */
}
}
?>