PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/controller/tool/reset.php

https://github.com/glcolin/institute
PHP | 89 lines | 57 code | 20 blank | 12 comment | 14 complexity | 47bbe45f65e397e42ff1ef8cebfb3b56 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. class ControllerToolReset extends Controller {
  3. public function index() {
  4. if (!$this->user->isLogged()){
  5. //redirect to common/login
  6. $this->redirect($this->url->link('common/login'));
  7. }
  8. $this->document->setTitle('Reset Password');
  9. //Alert and Warning
  10. if (isset($this->session->data['error_warning'])) {
  11. $this->data['error_warning'] = $this->session->data['error_warning'];
  12. unset($this->session->data['error_warning']);
  13. } else {
  14. $this->data['error_warning'] = '';
  15. }
  16. if (isset($this->session->data['success'])) {
  17. $this->data['success'] = $this->session->data['success'];
  18. unset($this->session->data['success']);
  19. } else {
  20. $this->data['success'] = '';
  21. }
  22. //render
  23. $this->template = 'tool/reset.tpl';
  24. $this->children = array(
  25. 'common/header',
  26. 'common/footer'
  27. );
  28. $this->response->setOutput($this->render());
  29. }
  30. public function reset() {
  31. //check if login
  32. if (!$this->user->isLogged()){
  33. //redirect to common/login
  34. $this->redirect($this->url->link('common/login'));
  35. }
  36. if ($this->request->server['REQUEST_METHOD'] == 'POST'){
  37. //retrieve POST vars
  38. $oldPassword = $this->request->post['oldpassword'];
  39. $newpassword = $this->request->post['newpassword'];
  40. $newpassword2 = $this->request->post['newpassword2'];
  41. //Check if Old password is correct
  42. if( md5($oldPassword) != $this->user->getPassword()){
  43. $this->session->data['error_warning'] = 'Incorrect Password';
  44. $this->redirect($this->url->link('tool/reset'));
  45. }
  46. //Check if passwords match
  47. if( $newpassword != $newpassword2 ){
  48. $this->session->data['error_warning'] = 'Passwords are not matched!';
  49. $this->redirect($this->url->link('tool/reset'));
  50. }
  51. //Check if only alphbet and digits in password
  52. if(!ctype_alnum($newpassword)){
  53. $this->session->data['error_warning'] = 'Password can only contain letters and digits!';
  54. $this->redirect($this->url->link('tool/reset'));
  55. }
  56. //Check if password's length greater or equal to 6
  57. if(!(strlen($newpassword) >= 6)){
  58. $this->session->data['error_warning'] = 'Password\'s length must be at least 6!';
  59. $this->redirect($this->url->link('tool/reset'));
  60. }
  61. //Update Password
  62. $this->user->updatePassword($newpassword);
  63. $this->session->data['success'] = 'Password has been successfully changed!';
  64. }
  65. //return page
  66. $this->redirect($this->url->link('tool/reset'));
  67. }
  68. }
  69. ?>