| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Chipotle Software TM |
|---|
| 4 | * Manuel Montoya 2002-2008 |
|---|
| 5 | * GPLv3 manuel<arroba>mononeurona<punto>org |
|---|
| 6 | * @version 0.3 |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | class User extends AppModel { |
|---|
| 10 | |
|---|
| 11 | public $belongsTo = array( |
|---|
| 12 | 'Group' => array( |
|---|
| 13 | 'className' => 'Group' |
|---|
| 14 | )); |
|---|
| 15 | |
|---|
| 16 | /* public $hasAndBelongsToMany = array('Vclassroom' => |
|---|
| 17 | array('className' => 'Vclassroom', |
|---|
| 18 | 'joinTable' => 'users_vclassrooms', |
|---|
| 19 | 'foreignKey' => 'user_id', |
|---|
| 20 | 'associationForeignKey'=> 'vclassroom_id', |
|---|
| 21 | 'conditions' => '', |
|---|
| 22 | 'order' => '', |
|---|
| 23 | 'limit' => '', |
|---|
| 24 | 'unique' => true, |
|---|
| 25 | 'finderQuery' => '', |
|---|
| 26 | 'deleteQuery' => '', |
|---|
| 27 | ) |
|---|
| 28 | ); */ |
|---|
| 29 | |
|---|
| 30 | public $hasMany = array( |
|---|
| 31 | "Entry" => array( |
|---|
| 32 | "className" => "Entry" |
|---|
| 33 | ), |
|---|
| 34 | "Category" => array( |
|---|
| 35 | "className" => "Category" |
|---|
| 36 | ), |
|---|
| 37 | "Faq" => array( |
|---|
| 38 | "className" => "Faq" |
|---|
| 39 | ), |
|---|
| 40 | "Acquaintance" => array( |
|---|
| 41 | "className" => "Acquaintance" |
|---|
| 42 | ), |
|---|
| 43 | "Lesson" => array( |
|---|
| 44 | "className" => "Lesson" |
|---|
| 45 | ), |
|---|
| 46 | "Vclassroom" => array( |
|---|
| 47 | "className" => "Vclassroom" |
|---|
| 48 | ), |
|---|
| 49 | "Confirm" => array( |
|---|
| 50 | "className" => "Confirm" |
|---|
| 51 | ) |
|---|
| 52 | ); |
|---|
| 53 | |
|---|
| 54 | public $notNow = array('hasMany'=>array('Entry', 'Category', 'Acquaintance', 'Faq', 'Glossary', 'Vclassroom', 'Lesson', 'Confirm', 'Vclassroom')); |
|---|
| 55 | |
|---|
| 56 | public $validate = array( |
|---|
| 57 | 'login' => VALID_NOT_EMPTY, |
|---|
| 58 | 'pwd' => VALID_NOT_EMPTY, |
|---|
| 59 | 'username' => VALID_NOT_EMPTY, |
|---|
| 60 | 'name' => VALID_NOT_EMPTY, |
|---|
| 61 | 'email' => VALID_EMAIL |
|---|
| 62 | ); |
|---|
| 63 | /* |
|---|
| 64 | I will work on this later |
|---|
| 65 | public $validate = array( |
|---|
| 66 | 'username' => array('rule' => 'alphanumeric', |
|---|
| 67 | 'required' => true, |
|---|
| 68 | 'message' => 'Please enter a username'), |
|---|
| 69 | 'pwd' => array('rule' => array('confirmPassword', 'password'), |
|---|
| 70 | 'message' => 'Passwords do not match'), |
|---|
| 71 | 'pwd_confirm' => array('rule' => 'alphanumeric', |
|---|
| 72 | 'required' => true) |
|---|
| 73 | ); |
|---|
| 74 | */ |
|---|
| 75 | |
|---|
| 76 | public function confirmPassword($data) |
|---|
| 77 | { |
|---|
| 78 | $valid = false; |
|---|
| 79 | |
|---|
| 80 | if ($data['password'] == Security::hash(Configure::read('Security.salt') . $this->data['User']['password_confirm'])) |
|---|
| 81 | { |
|---|
| 82 | $valid = true; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | return $valid; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /* |
|---|
| 89 | * excepts : model you need |
|---|
| 90 | * |
|---|
| 91 | */ |
|---|
| 92 | public function removeBinds($excepts = array()) |
|---|
| 93 | { |
|---|
| 94 | foreach ($excepts as $e) |
|---|
| 95 | { |
|---|
| 96 | if ( in_array($e, $this->notNow) ) |
|---|
| 97 | { |
|---|
| 98 | unset($this->notNow[$e]); // not unbind this model |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | $this->unbindModel($this->notNow); |
|---|
| 103 | |
|---|
| 104 | return true; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /* |
|---|
| 108 | * Remove pwd if too short |
|---|
| 109 | * |
|---|
| 110 | */ |
|---|
| 111 | public function beforeValidate() |
|---|
| 112 | { |
|---|
| 113 | |
|---|
| 114 | if ( !empty($this->data['User']['pwd']) ): |
|---|
| 115 | |
|---|
| 116 | if ( strlen($this->data['User']['pwd']) < 6): // only if pwd is big enough |
|---|
| 117 | unset($this->data['User']['pwd']); |
|---|
| 118 | endif; |
|---|
| 119 | |
|---|
| 120 | endif; |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | return true; |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | ?> |
|---|