Subversion Repositories SmartDukaan

Rev

Rev 13532 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * UserAccounts Controller
5
 *
6
 * @property UserAccount $UserAccount
7
 * @property PaginatorComponent $Paginator
8
 */
9
class UserAccountsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
13673 anikendra 18
	public function beforeFilter() {		
19
		parent::beforeFilter();
20
		$this->Auth->allow('saholic');
21
		$this->apihost = Configure::read('pythonapihost');
22
	}
23
 
24
	public function saholic($userId=null){
25
		$this->response->type('json');
26
		$this->layout = 'ajax';
27
		if(!$userId){
28
			$result = array('success'=>false,'message'=>'UserId is missing','account_key'=>-1);
29
		}else{
30
			$options = array('conditions'=>array('user_id'=>$userId,'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'account_key');
31
			$userAccount = $this->UserAccount->find('first',$options);
32
			if(empty($userAccount)){
33
				$result = array('success'=>false,'message'=>'UserId not present in our system','account_key'=>-1);
34
			}else{
35
				$result = array('success'=>true,'message'=>'UserId present in our system','account_key'=>$userAccount['UserAccount']['account_key']);
36
			}
37
		}
38
		$this->set(array(
39
		    'result' => $result,
40
		    // 'callback' => $callback,
41
		    '_serialize' => array('result')
42
		));
43
		$this->render('/Elements/json');	
44
	}
13532 anikendra 45
/**
46
 * index method
47
 *
48
 * @return void
49
 */
50
	public function index() {
51
		$this->UserAccount->recursive = 0;
52
		$this->set('userAccounts', $this->Paginator->paginate());
53
	}
54
 
55
/**
56
 * view method
57
 *
58
 * @throws NotFoundException
59
 * @param string $id
60
 * @return void
61
 */
62
	public function view($id = null) {
63
		if (!$this->UserAccount->exists($id)) {
64
			throw new NotFoundException(__('Invalid user account'));
65
		}
66
		$options = array('conditions' => array('UserAccount.' . $this->UserAccount->primaryKey => $id));
67
		$this->set('userAccount', $this->UserAccount->find('first', $options));
68
	}
69
 
70
/**
71
 * add method
72
 *
73
 * @return void
74
 */
75
	public function add() {
76
		if ($this->request->is('post')) {
77
			$this->UserAccount->create();
78
			if ($this->UserAccount->save($this->request->data)) {
79
				$this->Session->setFlash(__('The user account has been saved.'));
80
				return $this->redirect(array('action' => 'index'));
81
			} else {
82
				$this->Session->setFlash(__('The user account could not be saved. Please, try again.'));
83
			}
84
		}
85
		$users = $this->UserAccount->User->find('list');
86
		$this->set(compact('users'));
87
	}
88
 
89
/**
90
 * edit method
91
 *
92
 * @throws NotFoundException
93
 * @param string $id
94
 * @return void
95
 */
96
	public function edit($id = null) {
97
		if (!$this->UserAccount->exists($id)) {
98
			throw new NotFoundException(__('Invalid user account'));
99
		}
100
		if ($this->request->is(array('post', 'put'))) {
101
			if ($this->UserAccount->save($this->request->data)) {
102
				$this->Session->setFlash(__('The user account has been saved.'));
103
				return $this->redirect(array('action' => 'index'));
104
			} else {
105
				$this->Session->setFlash(__('The user account could not be saved. Please, try again.'));
106
			}
107
		} else {
108
			$options = array('conditions' => array('UserAccount.' . $this->UserAccount->primaryKey => $id));
109
			$this->request->data = $this->UserAccount->find('first', $options);
110
		}
111
		$users = $this->UserAccount->User->find('list');
112
		$this->set(compact('users'));
113
	}
114
 
115
/**
116
 * delete method
117
 *
118
 * @throws NotFoundException
119
 * @param string $id
120
 * @return void
121
 */
122
	public function delete($id = null) {
123
		$this->UserAccount->id = $id;
124
		if (!$this->UserAccount->exists()) {
125
			throw new NotFoundException(__('Invalid user account'));
126
		}
127
		$this->request->onlyAllow('post', 'delete');
128
		if ($this->UserAccount->delete()) {
129
			$this->Session->setFlash(__('The user account has been deleted.'));
130
		} else {
131
			$this->Session->setFlash(__('The user account could not be deleted. Please, try again.'));
132
		}
133
		return $this->redirect(array('action' => 'index'));
134
	}
135
 
136
/**
137
 * admin_index method
138
 *
139
 * @return void
140
 */
141
	public function admin_index() {
142
		$this->UserAccount->recursive = 0;
143
		$this->set('userAccounts', $this->Paginator->paginate());
144
	}
145
 
146
/**
147
 * admin_view method
148
 *
149
 * @throws NotFoundException
150
 * @param string $id
151
 * @return void
152
 */
153
	public function admin_view($id = null) {
154
		if (!$this->UserAccount->exists($id)) {
155
			throw new NotFoundException(__('Invalid user account'));
156
		}
157
		$options = array('conditions' => array('UserAccount.' . $this->UserAccount->primaryKey => $id));
158
		$this->set('userAccount', $this->UserAccount->find('first', $options));
159
	}
160
 
161
/**
162
 * admin_add method
163
 *
164
 * @return void
165
 */
166
	public function admin_add() {
167
		if ($this->request->is('post')) {
168
			$this->UserAccount->create();
169
			if ($this->UserAccount->save($this->request->data)) {
170
				$this->Session->setFlash(__('The user account has been saved.'));
171
				return $this->redirect(array('action' => 'index'));
172
			} else {
173
				$this->Session->setFlash(__('The user account could not be saved. Please, try again.'));
174
			}
175
		}
176
		$users = $this->UserAccount->User->find('list');
177
		$this->set(compact('users'));
178
	}
179
 
180
/**
181
 * admin_edit method
182
 *
183
 * @throws NotFoundException
184
 * @param string $id
185
 * @return void
186
 */
187
	public function admin_edit($id = null) {
188
		if (!$this->UserAccount->exists($id)) {
189
			throw new NotFoundException(__('Invalid user account'));
190
		}
191
		if ($this->request->is(array('post', 'put'))) {
192
			if ($this->UserAccount->save($this->request->data)) {
193
				$this->Session->setFlash(__('The user account has been saved.'));
194
				return $this->redirect(array('action' => 'index'));
195
			} else {
196
				$this->Session->setFlash(__('The user account could not be saved. Please, try again.'));
197
			}
198
		} else {
199
			$options = array('conditions' => array('UserAccount.' . $this->UserAccount->primaryKey => $id));
200
			$this->request->data = $this->UserAccount->find('first', $options);
201
		}
202
		$users = $this->UserAccount->User->find('list');
203
		$this->set(compact('users'));
204
	}
205
 
206
/**
207
 * admin_delete method
208
 *
209
 * @throws NotFoundException
210
 * @param string $id
211
 * @return void
212
 */
213
	public function admin_delete($id = null) {
214
		$this->UserAccount->id = $id;
215
		if (!$this->UserAccount->exists()) {
216
			throw new NotFoundException(__('Invalid user account'));
217
		}
218
		$this->request->onlyAllow('post', 'delete');
219
		if ($this->UserAccount->delete()) {
220
			$this->Session->setFlash(__('The user account has been deleted.'));
221
		} else {
222
			$this->Session->setFlash(__('The user account could not be deleted. Please, try again.'));
223
		}
224
		return $this->redirect(array('action' => 'index'));
225
	}}