Guest User

Untitled

a guest
Aug 2nd, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. Controller help and functions
  2. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  3.  
  4. class Users extends CI_Controller {
  5.  
  6.  
  7. public function index()
  8. {
  9. $data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
  10. $data['pageTitle'] = "Create User";
  11. $this->load->view('frontend/assets/header', $data);
  12. $this->load->view('frontend/users', $data);
  13. $this->load->view('frontend/assets/footer');
  14. }
  15.  
  16. public function create(){
  17.  
  18. //If form validation fails load previous page with errors else do the job and insert data into db
  19.  
  20. if($this->form_validation->run('createUser') == FALSE)
  21. {
  22. $data['success'] = "";
  23. }else{
  24. $username = $this->input->post('userName');
  25. $password = $this->input->post('userPassword');
  26. $firstname = $this->input->post('userFirstName');
  27. $lastname = $this->input->post('userLastName');
  28. $email = $this->input->post('userEmail');
  29.  
  30. $passwordHash = $this->encrypt->sha1($password); // Lets encrypt the password why sha1? MD5 is for tossers
  31.  
  32. $activateCode = $this->_activateCode(10);
  33.  
  34. // If the data is correct follow through with db insert
  35.  
  36. if($this->users_model->createUser($username,$passwordHash,$firstname,$lastname,$email,$activateCode))
  37. {
  38. $data['success'] = TRUE;
  39.  
  40. redirect('frontend/users/create','refresh');
  41.  
  42. }
  43.  
  44. }
  45. $data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
  46. $data['pageTitle'] = "Create User";
  47. $this->load->view('frontend/assets/header', $data);
  48. $this->load->view('frontend/user_create', $data);
  49. $this->load->view('admin/assets/footer');
  50.  
  51. echo get_class($this);
  52. var_dump(method_exists($this, '_activateCode'));
  53. }
  54.  
  55. function _userRegEmail($activateCode,$email,$firstname,$lastname){
  56. $data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
  57. $data['companyEmail'] = $this->core_model->companyDetails()->coreCompanyEmail;
  58. $data['companyContact'] = $this->core_model->companyDetails()->coreContactName;
  59. $data['firstName'] = $firstName;
  60. $data['lastName'] = $lastname;
  61. $data['email'] = $email;
  62. $data['activateCode'] = $activateCode;
  63.  
  64. $this->email->from($this->core_model->companyDetails()->coreCompanyEmail, $this->core_model->companyDetails()->coreCompanyName);
  65. $this->email->to($email);
  66. $this->email->subject($this->core_model->companyDetails()->coreCompanyName, 'User Registration Confirmation');
  67.  
  68. $messageContent= $this->load->view('email_templates/userReg','', TRUE);
  69.  
  70. $this->email->message($messageContent);
  71.  
  72. //$this->email->send();
  73. }
  74.  
  75. function usersconfirm(){
  76.  
  77. $activateCode = $this->uri->segment(3);
  78.  
  79. if($activateCode == '')
  80. {
  81. $this->form_validation->set_message('userConfirmError', 'Sorry you did not have a correct Activation Code.');
  82. }
  83. $userConfirmed = $this->users_model->confirm_user($activateCode);
  84.  
  85. if($userConfirmed){
  86. $this->form_validation->set_message('userConfirmed', 'Thanks your account is now active you may login!');
  87. }else{
  88. $this->form_validation->set_message('userRecord', 'I am sorry we do not have any details with that Activation Code');
  89. }
  90. }
  91.  
  92. function _username_check($username)
  93. {
  94. if($this->users_model->username_taken($username))
  95. {
  96. $this->form_validation->set_message('username_check', 'Sorry the username %s is taken!');
  97. return FALSE;
  98. }else{
  99. return TRUE;
  100. }
  101. }
  102.  
  103. function _email_check($email)
  104. {
  105. if($this->users_model->email_check($email))
  106. {
  107. $this->form_validation->set_message('email_check','Sorry there is already a user with this %s');
  108. return FALSE;
  109. }else{
  110. return TRUE;
  111. }
  112.  
  113. }
  114.  
  115. function _activateCode($length)
  116. {
  117. return random_string('alnum', $length);
  118. }
  119.  
  120. }
  121.  
  122. /* End of file users.php */
  123. /* Location: ./application/controllers/users.php */
Add Comment
Please, Sign In to add comment