commit 16e57cae68f57ca57a9efadd7f41c82be8cc5223
Author: hasse <hasegawa@i-hearts.jp>
Date:   Fri Mar 11 01:01:53 2016 -0500

    パスワード再設定100％

diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php
index f56f659..1ef6740 100755
--- a/app/Controller/UsersController.php
+++ b/app/Controller/UsersController.php
@@ -94,18 +94,18 @@ class UsersController extends AppController {
             DS . 'users' .          // コントローラ
             DS . 'activate' .                       // アクション
             DS . $this->User->id .                  // ユーザID
-            DS . $this->User->getActivationHash();  // ハッシュ値
+            DS . $this->User->activationHash();  // ハッシュ値
         $url = Router::url( $url, true);  // ドメイン(+サブディレクトリ)を付与
 		$comment = $url;
 
 		$Email = new CakeEmail();
 		$Email->charset('ISO-2022-JP');
 		$Email->emailFormat('text');
-		$Email->template('user_register');
+		$Email->template('register_mail');
 		$Email->viewVars(array('name'=>$name,'comment'=>$comment));
 		$Email->from( MAIL_FROM ); //MAIL_FROM：Config/const.phpにて定義
 		$Email->to($mail);
-		$Email->subject('[PICT CODE]問い合わせ');
+		$Email->subject('【PictCode】仮登録が完了しました。');
 		$Email->send();
 	    }
 
