PageRenderTime 57ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/controller/tool/reset.php

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