Guest User

Untitled

a guest
Jul 12th, 2018
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <?php if(!defined('BASEPATH')) exit('No direct script access is allowed');
  2.  
  3. /*
  4. * Upbeat Authentication Library
  5. *
  6. * User authentication... blah blah blah
  7. *
  8. * John
  9. */
  10.  
  11. class Auth
  12. {
  13. function Auth()
  14. {
  15. $this->CI = &get_instance();
  16.  
  17. // Load the language file for auth
  18. $this->CI->lang->load('libraries/auth');
  19. }
  20.  
  21. function register($username, $password, $email)
  22. {
  23. // Load encryption & email library
  24. $this->CI->load->library(array('encrypt', 'email'));
  25.  
  26. // Load the string helper
  27. $this->CI->load->helper('string');
  28.  
  29. $email_config['protocol'] = 'smtp';
  30. $email_config['smtp_host'] = 'localhost';
  31. $email_config['validate'] = 'TRUE';
  32.  
  33. // Initialize with the values set in the configuration dictionary
  34. $this->CI->email->initialize($email_config);
  35.  
  36. // Generate random activation code of length 10
  37. $activation_code = random_string('alnum', 10);
  38.  
  39. // Escape values from the database
  40. $username = $this->CI->db->escape_str($username);
  41. $password = $this->CI->db->escape_str($password);
  42. $email = $this->CI->db->escape_str($email);
  43.  
  44. // SQL-query
  45. $query = "INSERT INTO users (username, password, email, activation_code, active) VALUES(" .
  46. "'{$username}', '{$password}', '{$email}', '{$activation_code}', 0)";
  47.  
  48. // Run the query
  49. $this->CI->db->query($query);
  50.  
  51. // Send the activation e-mail to the person who just registered
  52. $this->email->from('dev@upbeat.no', 'Upbeat.no');
  53. $this->email->to($email);
  54. $email_message = $this->CI->lang->line('email_activation_message');
  55.  
  56. // Append the activation URL
  57. $email_message = '<br/>' . "<a href='" . $this->CI->config['auth_activation_url'] . $activation_code . "'>" . $this->CI->config['auth_activation_url'] . "</a>";
  58.  
  59. $this->CI->email->subject($this->CI->lang->line('email_activation_subject'));
  60.  
  61. // Send the email and check return code
  62. if($this->CI->email->send())
  63. return true;
  64. else
  65. return false;
  66. }
  67. }
Add Comment
Please, Sign In to add comment