pictcode / app / Controller / UsersController.php @ d6c3d8de
履歴 | 表示 | アノテート | ダウンロード (3.187 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 | // var $name = 'users';
|
||
13 | 5ec4ad9d | admin | |
14 | public function beforeFilter() { |
||
15 | parent::beforeFilter();
|
||
16 | d6c3d8de | root | $this->Auth->allow('add'); |
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 | /**
|
||
52 | * add method
|
||
53 | *
|
||
54 | * @return void
|
||
55 | */
|
||
56 | public function add() { |
||
57 | if ($this->request->is('post')) { |
||
58 | $this->User->create(); |
||
59 | if ($this->User->save($this->request->data)) { |
||
60 | $this->Flash->success(__('The user has been saved.')); |
||
61 | return $this->redirect(array('action' => 'index')); |
||
62 | } else {
|
||
63 | $this->Flash->error(__('The user could not be saved. Please, try again.')); |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | |||
68 | /**
|
||
69 | * edit method
|
||
70 | *
|
||
71 | * @throws NotFoundException
|
||
72 | * @param string $id
|
||
73 | * @return void
|
||
74 | */
|
||
75 | public function edit($id = null) { |
||
76 | if (!$this->User->exists($id)) { |
||
77 | throw new NotFoundException(__('Invalid user')); |
||
78 | } |
||
79 | if ($this->request->is(array('post', 'put'))) { |
||
80 | if ($this->User->save($this->request->data)) { |
||
81 | $this->Flash->success(__('The user has been saved.')); |
||
82 | return $this->redirect(array('action' => 'index')); |
||
83 | } else {
|
||
84 | $this->Flash->error(__('The user could not be saved. Please, try again.')); |
||
85 | } |
||
86 | } else {
|
||
87 | $options = array('conditions' => array('User.' . $this->User->primaryKey => $id)); |
||
88 | $this->request->data = $this->User->find('first', $options); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | /**
|
||
93 | * delete method
|
||
94 | *
|
||
95 | * @throws NotFoundException
|
||
96 | * @param string $id
|
||
97 | * @return void
|
||
98 | */
|
||
99 | public function delete($id = null) { |
||
100 | $this->User->id = $id; |
||
101 | if (!$this->User->exists()) { |
||
102 | throw new NotFoundException(__('Invalid user')); |
||
103 | } |
||
104 | $this->request->allowMethod('post', 'delete'); |
||
105 | if ($this->User->delete()) { |
||
106 | $this->Flash->success(__('The user has been deleted.')); |
||
107 | } else {
|
||
108 | $this->Flash->error(__('The user could not be deleted. Please, try again.')); |
||
109 | } |
||
110 | return $this->redirect(array('action' => 'index')); |
||
111 | } |
||
112 | |||
113 | /**
|
||
114 | * login method
|
||
115 | *
|
||
116 | * @throws NotFoundException
|
||
117 | * @param string $id
|
||
118 | * @return void
|
||
119 | */
|
||
120 | public function login() { |
||
121 | //var_dump(Security::hash( "123", 'blowfish'));
|
||
122 | if($this->Auth->user()){ |
||
123 | $this->redirect($this->Auth->redirectUrl()); |
||
124 | } |
||
125 | if ($this->request->is('post')) { |
||
126 | if ($this->Auth->login()) { |
||
127 | $this->redirect($this->Auth->redirectUrl()); |
||
128 | } else {
|
||
129 | $this->Flash->error(__('login error')); |
||
130 | } |
||
131 | } |
||
132 | } |
||
133 | /**
|
||
134 | * logout method
|
||
135 | *
|
||
136 | * @throws NotFoundException
|
||
137 | * @param string $id
|
||
138 | * @return void
|
||
139 | */
|
||
140 | public function logout() { |
||
141 | $this->redirect($this->Auth->logout()); |
||
142 | } |
||
143 | } |