pictcode / app / Model / User.php @ b3a58ce1
履歴 | 表示 | アノテート | ダウンロード (3.466 KB)
1 | d6c3d8de | root | <?php
|
---|---|---|---|
2 | App::uses('AppModel', 'Model'); |
||
3 | App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth'); |
||
4 | |||
5 | |||
6 | /**
|
||
7 | * User Model
|
||
8 | *
|
||
9 | * @property Login $Login
|
||
10 | * @property Program $Program
|
||
11 | */
|
||
12 | class User extends AppModel { |
||
13 | |||
14 | |||
15 | /**
|
||
16 | * Validation rules
|
||
17 | *
|
||
18 | * @var array
|
||
19 | */
|
||
20 | public $validate = array( |
||
21 | 'login_id' => array( |
||
22 | 'rule' => array('notBlank'), |
||
23 | 8b8631af | hasse | 'message' => 'この項目は入力必須です' |
24 | d6c3d8de | root | ), |
25 | 04e657a7 | root | 'email' => array( |
26 | 8b8631af | hasse | array(
|
27 | 'rule' => array('notBlank'), |
||
28 | 'message' => 'メールアドレスを入力してください' |
||
29 | ), |
||
30 | 04e657a7 | root | // メールアドレスであること。
|
31 | 8b8631af | hasse | 'isEmail' => array( |
32 | 'rule' => 'Email', |
||
33 | 'message' => '正しいメールアドレスを入力してください' |
||
34 | ), |
||
35 | array(
|
||
36 | 'rule' => 'DuplicateEmailCheck', |
||
37 | 'message' => 'このメールアドレスは既に登録されています' |
||
38 | ), |
||
39 | 04e657a7 | root | // 一意性チェック
|
40 | // 'emailExists' => array( 'rule' => 'isUnique', 'message' => '既に登録されています'),
|
||
41 | ), |
||
42 | 'password' => array( |
||
43 | 8b8631af | hasse | array(
|
44 | 'rule' => array('notBlank'), |
||
45 | 'message' => 'パスワードを入力してください' |
||
46 | ), |
||
47 | array(
|
||
48 | 'rule' => array('minLength', 8), |
||
49 | 'message' => 'パスワードは8文字以上入力してください', |
||
50 | ), |
||
51 | array(
|
||
52 | 'rule' => 'passwordConfirm', |
||
53 | 'message' => 'パスワードが一致していません' |
||
54 | ), |
||
55 | ), |
||
56 | 'password_confirm' => array( |
||
57 | array(
|
||
58 | 'rule' => array('notBlank'), |
||
59 | 'message' => 'パスワード(確認)を入力してください' |
||
60 | ), |
||
61 | 04e657a7 | root | ), |
62 | d6c3d8de | root | 'status' => array( |
63 | 'numeric' => array( |
||
64 | 'rule' => array('numeric'), |
||
65 | //'message' => 'Your custom message here',
|
||
66 | //'allowEmpty' => false,
|
||
67 | //'required' => false,
|
||
68 | //'last' => false, // Stop validation after this rule
|
||
69 | //'on' => 'create', // Limit validation to 'create' or 'update' operations
|
||
70 | ), |
||
71 | ), |
||
72 | ); |
||
73 | |||
74 | |||
75 | 8b8631af | hasse | public function DuplicateEmailCheck(){ |
76 | $query = array('conditions' => array('User.email' => $this->data['User']['email'],'User.status' => 1)); |
||
77 | $num = $this->find('count',$query); |
||
78 | //$this->log($recodes);
|
||
79 | //var_dump($num);
|
||
80 | //exit;
|
||
81 | if($num > 0){ |
||
82 | return false; //登録済み |
||
83 | } else{
|
||
84 | return true; //未登録 |
||
85 | } |
||
86 | } |
||
87 | 04e657a7 | root | |
88 | 8b8631af | hasse | public function passwordConfirm($check){ |
89 | //2つのパスワードフィールドが一致する事を確認する
|
||
90 | if($this->data['User']['password'] === $this->data['User']['password_confirm']){ |
||
91 | 04e657a7 | root | // パスワードハッシュ化
|
92 | 8b8631af | hasse | $this->data[$this->name]['password'] = Security::hash( $password, 'sha512', true); |
93 | 04e657a7 | root | return true; |
94 | 8b8631af | hasse | }else{
|
95 | return false; |
||
96 | 04e657a7 | root | } |
97 | 8b8631af | hasse | |
98 | 04e657a7 | root | } |
99 | |||
100 | 8b8631af | hasse | |
101 | 04e657a7 | root | public function getActivationHash() { |
102 | // ユーザIDの有無確認
|
||
103 | if (!isset($this->id)) { |
||
104 | return false; |
||
105 | } |
||
106 | // 更新日時をハッシュ化
|
||
107 | return Security::hash( $this->field('updated'), 'md5', true); |
||
108 | } |
||
109 | |||
110 | |||
111 | d6c3d8de | root | public function beforeSave($options = array()) { |
112 | if (isset($this->data[$this->alias]['password'])) { |
||
113 | $passwordHasher = new BlowfishPasswordHasher(); |
||
114 | $this->data[$this->alias]['password'] = $passwordHasher->hash( |
||
115 | $this->data[$this->alias]['password'] |
||
116 | ); |
||
117 | } |
||
118 | return true; |
||
119 | } |
||
120 | |||
121 | |||
122 | } |