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

pictcode / app / Controller / UsersController.php @ 5ec4ad9d

履歴 | 表示 | アノテート | ダウンロード (3.144 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
        public $layout = 'top';
12
        var $name = 'users';
13
14
    public function beforeFilter() {
15
        parent::beforeFilter();
16
    }
17
18
/**
19
 * Components
20
 *
21
 * @var array
22
 */
23
        public $components = array('Paginator');
24
25
/**
26
 * index method
27
 *
28
 * @return void
29
 */
30
        public function index() {
31
                $this->User->recursive = 0;
32
                $this->set('users', $this->Paginator->paginate());
33
        }
34
35
/**
36
 * view method
37
 *
38
 * @throws NotFoundException
39
 * @param string $id
40
 * @return void
41
 */
42
        public function view($id = null) {
43
                if (!$this->User->exists($id)) {
44
                        throw new NotFoundException(__('Invalid user'));
45
                }
46
                $options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
47
                $this->set('user', $this->User->find('first', $options));
48
        }
49
50
/**
51
 * add method
52
 *
53
 * @return void
54
 */
55
        public function add() {
56
                if ($this->request->is('post')) {
57
                        $this->User->create();
58
                        if ($this->User->save($this->request->data)) {
59
                                $this->Flash->success(__('The user has been saved.'));
60
                                return $this->redirect(array('action' => 'index'));
61
                        } else {
62
                                $this->Flash->error(__('The user could not be saved. Please, try again.'));
63
                        }
64
                }
65
        }
66
67
/**
68
 * edit method
69
 *
70
 * @throws NotFoundException
71
 * @param string $id
72
 * @return void
73
 */
74
        public function edit($id = null) {
75
                if (!$this->User->exists($id)) {
76
                        throw new NotFoundException(__('Invalid user'));
77
                }
78
                if ($this->request->is(array('post', 'put'))) {
79
                        if ($this->User->save($this->request->data)) {
80
                                $this->Flash->success(__('The user has been saved.'));
81
                                return $this->redirect(array('action' => 'index'));
82
                        } else {
83
                                $this->Flash->error(__('The user could not be saved. Please, try again.'));
84
                        }
85
                } else {
86
                        $options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
87
                        $this->request->data = $this->User->find('first', $options);
88
                }
89
        }
90
91
/**
92
 * delete method
93
 *
94
 * @throws NotFoundException
95
 * @param string $id
96
 * @return void
97
 */
98
        public function delete($id = null) {
99
                $this->User->id = $id;
100
                if (!$this->User->exists()) {
101
                        throw new NotFoundException(__('Invalid user'));
102
                }
103
                $this->request->allowMethod('post', 'delete');
104
                if ($this->User->delete()) {
105
                        $this->Flash->success(__('The user has been deleted.'));
106
                } else {
107
                        $this->Flash->error(__('The user could not be deleted. Please, try again.'));
108
                }
109
                return $this->redirect(array('action' => 'index'));
110
        }
111
112
/**
113
 * login method
114
 *
115
 * @throws NotFoundException
116
 * @param string $id
117
 * @return void
118
 */
119
        public function login() {
120
                //var_dump(Security::hash( "123", 'blowfish'));
121
                if($this->Auth->user()){
122
                        $this->redirect($this->Auth->redirectUrl());                          
123
                }
124
                if ($this->request->is('post')) {
125
                        if ($this->Auth->login()) {
126
                                $this->redirect($this->Auth->redirectUrl());                          
127
                        } else {
128
                                $this->Flash->error(__('login error'));
129
                        }
130
                }
131
        }        
132
/**
133
 * logout method
134
 *
135
 * @throws NotFoundException
136
 * @param string $id
137
 * @return void
138
 */
139
        public function logout() {
140
            $this->redirect($this->Auth->logout());
141
        }
142
}