統計
| ブランチ: | リビジョン:

pictcode / app / Controller / UsersController.php @ 001918d1

履歴 | 表示 | アノテート | ダウンロード (6.229 KB)

1
<?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
        public $layout = 'procedure';
12
        public $name = 'users';
13
        public $uses = array('User');
14

    
15
    public function beforeFilter() {
16
        parent::beforeFilter();
17
        $this->Auth->allow('register','activate','confirm','sent','login','index');
18
    }
19

    
20
/**
21
 * Components
22
 *
23
 * @var array
24
 */
25
        public $components = array('Paginator','Recaptcha.Recaptcha');
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

    
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
                $name = $this->Session->read('register.User.login_id');
91
                $mail = $this->Session->read('register.User.email');
92
        // ユーザアクティベート(本登録)用URLの作成 DSはスラッシュの意味
93
        $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
                $Email->from( MAIL_FROM ); //MAIL_FROM:Config/const.phpにて定義
107
                $Email->to($mail);
108
                $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
                // statusフィールドを1に更新
123
                $this->User->saveField( 'status', 1);
124
                $this->Session->setFlash( 'Your account has been activated.');
125
            }else{
126
            // 本登録に無効なURL
127
                $this->Session->setFlash( 'Invalid activation URL');
128
            }
129
        }
130
        
131
/**
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->register->user()){
203
                        $this->redirect($this->Auth->redirectUrl());                          
204
                }
205
                if ($this->request->is('post')) {
206
<<<<<<< HEAD
207
                        if ($this->register->login()) {
208
                                $this->redirect('/Users/login_top');                          
209
=======
210
                        if ($this->Auth->login()) {
211
                                // 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
>>>>>>> 8fa10255c509b6b77d694b7366878172b605ee59
221
                        } else {
222
                                $this->Flash->loginerror('ニックネームか パスワードにまちがいが あるよ!', array(
223
                                    'key' => 'positive',
224
                                        ));
225
                        }
226
                }
227
        }        
228
/**
229
 * logout methods
230
 *
231
 * @throws NotFoundException
232
 * @param string $id
233
 * @return void
234
 */
235
        public function logout() {
236
            $this->redirect($this->register->logout());
237
        }
238

    
239

    
240
/**
241
 * login_top method
242
 *
243
 */
244
        public function login_top() {
245
        }
246

    
247

    
248

    
249
}
250

    
251