Advertisement
Guest User

Untitled

a guest
May 17th, 2017
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('BASEPATH'))
  4. exit('No direct script access allowed');
  5.  
  6. class Login extends CI_Controller {
  7.  
  8. function __construct() {
  9. parent::__construct();
  10. }
  11.  
  12. function index() {
  13. $data['header'] = 'include/header';
  14. $data['body'] = 'login';
  15. $data['footer'] = 'include/footer';
  16.  
  17. $this->load->view('templates/frame', $data);
  18. }
  19.  
  20. function reset() {
  21. $data['header'] = 'include/header';
  22. $data['body'] = 'reset';
  23. $data['footer'] = 'include/footer';
  24.  
  25. $this->load->view('templates/frame', $data);
  26. }
  27.  
  28. public function email_check($email) {
  29. $user = $this->unit_model->get_userEmailSite_model($email);
  30. if (!$user) {
  31. $this->form_validation->set_message('email_check', 'Email does not exist.');
  32. return FALSE;
  33. } else {
  34. return TRUE;
  35. }
  36. }
  37.  
  38. public function send_links() {
  39. $email = $this->db->escape_str($this->input->post('email'));
  40.  
  41. $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
  42. $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_email_check');
  43.  
  44. if ($this->form_validation->run($this) == FALSE) {
  45. $this->reset();
  46. } else {
  47. $resetcode = random_string('alnum', 8);
  48. $userdata['password_reset_code'] = $resetcode;
  49. $this->unit_model->update_user_model($email, $userdata);
  50.  
  51. $to = $email;
  52. $subject = "Here's the link to reset your password";
  53.  
  54. $content = "
  55. <pre>
  56. Hi,
  57.  
  58. We’ve recently received a request to make changes to your password for ???.
  59. Please ignore this email if it was not you, your password will not be changed.
  60. If you wish to change your password , please click on </pre><a href='" . base_url() . "login/change_pwd?email=" . urlencode($email) . "&tok=" . $resetcode . "'>" . base_url() . "login/change_pwd?email=" . urlencode($email) . "&tok=" . $resetcode . "</a>
  61.  
  62. <pre>
  63. Sincerely
  64. ??? Team
  65. </pre>
  66. ";
  67.  
  68. $message = "";
  69. $template = "./application/views/templates/html_email_template.php";
  70.  
  71. if (file_exists($template)) {
  72. $message = file_get_contents($template);
  73. $replace_with = array(
  74. base_url() . 'assets/img/logo.png',
  75. $subject,
  76. "USER PASSWORD CHANGE REQUEST",
  77. $content,
  78. date("Y")
  79. );
  80. for ($i = 0; $i < count($replace_with); $i++) {
  81. $message = str_replace("[part" . $i . "]", $replace_with[$i], $message);
  82. }
  83. } else {
  84. foreach ($_POST as $key => $value) {
  85. $message .= "<p>" . $key . ": " . $value . "</p>";
  86. }
  87. }
  88.  
  89. $headers = "MIME-Version: 1.0" . "\r\n";
  90. $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
  91. $headers .= 'From: <noreply@shriro.com.au>' . "\r\n";
  92. $headers .= "To: <$email>\r\n";
  93.  
  94. $headers .= "Reply-To: noreply@shriro.com.au\r\n";
  95. mail($email, $subject, $message, $headers);
  96.  
  97. $this->session->set_flashdata('info', "Email sent. We’ve sent you a link to change your password.");
  98. redirect(base_url() . 'login/reset');
  99. }
  100. }
  101.  
  102. public function change_pwd() {
  103. $email = urldecode($this->input->get('email'));
  104. $tok = $this->input->get('tok');
  105.  
  106. if (strlen($email) && strlen($tok)) {
  107.  
  108. $user = $this->unit_model->get_userEmailSiteTok_model($email, $tok);
  109. if (!$user) {
  110. redirect(base_url() . "login/reset");
  111. }
  112. $data['email'] = $email;
  113. $data['tok'] = $tok;
  114.  
  115. $data['header'] = 'include/header';
  116. $data['body'] = 'change_pwd';
  117. $data['footer'] = 'include/footer';
  118.  
  119. $this->load->view('templates/frame', $data);
  120. } else {
  121. redirect(base_url() . "login/reset");
  122. }
  123. }
  124.  
  125. public function loginid_check($email) {
  126. $this->form_validation->set_message('loginid_check', 'Wrong Email');
  127. return FALSE;
  128. }
  129.  
  130. public function update_pwd() {
  131. $loginid = $this->input->post('loginid');
  132.  
  133. $tok = $this->input->post('tok');
  134. $email = $this->input->post('email');
  135. $password = $this->input->post('password');
  136.  
  137.  
  138. if (!($loginid == $email)) {
  139. $this->form_validation->set_rules('username', 'Email', 'callback_loginid_check');
  140. } else {
  141. $this->form_validation->set_rules('loginid', 'Email', 'required');
  142. }
  143.  
  144. $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
  145.  
  146. $this->form_validation->set_rules('password', 'Password', 'required|alpha_numeric');
  147. $this->form_validation->set_rules('password_confirm', 'Password Confirm', 'required|alpha_numeric|matches[password]');
  148. if ($this->form_validation->run($this) == FALSE) {
  149. $data['email'] = $email;
  150. $data['tok'] = $tok;
  151. $data['header'] = 'include/header';
  152. $data['body'] = 'change_pwd';
  153. $data['footer'] = 'include/footer';
  154.  
  155. $this->load->view('templates/frame', $data);
  156. } else {
  157. $userinfo = $this->unit_model->get_userEmailSite_model($loginid);
  158. if (!$userinfo) {
  159. die('access denied');
  160. }
  161. $user = $this->unit_model->get_userEmailSiteTok_model($userinfo[0]->email, $tok);
  162. if (!$user) {
  163. die('access denied');
  164. }
  165. $pwd_data['password'] = password_hash($password, PASSWORD_DEFAULT);
  166. $pwd_data['password_reset_code'] = null;
  167. $this->unit_model->update_user_model($userinfo[0]->email, $pwd_data);
  168. $this->session->set_flashdata('info', "New password has been successfully updated.");
  169. redirect(base_url() . "login");
  170. }
  171. }
  172.  
  173. function logout() {
  174. $this->unit_model->userlog("logout");
  175. $this->session->sess_destroy();
  176. redirect(base_url() . "login");
  177. }
  178.  
  179. function auth() {
  180. $email = $this->db->escape_str($this->input->post('email'));
  181. $password = $this->db->escape_str($this->input->post('password'));
  182. $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
  183. $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_email_check');
  184. $this->form_validation->set_rules('password', 'Password', 'required|alpha_numeric');
  185. if ($this->form_validation->run($this) == FALSE) {
  186. $this->index();
  187. } else {
  188. $auth = $this->unit_model->auth_model($email);
  189. if (password_verify($password, $auth[0]->password)) {
  190. $company = $this->unit_model->get_unit_model("heston_company", array('id =' => $auth[0]->company_id));
  191. $logged_in_data['uid'] = $auth[0]->id;
  192. $logged_in_data['email'] = $auth[0]->email;
  193. $logged_in_data['fname'] = $auth[0]->first_name;
  194. $logged_in_data['lname'] = $auth[0]->last_name;
  195. $logged_in_data['level'] = $auth[0]->access_level;
  196. $logged_in_data['company'] = $company[0]->name;
  197. $logged_in_data['cid'] = $auth[0]->company_id;
  198.  
  199. $this->session->set_userdata('logged_in_data', $logged_in_data);
  200.  
  201. $this->session->set_userdata('location', 0);
  202.  
  203. $this->unit_model->userlog("login");
  204.  
  205. redirect(base_url() . "dashboard");
  206. } else {
  207. $this->session->set_flashdata('error', "Wrong login combination.");
  208. redirect(base_url() . 'login');
  209. }
  210. }
  211. }
  212.  
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement