PageRenderTime 131ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/models/user.php

https://github.com/felixding/LonelyThinker
PHP | 77 lines | 56 code | 0 blank | 21 comment | 0 complexity | 262ab087d48c02fe396e26d40ef7c69f MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /* SVN FILE: $Id: user.php 39 2009-07-16 10:03:24Z $ */
  3. /**
  4. * Short description for file.
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 5
  9. *
  10. * Licensed under The BSD License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @filesource
  14. * @copyright Copyright 2007-2009, Felix Ding (http://dingyu.me)
  15. * @link http://lonelythinker.org Project LonelyThinker
  16. * @package LonelyThinker
  17. * @author $LastChangedBy: $
  18. * @version $Revision: 39 $
  19. * @modifiedby $LastChangedBy: $
  20. * @lastmodified $Date: 2009-07-16 18:03:24 +0800 (Thu, 16 Jul 2009) $
  21. * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  22. */
  23. class User extends AppModel
  24. {
  25. var $name = 'User';
  26. var $belongsTo = 'Group';
  27. var $validate = array(
  28. 'name' => array('rule'=>'notEmpty', 'message'=>'You forgot the name'),
  29. 'email' => array(
  30. 'email'=>array('rule'=>'email', 'message'=>"Make sure you have input an valid email address"),
  31. 'isUnique'=>array('rule'=>'isUnique', 'message'=>"This email address is already in use, please try another")
  32. ),
  33. 'passwd' => array(
  34. 'required' => array('rule'=>'areCharactersValid', 'message'=>'Must be 6 characters or longer'),
  35. 'length' => array('rule'=>'doPasswordsMatch', 'message'=>"Your passwords don't match")
  36. )
  37. );
  38. /**
  39. * custom validation rules
  40. */
  41. public function areCharactersValid()
  42. {
  43. if(isset($this->data['User']['passwd']) && !empty($this->data['User']['passwd'])) return preg_match('/[a-zA-Z0-9\_\-]{6,}$/i', $this->data['User']['passwd']);
  44. else return true;
  45. }
  46. /**
  47. * custom validation rules
  48. *
  49. * courtesy of http://edwardawebb.com/programming/php-programming/cakephp/complex-validation-cakephp-12
  50. */
  51. public function doPasswordsMatch()
  52. {
  53. $passed = true;
  54. //only run if there are two password feield (like NOT on the contact or signin pages..)
  55. if(isset($this->data['User']['confirmpassword']))
  56. {
  57. if($this->data['User']['passwd'] != $this->data['User']['confirmpassword'])
  58. {
  59. $this->invalidate('passwd');
  60. //they didnt condifrm password
  61. $passed = false;
  62. }
  63. else
  64. {
  65. //hash password before saving
  66. $this->data['User']['passwd']=md5($this->data['User']['passwd']);
  67. }
  68. }
  69. return $passed;
  70. }
  71. }
  72. ?>