Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if(!defined('BASEPATH')) exit('No direct script access is allowed');
- /*
- * Upbeat Authentication Library
- *
- * User authentication... blah blah blah
- *
- * John
- */
- class Auth
- {
- function Auth()
- {
- $this->CI = &get_instance();
- // Load the language file for auth
- $this->CI->lang->load('libraries/auth');
- }
- function register($username, $password, $email)
- {
- // Load encryption & email library
- $this->CI->load->library(array('encrypt', 'email'));
- // Load the string helper
- $this->CI->load->helper('string');
- $email_config['protocol'] = 'smtp';
- $email_config['smtp_host'] = 'localhost';
- $email_config['validate'] = 'TRUE';
- // Initialize with the values set in the configuration dictionary
- $this->CI->email->initialize($email_config);
- // Generate random activation code of length 10
- $activation_code = random_string('alnum', 10);
- // Escape values from the database
- $username = $this->CI->db->escape_str($username);
- $password = $this->CI->db->escape_str($password);
- $email = $this->CI->db->escape_str($email);
- // SQL-query
- $query = "INSERT INTO users (username, password, email, activation_code, active) VALUES(" .
- "'{$username}', '{$password}', '{$email}', '{$activation_code}', 0)";
- // Run the query
- $this->CI->db->query($query);
- // Send the activation e-mail to the person who just registered
- $this->email->from('dev@upbeat.no', 'Upbeat.no');
- $this->email->to($email);
- $email_message = $this->CI->lang->line('email_activation_message');
- // Append the activation URL
- $email_message = '<br/>' . "<a href='" . $this->CI->config['auth_activation_url'] . $activation_code . "'>" . $this->CI->config['auth_activation_url'] . "</a>";
- $this->CI->email->subject($this->CI->lang->line('email_activation_subject'));
- // Send the email and check return code
- if($this->CI->email->send())
- return true;
- else
- return false;
- }
- }
Add Comment
Please, Sign In to add comment