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

pictcode / app / Controller / UsersController.php @ 410c42e5

履歴 | 表示 | アノテート | ダウンロード (5.758 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 8b8631af hasse
        $this->Auth->allow('register','activate','confirm','sent','login');
18 5ec4ad9d admin
    }
19
20
/**
21
 * Components
22
 *
23
 * @var array
24
 */
25
        public $components = array('Paginator');
26
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 8b8631af hasse
                $Email->from('hasegawa@i-hearts.jp');
107
                $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
                // statusフィールドを0に更新
123
                $this->User->saveField( 'status', 0);
124
                $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
                //var_dump(Security::hash( "123", 'blowfish'));
202 410c42e5 hasegawa
                if($this->register->user()){
203 5ec4ad9d admin
                        $this->redirect($this->Auth->redirectUrl());                          
204
                }
205
                if ($this->request->is('post')) {
206 410c42e5 hasegawa
                        if ($this->register->login()) {
207 ceb21f43 hasse
                                $this->redirect('/Users/login_top');                          
208 5ec4ad9d admin
                        } else {
209 ceb21f43 hasse
                                $this->Flash->error(__('error'));
210
                                // $this->Flash->error(__('<section class="caution"><p>ニックネームか パスワードに<br>まちがいが あるよ!</p></section>'));
211 5ec4ad9d admin
                        }
212
                }
213
        }        
214
/**
215 ceb21f43 hasse
 * logout methods
216 5ec4ad9d admin
 *
217
 * @throws NotFoundException
218
 * @param string $id
219
 * @return void
220
 */
221
        public function logout() {
222 410c42e5 hasegawa
            $this->redirect($this->register->logout());
223 5ec4ad9d admin
        }
224 04e657a7 root
225
226 ceb21f43 hasse
/**
227
 * login_top method
228
 *
229
 */
230
        public function login_top() {
231
        }
232
233
234 04e657a7 root
235 5ec4ad9d admin
}
236 04e657a7 root