統計
| ブランチ: | リビジョン:

pictcode / app / Controller / UsersController.php @ 67acbfb5

履歴 | 表示 | アノテート | ダウンロード (12.179 KB)

1 5ec4ad9d admin
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Users Controller
5
 *
6
 * @property User $User
7
 * @property PaginatorComponent $Paginator
8
 */
9
class UsersController extends AppController {
10
11 d6c3d8de root
        public $layout = 'procedure';
12 8aec79d5 hasse
        public $name = 'users';
13 8b8631af hasse
        public $uses = array('User');
14 5ec4ad9d admin
15
    public function beforeFilter() {
16
        parent::beforeFilter();
17 67acbfb5 hasse
        $this->Auth->allow('register','activate','confirm','sent','login','reset_pwd','reset_pwd_confirm','reset_pwd_sent','newpwd','reset_pwd_comp_mail');
18 5ec4ad9d admin
    }
19
20
/**
21
 * Components
22
 *
23
 * @var array
24
 */
25 b3a58ce1 hasse
        public $components = array('Paginator','Recaptcha.Recaptcha');
26 5ec4ad9d admin
27
/**
28
 * index method
29
 *
30
 * @return void
31
 */
32
        public function index() {
33
                $this->User->recursive = 0;
34
                $this->set('users', $this->Paginator->paginate());
35
        }
36
37
/**
38
 * view method
39
 *
40
 * @throws NotFoundException
41
 * @param string $id
42
 * @return void
43
 */
44
        public function view($id = null) {
45
                if (!$this->User->exists($id)) {
46
                        throw new NotFoundException(__('Invalid user'));
47
                }
48
                $options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
49
                $this->set('user', $this->User->find('first', $options));
50
        }
51
52 04e657a7 root
53
/**
54
 * register method
55
 *
56
 * @return void
57
 */
58
        public function register() {
59
                if($this->request->is('post') || $this->request->is('put')){
60
                        $this->User->set($this->request->data);
61
                        if($this->User->validates()){
62
                                $this->Session->write('register',$this->request->data);
63
                                $this->redirect(array('action'=>'confirm'));
64
                        }else{
65
                        }
66
                }
67
        }
68
        
69
/**
70
 * register confirm
71
 */
72
        public function confirm() {
73
                if($this->Session->read('register')){
74
                        $this->set('register',$this->Session->read('register'));
75
                }else{
76
                        $this->redirect(array('action'=>'register'));
77
                }
78
        }
79
80
81
/**
82
 * register sent
83
 */
84
        public function sent() {
85
                // if (!empty( $this->data)){
86
         //        //  保存
87
           if( $this->User->save($this->Session->read('register'))){
88
                    //  メール送信
89
                $this->set('register',$this->Session->read('register'));
90 a5ebb280 root
                $name = $this->Session->read('register.User.login_id');
91
                $mail = $this->Session->read('register.User.email');
92 8b8631af hasse
        // ユーザアクティベート(本登録)用URLの作成 DSはスラッシュの意味
93 04e657a7 root
        $url = 
94
            DS . 'users' .          // コントローラ
95
            DS . 'activate' .                       // アクション
96
            DS . $this->User->id .                  // ユーザID
97
            DS . $this->User->getActivationHash();  // ハッシュ値
98
        $url = Router::url( $url, true);  // ドメイン(+サブディレクトリ)を付与
99
                $comment = $url;
100
101
                $Email = new CakeEmail();
102
                $Email->charset('ISO-2022-JP');
103
                $Email->emailFormat('text');
104
                $Email->template('user_register');
105
                $Email->viewVars(array('name'=>$name,'comment'=>$comment));
106 8fa10255 hasse
                $Email->from( MAIL_FROM ); //MAIL_FROM:Config/const.phpにて定義
107 8b8631af hasse
                $Email->to($mail);
108 04e657a7 root
                $Email->subject('[PICT CODE]問い合わせ');
109
                $Email->send();
110
            }
111
112
        }        
113
114
/**
115
 * register activate
116
 */
117
        public function activate( $user_id = null, $in_hash = null) {
118
            // UserモデルにIDをセット
119
            $this->User->id = $user_id;
120
            if ($this->User->exists() && $in_hash == $this->User->getActivationHash()) {
121
            // 本登録に有効なURL
122 8fa10255 hasse
                // statusフィールドを1に更新
123
                $this->User->saveField( 'status', 1);
124 04e657a7 root
                $this->Session->setFlash( 'Your account has been activated.');
125
            }else{
126
            // 本登録に無効なURL
127
                $this->Session->setFlash( 'Invalid activation URL');
128
            }
129
        }
130
        
131 5ec4ad9d admin
/**
132
 * add method
133
 *
134
 * @return void
135
 */
136
        public function add() {
137
                if ($this->request->is('post')) {
138
                        $this->User->create();
139
                        if ($this->User->save($this->request->data)) {
140
                                $this->Flash->success(__('The user has been saved.'));
141
                                return $this->redirect(array('action' => 'index'));
142
                        } else {
143
                                $this->Flash->error(__('The user could not be saved. Please, try again.'));
144
                        }
145
                }
146
        }
147
148
/**
149
 * edit method
150
 *
151
 * @throws NotFoundException
152
 * @param string $id
153
 * @return void
154
 */
155
        public function edit($id = null) {
156
                if (!$this->User->exists($id)) {
157
                        throw new NotFoundException(__('Invalid user'));
158
                }
159
                if ($this->request->is(array('post', 'put'))) {
160
                        if ($this->User->save($this->request->data)) {
161
                                $this->Flash->success(__('The user has been saved.'));
162
                                return $this->redirect(array('action' => 'index'));
163
                        } else {
164
                                $this->Flash->error(__('The user could not be saved. Please, try again.'));
165
                        }
166
                } else {
167
                        $options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
168
                        $this->request->data = $this->User->find('first', $options);
169
                }
170
        }
171
172
/**
173
 * delete method
174
 *
175
 * @throws NotFoundException
176
 * @param string $id
177
 * @return void
178
 */
179
        public function delete($id = null) {
180
                $this->User->id = $id;
181
                if (!$this->User->exists()) {
182
                        throw new NotFoundException(__('Invalid user'));
183
                }
184
                $this->request->allowMethod('post', 'delete');
185
                if ($this->User->delete()) {
186
                        $this->Flash->success(__('The user has been deleted.'));
187
                } else {
188
                        $this->Flash->error(__('The user could not be deleted. Please, try again.'));
189
                }
190
                return $this->redirect(array('action' => 'index'));
191
        }
192
193
/**
194
 * login method
195
 *
196
 * @throws NotFoundException
197
 * @param string $id
198
 * @return void
199
 */
200
        public function login() {
201 67acbfb5 hasse
                // if($this->Auth->user()){
202
                //         $this->redirect($this->Auth->redirectUrl());                          
203
                // }
204 5ec4ad9d admin
                if ($this->request->is('post')) {
205
                        if ($this->Auth->login()) {
206 67acbfb5 hasse
                 //    $options = array('conditions' => array('User.email' => $this->Auth->user('User.email'),'User.status' => 1));
207
                        // $this->request->data = $this->User->find('first', $options);
208
                        // $this->set('user', $this->request->data);
209
                                if($this->Auth->user('status') == 1){
210 8fa10255 hasse
                                        $this->redirect('/Users/login_top');                          
211
                                }else{
212
                                $this->Flash->loginerror('まだ本登録が完了していません。送られてきたメールを見てね!', array(
213
                                    'key' => 'positive',
214
                                        ));
215
                                }
216 5ec4ad9d admin
                        } else {
217 b3a58ce1 hasse
                                $this->Flash->loginerror('ニックネームか パスワードにまちがいが あるよ!', array(
218
                                    'key' => 'positive',
219
                                        ));
220 5ec4ad9d admin
                        }
221
                }
222
        }        
223
/**
224 ceb21f43 hasse
 * logout methods
225 5ec4ad9d admin
 *
226
 * @throws NotFoundException
227
 * @param string $id
228
 * @return void
229
 */
230
        public function logout() {
231
            $this->redirect($this->Auth->logout());
232
        }
233 04e657a7 root
234
235 ceb21f43 hasse
/**
236
 * login_top method
237
 *
238
 */
239
        public function login_top() {
240
        }
241
242
243 67acbfb5 hasse
/**
244
 * reset_pwd
245
 */
246
        public function reset_pwd() {
247
                $this->User->validate = $this->User->reset_pwd_validate;
248
                if ($this->request->is(array('post', 'put'))) {
249
                        $this->User->set($this->request->data);
250
                        if($this->User->validates()){
251
                                $this->Session->write('register',$this->request->data);
252
                                $this->redirect(array('action'=>'reset_pwd_confirm'));
253
                        }else{
254
                                $this->Flash->loginerror('メールアドレスが一致しません。誤りがないかもう一度ご確認の上、正確にご入力ください。', array(
255
                                    'key' => 'positive',
256
                                        ));
257
                        }
258
                }
259
        }
260
        
261
/**
262
 * reset_pwd confirm
263
 */
264
        public function reset_pwd_confirm() {
265
                if($this->Session->read('register')){
266
                        $this->set('register',$this->Session->read('register'));
267
                }else{
268
                        $this->redirect(array('action'=>'reset_pwd'));
269
                }
270
        }
271
272
273
/**
274
 * register sent
275
 */
276
        public function reset_pwd_sent() {
277
                // if (!empty( $this->data)){
278
         //        //  保存
279
            if($this->Session->read('register')){
280
                    //  メール送信
281
                $this->set('register',$this->Session->read('register'));
282
                $mail = $this->Session->read('register.User.email');
283
                $options = array('conditions' => array('User.email' => $mail));
284
                $user = $this->User->find('first', $options);
285
                $name = $user['User']['login_id'];
286
287
        // ユーザアクティベート(本登録)用URLの作成 DSはスラッシュの意味
288
        $url = 
289
            DS . 'users' .          // コントローラ
290
            DS . 'newpwd' .                       // アクション
291
            DS . $user['User']['id'] .                  // ユーザID
292
            DS . $this->User->getActivationHash();  // ハッシュ値
293
        $url = Router::url( $url, true);  // ドメイン(+サブディレクトリ)を付与
294
                $comment = $url;
295
                $Email = new CakeEmail();
296
                $Email->charset('ISO-2022-JP');
297
                $Email->emailFormat('text');
298
                $Email->template('user_reset_pwd');
299
                $Email->viewVars(array('name'=>$name,'comment'=>$comment));
300
                $Email->from( MAIL_FROM ); //MAIL_FROM:Config/const.phpにて定義
301
                $Email->to($mail);
302
                $Email->subject('[PICT CODE]問い合わせ');
303
                $Email->send();
304
            }
305
306
        }
307
308
309
310
/**
311
 * new password
312
 */
313
        public function newpwd( $user_id = null, $in_hash = null) {
314
                $this->User->validate = $this->User->new_pwd_validate;
315
316
            // UserモデルにIDをセット
317
            $this->User->id = $user_id;
318
            if ($this->User->exists() && $in_hash == $this->User->getActivationHash()) {
319
                $this->Session->setFlash( '無効なURLです');
320
                        return $this->redirect(array('controller' => 'top', 'action' => 'index'));
321
322
            }else{
323
                    if ($this->request->is(array('post', 'put'))) {
324
325
                                $this->set('user', $this->request->data);
326
                                if ($this->User->save($this->request->data)) {
327
                                        return $this->redirect(array('action' => 'reset_pwd_comp_mail'));
328
                                } 
329
                        } else {
330
                            $options = array('conditions' => array('User.id' => $user_id,'User.status' => 1));
331
                                $this->request->data = $this->User->find('first', $options);
332
                                $this->set('user', $this->request->data);
333
                                          //           var_dump($this->request->data);
334
                            // exit;
335
                        }
336
            }
337
338
         //    $options = array('conditions' => array('User.id' => $user_id,'User.status' => 1));
339
                // // $this->request->data = $this->set('user',$this->User->find('first', $options));
340
                // $this->set('user',$this->User->find('first', $options));
341
                // // $this->set('user', $this->request->data);
342
343
344
         //    // if ($this->User->exists() && $in_hash == $this->User->getActivationHash()) {
345
         //    // var_dump($this->request->data);
346
         //    // exit;
347
         //        if ($this->request->is(array('post', 'put'))) {
348
                //                 // if($this->User->validates()){
349
350
         //                    $this->User->save($this->request->data);
351
                //                         $this->redirect(array('action'=>'reset_pwd_comp_mail'));
352
         //     //        } else {
353
                //                                 // $this->Flash->loginerror('パスワードが一致しません。誤りがないかもう一度ご確認の上、正確にご入力ください。', array(
354
                //                                 //     'key' => 'positive',
355
                //                                 //         ));
356
         //     //        }
357
         //   //      } else {
358
                //          //    $options = array('conditions' => array('User.id' => $user_id,'User.status' => 1));
359
                //                 // $this->request->data = $this->set('user',$this->User->find('first', $options));
360
                //                 // // $this->set('user', $this->request->data);
361
         //   //      $this->Session->setFlash( '無効なURLですaaa');
362
         //        // }
363
364
365
         //    }else{
366
         //    // 本登録に無効なURL
367
         //        $this->Session->setFlash( '無効なURLです');
368
         //    }
369
        }
370
371
/**
372
 * 
373
 */
374
        public function reset_pwd_comp_mail() {
375
                // if (!empty( $this->data)){
376
                 //  保存
377
                $this->User->validate = $this->User->new_pwd_validate;
378
                    if( $this->User->save($this->request->data('user'))){
379
                            //  メール送信
380
                        $this->set('register',$this->Session->read('register'));
381
                        $mail = $this->Session->read('register.User.email');
382
                        // exit;
383
                        $options = array('conditions' => array('User.email' => $mail));
384
                        $user = $this->User->find('first', $options);
385
                        $name = $user['User']['login_id'];
386
387
                // ユーザアクティベート(本登録)用URLの作成 DSはスラッシュの意味
388
                // $url = 
389
                //     DS . 'users' .          // コントローラ
390
                //     DS . 'newpwd' .                       // アクション
391
                //     DS . $user['User']['id'] .                  // ユーザID
392
                //     DS . $this->User->getActivationHash();  // ハッシュ値
393
                // $url = Router::url( $url, true);  // ドメイン(+サブディレクトリ)を付与
394
                        $comment = "本文本文本文本文本文本文本文本文";
395
                        $Email = new CakeEmail();
396
                        $Email->charset('ISO-2022-JP');
397
                        $Email->emailFormat('text');
398
                        $Email->template('comp_reset_pwd');
399
                        $Email->viewVars(array('name'=>$name,'comment'=>$comment));
400
                        $Email->from( MAIL_FROM ); //MAIL_FROM:Config/const.phpにて定義
401
                        $Email->to($mail);
402
                        $Email->subject('[PICT CODE]問い合わせ');
403
                        $Email->send();
404
                    }
405
            // }
406
                // }else{
407
         //        exit;
408
                // }
409
debug($this->User->validationErrors);
410
        }
411
412
413 04e657a7 root
414 5ec4ad9d admin
}
415 04e657a7 root