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