pictcode / app / Controller / UsersController.php @ 04e657a7
履歴 | 表示 | アノテート | ダウンロード (6.883 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 | 5ec4ad9d | admin | |
13 | public function beforeFilter() { |
||
14 | parent::beforeFilter();
|
||
15 | 04e657a7 | root | $this->Auth->allow('register','activate'); |
16 | 5ec4ad9d | admin | } |
17 | |||
18 | /**
|
||
19 | * Components
|
||
20 | *
|
||
21 | * @var array
|
||
22 | */
|
||
23 | public $components = array('Paginator'); |
||
24 | |||
25 | /**
|
||
26 | * index method
|
||
27 | *
|
||
28 | * @return void
|
||
29 | */
|
||
30 | public function index() { |
||
31 | $this->User->recursive = 0; |
||
32 | $this->set('users', $this->Paginator->paginate()); |
||
33 | } |
||
34 | |||
35 | /**
|
||
36 | * view method
|
||
37 | *
|
||
38 | * @throws NotFoundException
|
||
39 | * @param string $id
|
||
40 | * @return void
|
||
41 | */
|
||
42 | public function view($id = null) { |
||
43 | if (!$this->User->exists($id)) { |
||
44 | throw new NotFoundException(__('Invalid user')); |
||
45 | } |
||
46 | $options = array('conditions' => array('User.' . $this->User->primaryKey => $id)); |
||
47 | $this->set('user', $this->User->find('first', $options)); |
||
48 | } |
||
49 | |||
50 | 04e657a7 | root | |
51 | /**
|
||
52 | * register method
|
||
53 | *
|
||
54 | * @return void
|
||
55 | */
|
||
56 | public function register() { |
||
57 | if($this->request->is('post') || $this->request->is('put')){ |
||
58 | $this->User->set($this->request->data); |
||
59 | if($this->User->validates()){ |
||
60 | $this->Session->write('register',$this->request->data); |
||
61 | $this->redirect(array('action'=>'confirm')); |
||
62 | }else{
|
||
63 | } |
||
64 | } |
||
65 | |||
66 | // if (!empty( $this->data)){
|
||
67 | // // 保存
|
||
68 | // if( $this->User->set( $this->data)){
|
||
69 | // // if( $this->User->save( $this->data)){
|
||
70 | // // ユーザアクティベート(本登録)用URLの作成
|
||
71 | // $url =
|
||
72 | // DS . strtolower($this->name) . // コントローラ
|
||
73 | // DS . 'activate' . // アクション
|
||
74 | // DS . $this->User->id . // ユーザID
|
||
75 | // DS . $this->User->getActivationHash(); // ハッシュ値
|
||
76 | // $url = Router::url( $url, true); // ドメイン(+サブディレクトリ)を付与
|
||
77 | // // メール送信
|
||
78 | // // return
|
||
79 | // $this->redirect(array('action' => 'confirm'));
|
||
80 | // $this->Session->write('register',$this->request->data);
|
||
81 | // $this->Session->setFlash( '仮登録成功。メール送信しました。');
|
||
82 | // } else {
|
||
83 | // // バリデーションエラーメッセージを渡す
|
||
84 | // $this->Session->setFlash( '入力エラー');
|
||
85 | // }
|
||
86 | // }
|
||
87 | } |
||
88 | |||
89 | /**
|
||
90 | * register confirm
|
||
91 | */
|
||
92 | public function confirm() { |
||
93 | if($this->Session->read('register')){ |
||
94 | $this->set('register',$this->Session->read('register')); |
||
95 | }else{
|
||
96 | $this->redirect(array('action'=>'register')); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | |||
101 | /**
|
||
102 | * register sent
|
||
103 | */
|
||
104 | public function sent() { |
||
105 | // if (!empty( $this->data)){
|
||
106 | // // 保存
|
||
107 | if( $this->User->save($this->Session->read('register'))){ |
||
108 | // メール送信
|
||
109 | $this->set('register',$this->Session->read('register')); |
||
110 | $name = $this->Session->read('register.user.login_id'); |
||
111 | $mail = $this->Session->read('register.user.email'); |
||
112 | // ユーザアクティベート(本登録)用URLの作成
|
||
113 | $url =
|
||
114 | DS . 'users' . // コントローラ |
||
115 | DS . 'activate' . // アクション |
||
116 | DS . $this->User->id . // ユーザID |
||
117 | DS . $this->User->getActivationHash(); // ハッシュ値 |
||
118 | $url = Router::url( $url, true); // ドメイン(+サブディレクトリ)を付与 |
||
119 | $comment = $url; |
||
120 | |||
121 | $Email = new CakeEmail(); |
||
122 | $Email->charset('ISO-2022-JP'); |
||
123 | $Email->emailFormat('text'); |
||
124 | $Email->template('user_register'); |
||
125 | $Email->viewVars(array('name'=>$name,'comment'=>$comment)); |
||
126 | $Email->from($mail); |
||
127 | $Email->to('hasegawa@i-hearts.jp'); |
||
128 | $Email->subject('[PICT CODE]問い合わせ'); |
||
129 | $Email->send();
|
||
130 | |||
131 | // return
|
||
132 | // $this->redirect(array('action' => 'confirm'));
|
||
133 | // $this->Session->setFlash( '仮登録成功。メール送信しました。');
|
||
134 | // } else {
|
||
135 | // // バリデーションエラーメッセージを渡す
|
||
136 | // $this->Session->setFlash( '入力エラー');
|
||
137 | // }
|
||
138 | } |
||
139 | |||
140 | } |
||
141 | |||
142 | /**
|
||
143 | * register activate
|
||
144 | */
|
||
145 | public function activate( $user_id = null, $in_hash = null) { |
||
146 | // UserモデルにIDをセット
|
||
147 | $this->User->id = $user_id; |
||
148 | if ($this->User->exists() && $in_hash == $this->User->getActivationHash()) { |
||
149 | // 本登録に有効なURL
|
||
150 | // statusフィールドを0に更新
|
||
151 | $this->User->saveField( 'status', 0); |
||
152 | $this->Session->setFlash( 'Your account has been activated.'); |
||
153 | }else{
|
||
154 | // 本登録に無効なURL
|
||
155 | $this->Session->setFlash( 'Invalid activation URL'); |
||
156 | } |
||
157 | } |
||
158 | |||
159 | 5ec4ad9d | admin | /**
|
160 | * add method
|
||
161 | *
|
||
162 | * @return void
|
||
163 | */
|
||
164 | public function add() { |
||
165 | if ($this->request->is('post')) { |
||
166 | $this->User->create(); |
||
167 | if ($this->User->save($this->request->data)) { |
||
168 | $this->Flash->success(__('The user has been saved.')); |
||
169 | return $this->redirect(array('action' => 'index')); |
||
170 | } else {
|
||
171 | $this->Flash->error(__('The user could not be saved. Please, try again.')); |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | |||
176 | /**
|
||
177 | * edit method
|
||
178 | *
|
||
179 | * @throws NotFoundException
|
||
180 | * @param string $id
|
||
181 | * @return void
|
||
182 | */
|
||
183 | public function edit($id = null) { |
||
184 | if (!$this->User->exists($id)) { |
||
185 | throw new NotFoundException(__('Invalid user')); |
||
186 | } |
||
187 | if ($this->request->is(array('post', 'put'))) { |
||
188 | if ($this->User->save($this->request->data)) { |
||
189 | $this->Flash->success(__('The user has been saved.')); |
||
190 | return $this->redirect(array('action' => 'index')); |
||
191 | } else {
|
||
192 | $this->Flash->error(__('The user could not be saved. Please, try again.')); |
||
193 | } |
||
194 | } else {
|
||
195 | $options = array('conditions' => array('User.' . $this->User->primaryKey => $id)); |
||
196 | $this->request->data = $this->User->find('first', $options); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | /**
|
||
201 | * delete method
|
||
202 | *
|
||
203 | * @throws NotFoundException
|
||
204 | * @param string $id
|
||
205 | * @return void
|
||
206 | */
|
||
207 | public function delete($id = null) { |
||
208 | $this->User->id = $id; |
||
209 | if (!$this->User->exists()) { |
||
210 | throw new NotFoundException(__('Invalid user')); |
||
211 | } |
||
212 | $this->request->allowMethod('post', 'delete'); |
||
213 | if ($this->User->delete()) { |
||
214 | $this->Flash->success(__('The user has been deleted.')); |
||
215 | } else {
|
||
216 | $this->Flash->error(__('The user could not be deleted. Please, try again.')); |
||
217 | } |
||
218 | return $this->redirect(array('action' => 'index')); |
||
219 | } |
||
220 | |||
221 | /**
|
||
222 | * login method
|
||
223 | *
|
||
224 | * @throws NotFoundException
|
||
225 | * @param string $id
|
||
226 | * @return void
|
||
227 | */
|
||
228 | public function login() { |
||
229 | //var_dump(Security::hash( "123", 'blowfish'));
|
||
230 | if($this->Auth->user()){ |
||
231 | $this->redirect($this->Auth->redirectUrl()); |
||
232 | } |
||
233 | if ($this->request->is('post')) { |
||
234 | if ($this->Auth->login()) { |
||
235 | $this->redirect($this->Auth->redirectUrl()); |
||
236 | } else {
|
||
237 | $this->Flash->error(__('login error')); |
||
238 | } |
||
239 | } |
||
240 | } |
||
241 | /**
|
||
242 | * logout method
|
||
243 | *
|
||
244 | * @throws NotFoundException
|
||
245 | * @param string $id
|
||
246 | * @return void
|
||
247 | */
|
||
248 | public function logout() { |
||
249 | $this->redirect($this->Auth->logout()); |
||
250 | } |
||
251 | 04e657a7 | root | |
252 | |||
253 | |||
254 | 5ec4ad9d | admin | } |
255 | 04e657a7 | root |