PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/controller/common/reset.php

https://github.com/glcolin/travel
PHP | 102 lines | 63 code | 24 blank | 15 comment | 16 complexity | 5fa93e879c0983a202aa7e9588e02388 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. class ControllerCommonReset extends Controller {
  3. public function index() {
  4. $this->document->setTitle('Forgot and Reset Password');
  5. //Load Model
  6. $this->load->model('common/forgotten');
  7. //Alert and Warning
  8. if (isset($this->session->data['error_warning'])) {
  9. $this->data['error_warning'] = $this->session->data['error_warning'];
  10. unset($this->session->data['error_warning']);
  11. } else {
  12. $this->data['error_warning'] = '';
  13. }
  14. if (isset($this->session->data['success'])) {
  15. $this->data['success'] = $this->session->data['success'];
  16. unset($this->session->data['success']);
  17. } else {
  18. $this->data['success'] = '';
  19. }
  20. //check if GET isset
  21. if(!isset($this->request->get['u']) || !isset($this->request->get['p'])){
  22. die('<h2>ACCESS DENIED!</h2>');
  23. }
  24. //set variables
  25. $id = $this->request->get['u'];
  26. $password = $this->request->get['p'];
  27. //Check if there is an account associated with the id and password
  28. if($this->model_common_forgotten->getTotalUserInfoByIDandPassword($id,$password) != 1){
  29. die('<h2>ACCESS DENIED OR YOUR RESET URL HAS EXPIRED!</h2>');
  30. }
  31. //Set Data
  32. $this->data['id'] = $id;
  33. $this->data['password'] = $password;
  34. //render
  35. $this->template = 'common/resetpassword.tpl';
  36. $this->children = array(
  37. 'common/header',
  38. 'common/footer'
  39. );
  40. $this->response->setOutput($this->render());
  41. }
  42. public function reset() {
  43. //Load Model
  44. $this->load->model('common/forgotten');
  45. if ($this->request->server['REQUEST_METHOD'] == 'POST'){
  46. //retrieve POST vars
  47. $id = $this->request->post['userID'];
  48. $oldpassword = $this->request->post['oldpassword'];
  49. $newpassword = $this->request->post['newpassword'];
  50. $newpassword2 = $this->request->post['newpassword2'];
  51. //Check if there is an account associated with the id and password
  52. if($this->model_common_forgotten->getTotalUserInfoByIDandPassword($id,$oldpassword) != 1){
  53. die('<h2>ACCESS DENIED OR YOUR RESET URL HAS EXPIRED!</h2>');
  54. }
  55. //Check if passwords match
  56. if( $newpassword != $newpassword2 ){
  57. $this->session->data['error_warning'] = 'Passwords are not matched!';
  58. $this->redirect($this->url->link('common/reset','u='.$id.'&p='.$oldpassword));
  59. }
  60. //Check if only alphbet and digits in password
  61. if(!ctype_alnum($newpassword)){
  62. $this->session->data['error_warning'] = 'Password can only contain letters and digits!';
  63. $this->redirect($this->url->link('common/reset','u='.$id.'&p='.$oldpassword));
  64. }
  65. //Check if password's length greater or equal to 6
  66. if(!(strlen($newpassword) >= 6)){
  67. $this->session->data['error_warning'] = 'Password\'s length must be at least 6!';
  68. $this->redirect($this->url->link('common/reset','u='.$id.'&p='.$oldpassword));
  69. }
  70. //Update Password
  71. $this->model_common_forgotten->updatePassword($id,$oldpassword,$newpassword);
  72. $this->session->data['success'] = 'Password has been successfully changed!';
  73. }
  74. //return page
  75. $this->redirect($this->url->link('common/login'));
  76. }
  77. }
  78. ?>