リビジョン 04e657a7 app/Controller/UsersController.php
| app/Controller/UsersController.php | ||
|---|---|---|
| 9 | 9 |
class UsersController extends AppController {
|
| 10 | 10 |
|
| 11 | 11 |
public $layout = 'procedure'; |
| 12 |
// var $name = 'users'; |
|
| 13 | 12 |
|
| 14 | 13 |
public function beforeFilter() {
|
| 15 | 14 |
parent::beforeFilter(); |
| 16 |
$this->Auth->allow('add');
|
|
| 15 |
$this->Auth->allow('register','activate');
|
|
| 17 | 16 |
} |
| 18 | 17 |
|
| 19 | 18 |
/** |
| ... | ... | |
| 48 | 47 |
$this->set('user', $this->User->find('first', $options));
|
| 49 | 48 |
} |
| 50 | 49 |
|
| 50 |
|
|
| 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 |
|
|
| 51 | 159 |
/** |
| 52 | 160 |
* add method |
| 53 | 161 |
* |
| ... | ... | |
| 140 | 248 |
public function logout() {
|
| 141 | 249 |
$this->redirect($this->Auth->logout()); |
| 142 | 250 |
} |
| 251 |
|
|
| 252 |
|
|
| 253 |
|
|
| 143 | 254 |
} |
| 255 |
|
|
| 256 |
|
|
他の形式にエクスポート: Unified diff