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