pictcode / app / Controller / UsersController.php @ 93b01961
履歴 | 表示 | アノテート | ダウンロード (5.705 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 | 8b8631af | hasse | $this->Auth->allow('register','activate','confirm','sent','login'); |
| 18 | 5ec4ad9d | admin | } |
| 19 | |||
| 20 | /**
|
||
| 21 | * Components
|
||
| 22 | *
|
||
| 23 | * @var array
|
||
| 24 | */
|
||
| 25 | public $components = array('Paginator'); |
||
| 26 | |||
| 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 | 8b8631af | hasse | $Email->from('hasegawa@i-hearts.jp'); |
| 107 | $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 | 93b01961 | 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 | if($this->Auth->user()){ |
||
| 203 | $this->redirect($this->Auth->redirectUrl()); |
||
| 204 | } |
||
| 205 | if ($this->request->is('post')) { |
||
| 206 | if ($this->Auth->login()) { |
||
| 207 | ceb21f43 | hasse | $this->redirect('/Users/login_top'); |
| 208 | 5ec4ad9d | admin | } else {
|
| 209 | 93b01961 | hasse | $this->Flash->loginerror('ニックネームか パスワードにまちがいが あるよ!', array( |
| 210 | 'key' => 'positive', |
||
| 211 | )); |
||
| 212 | 5ec4ad9d | admin | } |
| 213 | } |
||
| 214 | } |
||
| 215 | /**
|
||
| 216 | ceb21f43 | hasse | * logout methods
|
| 217 | 5ec4ad9d | admin | *
|
| 218 | * @throws NotFoundException
|
||
| 219 | * @param string $id
|
||
| 220 | * @return void
|
||
| 221 | */
|
||
| 222 | public function logout() { |
||
| 223 | $this->redirect($this->Auth->logout()); |
||
| 224 | } |
||
| 225 | 04e657a7 | root | |
| 226 | |||
| 227 | ceb21f43 | hasse | /**
|
| 228 | * login_top method
|
||
| 229 | *
|
||
| 230 | */
|
||
| 231 | public function login_top() { |
||
| 232 | } |
||
| 233 | |||
| 234 | |||
| 235 | 04e657a7 | root | |
| 236 | 5ec4ad9d | admin | } |
| 237 | 04e657a7 | root |