リビジョン 67acbfb5 app/Controller/UsersController.php
| app/Controller/UsersController.php | ||
|---|---|---|
| 14 | 14 |
|
| 15 | 15 |
public function beforeFilter() {
|
| 16 | 16 |
parent::beforeFilter(); |
| 17 |
$this->Auth->allow('register','activate','confirm','sent','login','index');
|
|
| 17 |
$this->Auth->allow('register','activate','confirm','sent','login','reset_pwd','reset_pwd_confirm','reset_pwd_sent','newpwd','reset_pwd_comp_mail');
|
|
| 18 | 18 |
} |
| 19 | 19 |
|
| 20 | 20 |
/** |
| ... | ... | |
| 198 | 198 |
* @return void |
| 199 | 199 |
*/ |
| 200 | 200 |
public function login() {
|
| 201 |
//var_dump(Security::hash( "123", 'blowfish')); |
|
| 202 |
if($this->Auth->user()){
|
|
| 203 |
$this->redirect($this->Auth->redirectUrl()); |
|
| 204 |
} |
|
| 201 |
// if($this->Auth->user()){
|
|
| 202 |
// $this->redirect($this->Auth->redirectUrl()); |
|
| 203 |
// } |
|
| 205 | 204 |
if ($this->request->is('post')) {
|
| 206 | 205 |
if ($this->Auth->login()) {
|
| 207 |
// var_dump($this->Auth->login('User.status'));
|
|
| 208 |
// exit; |
|
| 209 |
if($this->Auth->user('User.status') == 1){
|
|
| 206 |
// $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 | 210 |
$this->redirect('/Users/login_top');
|
| 211 | 211 |
}else{
|
| 212 | 212 |
$this->Flash->loginerror('まだ本登録が完了していません。送られてきたメールを見てね!', array(
|
| ... | ... | |
| 240 | 240 |
} |
| 241 | 241 |
|
| 242 | 242 |
|
| 243 |
/** |
|
| 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 |
|
|
| 243 | 413 |
|
| 244 | 414 |
} |
| 245 | 415 |
|
他の形式にエクスポート: Unified diff