commit 67acbfb5a6ac42591b4c6bf3cf2b5fac97b78796
Author: hasse <hasegawa@i-hearts.jp>
Date:   Wed Mar 9 21:07:37 2016 -0500

    パスワード再発行機能実装

diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php
index 879d3d9..a4c82f3 100755
--- a/app/Controller/UsersController.php
+++ b/app/Controller/UsersController.php
@@ -14,7 +14,7 @@ class UsersController extends AppController {
 
     public function beforeFilter() {
         parent::beforeFilter();
-        $this->Auth->allow('register','activate','confirm','sent','login','index');
+        $this->Auth->allow('register','activate','confirm','sent','login','reset_pwd','reset_pwd_confirm','reset_pwd_sent','newpwd','reset_pwd_comp_mail');
     }
 
 /**
@@ -198,15 +198,15 @@ class UsersController extends AppController {
  * @return void
  */
 	public function login() {
-		//var_dump(Security::hash( "123", 'blowfish'));
-		if($this->Auth->user()){
-			$this->redirect($this->Auth->redirectUrl());                          
-		}
+		// if($this->Auth->user()){
+		// 	$this->redirect($this->Auth->redirectUrl());                          
+		// }
 		if ($this->request->is('post')) {
 			if ($this->Auth->login()) {
-				// var_dump($this->Auth->login('User.status'));
-				// exit;
-				if($this->Auth->user('User.status') == 1){
+		 //    $options = array('conditions' => array('User.email' => $this->Auth->user('User.email'),'User.status' => 1));
+			// $this->request->data = $this->User->find('first', $options);
+			// $this->set('user', $this->request->data);
+				if($this->Auth->user('status') == 1){
 					$this->redirect('/Users/login_top');                          
 				}else{
 				$this->Flash->loginerror('まだ本登録が完了していません。送られてきたメールを見てね！', array(
@@ -240,6 +240,176 @@ class UsersController extends AppController {
 	}
 
 
+/**
+ * reset_pwd
+ */
+	public function reset_pwd() {
+		$this->User->validate = $this->User->reset_pwd_validate;
+		if ($this->request->is(array('post', 'put'))) {
+			$this->User->set($this->request->data);
+			if($this->User->validates()){
+				$this->Session->write('register',$this->request->data);
+				$this->redirect(array('action'=>'reset_pwd_confirm'));
+			}else{
+				$this->Flash->loginerror('メールアドレスが一致しません。誤りがないかもう一度ご確認の上、正確にご入力ください。', array(
+				    'key' => 'positive',
+					));
+			}
+		}
+	}
+	
+/**
+ * reset_pwd confirm
+ */
+	public function reset_pwd_confirm() {
+		if($this->Session->read('register')){
+			$this->set('register',$this->Session->read('register'));
+		}else{
+			$this->redirect(array('action'=>'reset_pwd'));
+		}
+	}
+
+
+/**
+ * register sent
+ */
+	public function reset_pwd_sent() {
+		// if (!empty( $this->data)){
+	 //        //  保存
+	    if($this->Session->read('register')){
+	            //  メール送信
+		$this->set('register',$this->Session->read('register'));
+		$mail = $this->Session->read('register.User.email');
+		$options = array('conditions' => array('User.email' => $mail));
+		$user = $this->User->find('first', $options);
+		$name = $user['User']['login_id'];
+
+        // ユーザアクティベート(本登録)用URLの作成 DSはスラッシュの意味
+        $url = 
+            DS . 'users' .          // コントローラ
+            DS . 'newpwd' .                       // アクション
+            DS . $user['User']['id'] .                  // ユーザID
+            DS . $this->User->getActivationHash();  // ハッシュ値
+        $url = Router::url( $url, true);  // ドメイン(+サブディレクトリ)を付与
+		$comment = $url;
+		$Email = new CakeEmail();
+		$Email->charset('ISO-2022-JP');
+		$Email->emailFormat('text');
+		$Email->template('user_reset_pwd');
+		$Email->viewVars(array('name'=>$name,'comment'=>$comment));
+		$Email->from( MAIL_FROM ); //MAIL_FROM：Config/const.phpにて定義
+		$Email->to($mail);
+		$Email->subject('[PICT CODE]問い合わせ');
+		$Email->send();
+	    }
+
+	}
+
+
+
+/**
+ * new password
+ */
+	public function newpwd( $user_id = null, $in_hash = null) {
+		$this->User->validate = $this->User->new_pwd_validate;
+
+	    // UserモデルにIDをセット
+	    $this->User->id = $user_id;
+	    if ($this->User->exists() && $in_hash == $this->User->getActivationHash()) {
+	        $this->Session->setFlash( '無効なURLです');
+			return $this->redirect(array('controller' => 'top', 'action' => 'index'));
+
+	    }else{
+		    if ($this->request->is(array('post', 'put'))) {
+
+				$this->set('user', $this->request->data);
+				if ($this->User->save($this->request->data)) {
+					return $this->redirect(array('action' => 'reset_pwd_comp_mail'));
+				} 
+			} else {
+			    $options = array('conditions' => array('User.id' => $user_id,'User.status' => 1));
+				$this->request->data = $this->User->find('first', $options);
+				$this->set('user', $this->request->data);
+					  //   	var_dump($this->request->data);
+		    	// exit;
+			}
+	    }
+
+	 //    $options = array('conditions' => array('User.id' => $user_id,'User.status' => 1));
+		// // $this->request->data = $this->set('user',$this->User->find('first', $options));
+		// $this->set('user',$this->User->find('first', $options));
+		// // $this->set('user', $this->request->data);
+
+
+	 //    // if ($this->User->exists() && $in_hash == $this->User->getActivationHash()) {
+	 //    // var_dump($this->request->data);
+	 //    // exit;
+	 //        if ($this->request->is(array('post', 'put'))) {
+		// 		// if($this->User->validates()){
+
+	 //            	$this->User->save($this->request->data);
+		// 			$this->redirect(array('action'=>'reset_pwd_comp_mail'));
+	 //     //        } else {
+		// 				// $this->Flash->loginerror('パスワードが一致しません。誤りがないかもう一度ご確認の上、正確にご入力ください。', array(
+		// 				//     'key' => 'positive',
+		// 				// 	));
+	 //     //        }
+	 //   //      } else {
+		// 	 //    $options = array('conditions' => array('User.id' => $user_id,'User.status' => 1));
+		// 		// $this->request->data = $this->set('user',$this->User->find('first', $options));
+		// 		// // $this->set('user', $this->request->data);
+	 //   //      $this->Session->setFlash( '無効なURLですaaa');
+	 //        // }
+
+
+	 //    }else{
+	 //    // 本登録に無効なURL
+	 //        $this->Session->setFlash( '無効なURLです');
+	 //    }
+	}
+
+/**
+ * 
+ */
+	public function reset_pwd_comp_mail() {
+		// if (!empty( $this->data)){
+		 //  保存
+		$this->User->validate = $this->User->new_pwd_validate;
+		    if( $this->User->save($this->request->data('user'))){
+		            //  メール送信
+			$this->set('register',$this->Session->read('register'));
+			$mail = $this->Session->read('register.User.email');
+			// exit;
+			$options = array('conditions' => array('User.email' => $mail));
+			$user = $this->User->find('first', $options);
+			$name = $user['User']['login_id'];
+
+	        // ユーザアクティベート(本登録)用URLの作成 DSはスラッシュの意味
+	        // $url = 
+	        //     DS . 'users' .          // コントローラ
+	        //     DS . 'newpwd' .                       // アクション
+	        //     DS . $user['User']['id'] .                  // ユーザID
+	        //     DS . $this->User->getActivationHash();  // ハッシュ値
+	        // $url = Router::url( $url, true);  // ドメイン(+サブディレクトリ)を付与
+			$comment = "本文本文本文本文本文本文本文本文";
+			$Email = new CakeEmail();
+			$Email->charset('ISO-2022-JP');
+			$Email->emailFormat('text');
+			$Email->template('comp_reset_pwd');
+			$Email->viewVars(array('name'=>$name,'comment'=>$comment));
+			$Email->from( MAIL_FROM ); //MAIL_FROM：Config/const.phpにて定義
+			$Email->to($mail);
+			$Email->subject('[PICT CODE]問い合わせ');
+			$Email->send();
+	    	}
+	    // }
+		// }else{
+	 //        exit;
+		// }
+debug($this->User->validationErrors);
+	}
+
+
 
 }
 