@@ -117,14 +117,29 @@ class UsersController extends AppController {
 	public function activate( $user_id = null, $in_hash = null) {
 	    // UserモデルにIDをセット
 	    $this->User->id = $user_id;
-	    if ($this->User->exists() && $in_hash == $this->User->getActivationHash()) {
+	    if ($this->User->exists() && $in_hash == $this->User->activationHash()) {
 	    // 本登録に有効なURL
 	        // statusフィールドを1に更新
 	        $this->User->saveField( 'status', 1);
 	        $this->Session->setFlash( 'Your account has been activated.');
+			
+			$mail = $this->Session->read('register.User.email');
+			// exit;
+
+			$Email = new CakeEmail();
+			$Email->charset('ISO-2022-JP');
+			$Email->emailFormat('text');
+			$Email->template('register_comp');
+			// $Email->viewVars(array('name'=>$name,'comment'=>$comment));
+			$Email->from( MAIL_FROM ); //MAIL_FROM：Config/const.phpにて定義
+			$Email->to($mail);
+			$Email->subject('【PictCode】本登録が完了しました。');
+			$Email->send();
+
 	    }else{
 	    // 本登録に無効なURL
 	        $this->Session->setFlash( 'Invalid activation URL');
+			return $this->redirect(array('controller' => 'top', 'action' => 'index'));
 	    }
 	}
 	
@@ -198,21 +213,11 @@ class UsersController extends AppController {
  * @return void
  */
 	public function login() {
-<<<<<<< HEAD
-		// if($this->Auth->user()){
-		// 	$this->redirect($this->Auth->redirectUrl());                          
-		// }
-=======
-		//var_dump(Security::hash( "123", 'blowfish'));
-		if($this->register->user()){
-			$this->redirect($this->Auth->redirectUrl());                          
+		if($this->Auth->user()){
+			// $this->redirect($this->Auth->redirectUrl());                          
+					$this->redirect('/users/login_top');                          
 		}
->>>>>>> origin/develop
 		if ($this->request->is('post')) {
-<<<<<<< HEAD
-			if ($this->register->login()) {
-				$this->redirect('/Users/login_top');                          
-=======
 			if ($this->Auth->login()) {
 		 //    $options = array('conditions' => array('User.email' => $this->Auth->user('User.email'),'User.status' => 1));
 			// $this->request->data = $this->User->find('first', $options);
@@ -224,7 +229,6 @@ class UsersController extends AppController {
 				    'key' => 'positive',
 					));
 				}
->>>>>>> 8fa10255c509b6b77d694b7366878172b605ee59
 			} else {
 				$this->Flash->loginerror('ニックネームか　パスワードにまちがいが あるよ！', array(
 				    'key' => 'positive',
@@ -240,7 +244,7 @@ class UsersController extends AppController {
  * @return void
  */
 	public function logout() {
-	    $this->redirect($this->register->logout());
+	    $this->redirect($this->Auth->logout());
 	}
 
 
@@ -292,7 +296,7 @@ class UsersController extends AppController {
 	            //  メール送信
 		$this->set('register',$this->Session->read('register'));
 		$mail = $this->Session->read('register.User.email');
-		$options = array('conditions' => array('User.email' => $mail));
+		$options = array('conditions' => array('User.email' => $mail, 'User.status' => 1));
 		$user = $this->User->find('first', $options);
 		$name = $user['User']['login_id'];
 
@@ -301,7 +305,7 @@ class UsersController extends AppController {
             DS . 'users' .          // コントローラ
             DS . 'newpwd' .                       // アクション
             DS . $user['User']['id'] .                  // ユーザID
-            DS . $this->User->getActivationHash();  // ハッシュ値
+            DS . $this->User->getActivationHash($user['User']['id']);  // ハッシュ値
         $url = Router::url( $url, true);  // ドメイン(+サブディレクトリ)を付与
 		$comment = $url;
 		$Email = new CakeEmail();
@@ -311,7 +315,7 @@ class UsersController extends AppController {
 		$Email->viewVars(array('name'=>$name,'comment'=>$comment));
 		$Email->from( MAIL_FROM ); //MAIL_FROM：Config/const.phpにて定義
 		$Email->to($mail);
-		$Email->subject('[PICT CODE]問い合わせ');
+		$Email->subject('【PictCode】パスワードの再発行を受け付けました。');
 		$Email->send();
 	    }
 
@@ -327,98 +331,62 @@ class UsersController extends AppController {
 
 	    // 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->User->exists() && $in_hash == $this->User->activationHash()) {
+	    	//idとハッシュ値が正規の場合、パスワード変更画面を表示
 		    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'));
+					return $this->redirect(array('action' => 'reset_pwd_comp_mail',$user_id));
 				} 
 			} 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;
 			}
-	    }
+	    }else{
+	    	//idとハッシュ値が不正の場合、トップページにリダイレクト
+			$this->Session->setFlash( '無効なURLです');
+			return $this->redirect(array('controller' => 'top', 'action' => 'index'));
 
-	 //    $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'));
+	public function reset_pwd_comp_mail($user_id = null) {
+		// $options = array('conditions' => array('User.' . $this->User->primaryKey => $user_id));
+		// $this->request->data = $this->User->find('first', $options);
+		// //バリデーションを無効にして保存
+		// $this->User->validate = $this->User->reset_pwd_comp_mail_validate;
+
+		// if( $this->User->save($this->request->data)){
+		// var_dump($this->request->data['User']);
+		// exit;
+		if( !isset($this->request->data['User'])){
+		// $this->User->save($this->request->data,false);
+		    //  メール送信
 			$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->viewVars(array('name'=>$name,'comment'=>$comment));
 			$Email->from( MAIL_FROM ); //MAIL_FROM：Config/const.phpにて定義
 			$Email->to($mail);
-			$Email->subject('[PICT CODE]問い合わせ');
+			$Email->subject('【PictCode】パスワードの再設定が完了しました。');
 			$Email->send();
-	    	}
-	    // }
-		// }else{
-	 //        exit;
-		// }
-debug($this->User->validationErrors);
+	    }
+	    else{
+		$options = array('conditions' => array('User.' . $this->User->primaryKey => $user_id));
+		$this->request->data = $this->User->find('first', $options);
+		//バリデーションを無効にして保存
+		// $this->User->validate = $this->User->reset_pwd_comp_mail_validate;
+		$this->User->save($this->request->data,false);
+	    }
+
 	}
 
 
