Subversion Repositories SmartDukaan

Rev

Rev 14445 | Rev 14768 | Go to most recent revision | 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
 * Users Controller
5
 *
6
 * @property User $User
7
 */
14408 anikendra 8
 
9
set_time_limit(0);
10
 
13532 anikendra 11
class UsersController extends AppController {
12
 
14395 anikendra 13
	public $components = array('SignMeUp.SignMeUp','RequestHandler','Cookie','Paginator');
13532 anikendra 14
 
15
    public function beforeFilter() {
16
    	parent::beforeFilter();
17
    	// $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'dashboard');
18
    	$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display','home');
14395 anikendra 19
        $this->Auth->allow(array('mine','login', 'forgotten_password', 'register', 'activate', 'checkemail','checkfbuser','registertwitteruser','skipmobileverification','reauthenticate','edit','mywallet','admin_index')); 
13736 anikendra 20
		$this->Cookie->name = 'profittill';
21
		$this->Cookie->time = 86400*30; 
22
		$this->Cookie->path = '/';
23
		$this->Cookie->key = 'qSI232qs*&sXOw!adre@34SAv!@*(XSL#$%)asGb$@11~_+!@#H23s~#^';
24
		$this->Cookie->httpOnly = true;
13532 anikendra 25
    }
26
 
27
	public function bookmarklet() {
13714 anikendra 28
		$this->set('title_for_layout','Profittill Bookmarklet');
13532 anikendra 29
	}
30
 
14019 anikendra 31
	public function mywallet() {
32
		$userId = $this->request->query('user_id');
14150 anikendra 33
		if(isset($userId) && !empty($userId)){	
14441 anikendra 34
			$next = "/my-wallet";					
14150 anikendra 35
			$redirectUrl = $this->getAutoLoginUrl($userId,$next);
14019 anikendra 36
			header('location:'.$redirectUrl);
37
			exit();
38
		}
39
	}
40
 
13740 anikendra 41
	public function mine() {
13758 anikendra 42
		$this->response->type('json');
43
		$this->layout = 'ajax';
13740 anikendra 44
		$userId = $this->request->query('user_id');
45
		if(isset($userId) && !empty($userId)){
46
			$this->loadModel('User');
13758 anikendra 47
			$options = array('conditions'=>array('User.id'=>$userId),'fields'=>array('username','email','first_name','profile_pic','mobile_number','mobile_verified','address_line_1','address_line_2',
48
				'city','state','pincode','referrer'),'recursive'=>-1);
13763 anikendra 49
			$user = $this->User->find('first',$options);
50
			$result = $user['User'];
13740 anikendra 51
		}
13758 anikendra 52
		$this->set(array(
53
		    'result' => $result,
54
		    '_serialize' => array('result')
55
		)); 
56
		$this->render('/Elements/json'); 
13740 anikendra 57
	}
58
 
13532 anikendra 59
	function registertwitteruser(){
60
		$this->twitterObj->setToken($_GET['oauth_token']);
61
		$token = $this->twitterObj->getAccessToken();
62
		$this->twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
63
		$twitterInfo= $this->twitterObj->get_accountVerify_credentials();
64
		$data = array();
65
		$data['twitter_id'] = $twitterInfo->id;		
66
		$this->Session->write('twtusername',$twitterInfo->screen_name);
67
		$data['twitter_token'] = $token->oauth_token;
68
		$data['twitter_secret'] = $token->oauth_token_secret;
69
		$data['twitter_screen_name'] = $twitterInfo->screen_name;					
70
		$data['active'] = 1;
71
 
72
		$id = $this->Auth->user('id');
73
		if(!isset($id) || $id == ''){
74
		//	$count = $this->User->find('count',array('conditions' => array('twitter_id' => $data['twitter_id'])));
75
			$user = $this->User->find('first',array('conditions' => array('twitter_id' => $data['twitter_id'])));
76
			//if($count<1){
77
			if(empty($user)){
78
				$this->User->create();
79
				$this->User->save($data);
80
//				$dbuser = $this->User->read(null,$this->User->id);
81
				$this->Auth->login($this->User->data);
82
			}else{
83
		//		$data = $this->User->find('first',array('conditions' => array('twitter_id' => $data['twitter_id'])));
84
				$this->Auth->login($user['User']);
85
			}
86
		}else{
87
			//$data['id'] = $this->Auth->user('id');
88
			$user = $this->Auth->user;
89
//			$this->User->save($data);
90
//			$this->Auth->login($data);
91
		}                
92
		$user = $this->User->read(null, $this->Auth->User('id'));
93
		if ($user['User']['group_id'] == 1) {
94
			//$this->redirect(array('controller'=>'users','action'=>'dashboard','?userid='.$this->Auth->user('id')));
95
			header('location:users/dashboard?userid='.$this->Auth->user('id'));
96
			exit();
97
		}
98
		elseif ($user['User']['group_id'] == 2) {
99
			$this->redirect(array('controller' => 'administration', 'action' => 'dashboard'));
100
			exit();
101
		}
102
	}
103
 
104
    public function checkfbuser($accessToken=null){
105
		$sessionState = $this->Session->read('state');
106
		if($sessionState != $_GET['state']) {
107
			$this->redirect(array('controller'=>'users','action'=>'login'));
108
		}
109
		else {
110
			if(isset($_GET['code'])){
111
				$code = $_GET['code'];
112
				$facebookConfig = Configure::read("Facebook");		
113
				$token_url = "https://graph.facebook.com/oauth/access_token?"
114
			       . "client_id=" . $facebookConfig['fbappid'] . "&redirect_uri=" . urlencode($facebookConfig['base_url'].'/users/checkfbuser/')
115
			       . "&client_secret=" . $facebookConfig['secret'] . "&code=" . $code;
116
 
117
			    $response = file_get_contents($token_url);
118
			    $params = null;
119
			    parse_str($response, $params);
120
			    $accessToken = $params['access_token'];
121
			}else{
122
				$this->redirect(array('controller'=>'users','action'=>'login'));
123
			}
124
		}
125
		$this->User->recursive = -1;
126
		if (!$accessToken) {
127
		    $this->redirect(array('controller'=>'users','action'=>'login'));
128
		    //$this->redirect(array('controller'=>'pages','action'=>'display','home'));
129
		}        
130
		if (isset($accessToken) && $accessToken != 'undefined') {			
131
 
132
		    $graph_url = "https://graph.facebook.com/me?access_token=" . $accessToken;
133
 
134
		    $user = json_decode(file_get_contents($graph_url));
135
			$this->log("FB user = ".print_r($user,1),'fb');
136
		    if (!empty($user)) {
137
			if (!$this->isAuthorized()) {
138
			    $id = $this->User->checkFbUser($user,$accessToken);
139
				$dbuser = $this->User->findById($id);
140
			    $this->Session->write('facebook_id',$user->id);
141
				$this->Auth->login($dbuser['User']);
142
				if($this->Auth->login()){
143
					$this->log("logged = ".print_r($this->Auth->user('id'),1)."\n",'fb');
144
				}
145
			    $next = $this->Session->read('next');
146
				$this->log("next= ".$next."\n",'fb');
147
 
148
			    if (!empty($next)) {
149
					header('Location:' . $next);
150
					exit();
151
			    }else {
152
					//$this->redirect(array('controller'=>'users','action'=>'dashboard','?userid='.$this->Auth->user('id')));
153
					header('location:users/dashboard?userid='.$this->Auth->user('id'));
154
					exit();
155
			            }
156
					//$this->redirect(array('controller'=>'users','action'=>'dashboard','?userid='.$this->Auth->user('id')));
157
					header('location:users/dashboard?userid='.$this->Auth->user('id'));
158
					exit();
159
				} else {                	
160
					//$this->redirect(array('controller'=>'users','action'=>'dashboard','?userid='.$this->Auth->user('id')));
161
					header('location:users/dashboard?userid='.$this->Auth->user('id'));
162
					exit();
163
				}
164
		    }
165
		}
166
    }
167
 
168
	public function uploadavatar(){
169
		$this->log(print_r($_FILES,1),'debug');
170
		$path = "img/avatars/";
171
		$valid_formats = array("jpg", "png", "gif", "bmp");
172
		if ($this->request->is('post')) {
173
			$name = $_FILES['photoimg']['name'];
174
			$size = $_FILES['photoimg']['size'];
175
 
176
			if(strlen($name))
177
				{
178
					list($txt, $ext) = explode(".", $name);
179
					if(in_array($ext,$valid_formats))
180
					{
181
					if($size<(1024*1024))
182
						{
183
							$actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
184
							$tmp = $_FILES['photoimg']['tmp_name'];
185
							if(move_uploaded_file($tmp, $path.$actual_image_name))
186
								{
187
									echo "<img width='250' src='../".$path.$actual_image_name."'  class='preview'>";
188
									echo "<input type='hidden' id='imageUrl' name='photo_url' value='".'http://' . $_SERVER['SERVER_NAME'] . Router::url('/').$path.$actual_image_name."'></input>";
189
								}
190
							else
191
								echo __('Upload Failed');
192
						}
193
						else
194
						echo __("Maximum allowed image file size is 1 MB");					
195
						}
196
						else
197
						echo __("Invalid file format");	
198
				}
199
			else
200
				echo __("Please select image");
201
			exit;
202
		}
203
	}
204
 
205
    function checkemail() {
206
        $this->User->recursive = -1;
207
        $this->layout = 'ajax';
208
        if (!empty($this->params['url']['data']['User']['email'])) {
209
            $username = $this->params['url']['data']['User']['email'];
210
        } elseif (!empty($this->params['url']['data']['Doctor']['email'])) {
211
            $username = $this->params['url']['data']['Doctor']['email'];
212
        } else {
213
            $result = false;
214
            $this->set('result', $result);
215
        }
216
        if ($this->Auth->user('id') != null) {
217
            $conditions = array('User.email' => $username, 'User.id !=' => $this->Auth->user('id'));
218
        } else {
219
            $conditions = array('User.email' => $username);
220
        }
221
        $count = $this->User->find('count', array('conditions' => $conditions));
222
        if ($count > 0) {
223
            $result = false;
224
        } else {
225
            $result = true;
226
        }
227
        $this->set('result', $result);
228
    }
229
 
230
/**
231
 * view method
232
 *
233
 * @throws NotFoundException
234
 * @param string $id
235
 * @return void
236
 */
237
	public function view($id = null) {
238
		$this->response->type('json');
239
		$this->layout = 'ajax';
240
		$callback = $this->request->query('callback');
241
		$this->User->id = $id;
242
		if (!$this->User->exists()) {
243
			throw new NotFoundException(__('Invalid user'));
244
		}
245
		$user = $this->User->find('first', array('conditions' =>array('id' => $id),'recursive'=>-1));
246
		$result = array('user'=>$user);
247
		$this->set(array(
248
		    'result' => $result,
249
		    'callback' => $callback,
250
		    '_serialize' => array('result')
251
		));
13736 anikendra 252
		$this->render('/Elements/json');
13532 anikendra 253
	}
254
/**
255
 * edit method
256
 *
257
 * @throws NotFoundException
258
 * @param string $id
259
 * @return void
260
 */
261
 
13736 anikendra 262
    public function edit($id = null) {
13900 anikendra 263
	$this->log(print_r($this->request->data,1),'mydetails');
14300 anikendra 264
	$this->response->type('json');
13900 anikendra 265
	$this->layout = 'ajax';
266
	$this->User->recursive = -1;
13736 anikendra 267
        if (!$this->User->exists($id)) {
14300 anikendra 268
			$result = array('success'=>false,'message'=>'Invalid user');
13736 anikendra 269
		} else {
270
	        if ($this->request->is('post') || $this->request->is('put')) {
14316 anikendra 271
               		if(!empty($this->request->data['mobile_number']) && empty($this->request->data['mobile_verified'])){
272
				$options = array('conditions'=>array('User.id'=>$id),'fields'=>array('mobile_number'),'recursive'=>-1);
273
				$oldMobile = $this->User->find('first',$options);
274
				if($this->request->data['mobile_number'] != $oldMobile['User']['mobile_number']) {
275
		        		$this->request->data['mobile_verified'] = 0;
276
				}
14300 anikendra 277
	        	}
13736 anikendra 278
	            if ($this->User->save($this->request->data)) {
279
	                $result = array('success'=>true,'message'=>'Your profile has been saved');
280
	            } else {
281
	                $result = array('success'=>false,'message'=> 'The user could not be saved. Please, try again.');
282
	            }
283
	        }  
284
	    }
285
        $this->set(array(
286
		    'result' => $result,
287
		    '_serialize' => array('result')
288
		)); 
289
		$this->render('/Elements/json');      
13532 anikendra 290
    }
291
 
292
/**
293
 * admin_index method
294
 *
295
 * @return void
296
 */
14408 anikendra 297
 
298
	public function admin_pushnotifications(){
299
		if ($this->request->is('post')) {
300
			$sql = $this->request->data['User']['sql'];
301
			if(!empty($sql)){
302
				$users = $this->User->query($sql);
303
				$this->set(compact('users'));
304
			}
305
		}
306
	}
307
 
14445 anikendra 308
	public function generateAffiliateUrl($url,$user_id,$store){
309
		//Get StoreProduct Info		
14428 anikendra 310
		$storeId = $store['Store']['id'];
311
		$prefix = "SHA".$storeId;
312
		$tag = $prefix.time();
313
		if($storeId == 2){				
314
			$url = str_replace('www','m',$url);
315
		} elseif($storeId == 3) {
316
			$url_parts = parse_url($url);
317
			$url_parts['path'] = str_replace('viewAllSellers/','',$url_parts['path']);//quickfix for snapdeal
318
			if(isset($url_parts['query'])) {
319
				$url = "http://m.snapdeal.com".$url_parts['path'].'?'.$url_parts['query']."&utm_source=aff_prog&utm_campaign=afts&offer_id=17";
320
			}else{
321
				$url = "http://m.snapdeal.com".$url_parts['path'].'?utm_source=aff_prog&utm_campaign=afts&offer_id=17';
322
			}
323
		} elseif($storeId == 4){
14445 anikendra 324
			$next = str_replace('www','m',$url);	
14428 anikendra 325
			$url = $this->getAutoLoginUrl($userId,$next);
326
			$url .= '?utm_source=profitmandi';
327
		}
328
		if( strpos($url, '?') === false ) {
329
			$firstChar = '?';
330
		} else {
331
			$firstChar = '&';
332
		}
333
		$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
334
		if(!empty($store['Store']['sub_tag_param'])){
335
			$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
336
		}
337
		$extras = array('store'=>$store['Store']['name'],'source'=>'notification');
338
		$data = array('user_id' => $user_id,'store_product_id'=>0,'tag'=>$tag,'url'=>$url,'price'=>0,'extras'=>json_encode($extras));
339
		$this->loadModel('Click');
340
		$this->Click->create();
341
		$this->Click->save($data);
342
		return $url;
343
	}
344
 
14408 anikendra 345
	public function admin_push(){
346
		if ($this->request->is('post')) {
347
			if(empty($this->request->data['userIds'])){
348
				$this->Session->setFlash(__('Please choose a few users'));
349
				$this->redirect(array('action' => 'admin_pushnotifications'));
350
			}else{
14445 anikendra 351
				$message = $this->request->data['User'];
352
				if($message['type'] == 'url' && !empty($message['url'])) {
353
					$url = $message['url'];
354
					$this->loadModel('Store');
355
					$store = $this->Store->getByUrl($url);					
356
				}				
14408 anikendra 357
				$this->loadModel('GcmUser');
358
				foreach ($this->request->data['userIds'] as $key => $value) {					
14509 anikendra 359
					$options = array('conditions'=>array('user_id'=>$value),'fields'=>array('gcm_regid'),'order'=>array('id'=>'desc'),'group'=>array('user_id'));
14408 anikendra 360
					$gcmUser = $this->GcmUser->find('first',$options);
361
					$regIds = array($gcmUser['GcmUser']['gcm_regid']);
14445 anikendra 362
					// $message = array('message'=>$this->request->data['User']['message']);					
363
					if($message['type'] == 'url' && !empty($message['url'])) {
364
						$message['url'] = $this->generateAffiliateUrl($url,$value,$store);
14428 anikendra 365
					}					
366
					$this->send_push_notification($regIds,$message,$value);
14408 anikendra 367
				}
368
			}
369
		}
370
	}
371
 
14428 anikendra 372
	private function send_push_notification($registatoin_ids, $message, $user_id) {
14409 anikendra 373
		$msg = array(
374
		    'message'       => $message['message'],
14428 anikendra 375
		    'title'         => $message['title'],
376
		    'type'      	=> $message['type'],
377
		    'url'		    => $message['url'],
14409 anikendra 378
		    'vibrate'       => 1,
379
		    'sound'         => 1,
380
		    'largeIcon'     => 'large_icon',
381
		    'smallIcon'     => 'small_icon'
382
		);
383
		// Set POST variables
384
		$url = 'https://android.googleapis.com/gcm/send';
14408 anikendra 385
 
14409 anikendra 386
		$fields = array(
387
		    'registration_ids' => $registatoin_ids,
388
		    'data' => $msg,
389
		);
390
		$headers = array(
391
		    'Authorization: key=' . Configure::read('googleapikey'),
392
		    'Content-Type: application/json'
393
		);
394
		//print_r($headers);
395
		// Open connection
396
		$ch = curl_init();
14408 anikendra 397
 
14409 anikendra 398
		// Set the url, number of POST vars, POST data
399
		curl_setopt($ch, CURLOPT_URL, $url);
400
		curl_setopt($ch, CURLOPT_POST, true);
401
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
402
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
14408 anikendra 403
 
14409 anikendra 404
		// Disabling SSL Certificate support temporarly
405
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
14408 anikendra 406
 
14409 anikendra 407
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
14408 anikendra 408
 
14409 anikendra 409
		// Execute post
410
		$result = curl_exec($ch);
411
		if ($result === FALSE) {
412
		    die('Curl failed: ' . curl_error($ch));
413
		}
14408 anikendra 414
 
14409 anikendra 415
		// Close connection
416
		curl_close($ch);
14428 anikendra 417
		$this->log("For $user_id ".print_r($result,1),'notifiactions');
14409 anikendra 418
	}
14408 anikendra 419
 
420
	public function admin_index() {		
13532 anikendra 421
		$this->User->recursive = 0;
14395 anikendra 422
		$options = array('limit'=>100,'order'=>array('id'=>'desc'));
423
		$this->Paginator->settings = $options;
424
		$users = $this->Paginator->paginate();
13532 anikendra 425
		$groups = $this->User->Group->find('list');
426
		$this->set(compact('groups','users'));
427
	}
428
 
429
/**
430
 * admin_view method
431
 *
432
 * @throws NotFoundException
433
 * @param string $id
434
 * @return void
435
 */
436
	public function admin_view($id = null) {
437
		$this->User->id = $id;
438
		if (!$this->User->exists()) {
439
			throw new NotFoundException(__('Invalid user'));
440
		}
441
		$this->set('user', $this->User->read(null, $id));
442
	}
443
 
444
/**
445
 * admin_add method
446
 *
447
 * @return void
448
 */
449
	public function admin_add() {
450
		if ($this->request->is('post')) {
451
			$this->User->create();
452
			if ($this->User->save($this->request->data)) {
453
				$this->Session->setFlash(__('The user has been saved'));
454
				$this->redirect(array('action' => 'index'));
455
			} else {
456
				$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
457
			}
458
		}
459
		$groups = $this->User->Group->find('list');
460
		$this->set(compact('groups'));
461
	}
462
 
463
/**
464
 * admin_edit method
465
 *
466
 * @throws NotFoundException
467
 * @param string $id
468
 * @return void
469
 */
470
	public function admin_edit($id = null) {
471
		$this->User->id = $id;
472
		if (!$this->User->exists()) {
473
			throw new NotFoundException(__('Invalid user'));
474
		}
475
		if ($this->request->is('post') || $this->request->is('put')) {
476
			if ($this->User->save($this->request->data)) {
477
				$this->Session->setFlash(__('The user has been saved'));
478
				$this->redirect(array('action' => 'index'));
479
			} else {
480
				$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
481
			}
482
		} else {
483
			$this->request->data = $this->User->read(null, $id);
484
		}
485
		$groups = $this->User->Group->find('list');
486
		$this->set(compact('groups'));
487
	}
488
 
489
/**
490
 * admin_delete method
491
 *
492
 * @throws MethodNotAllowedException
493
 * @throws NotFoundException
494
 * @param string $id
495
 * @return void
496
 */
497
	public function admin_delete($id = null) {
498
		if (!$this->request->is('post')) {
499
			throw new MethodNotAllowedException();
500
		}
501
		$this->User->id = $id;
502
		if (!$this->User->exists()) {
503
			throw new NotFoundException(__('Invalid user'));
504
		}
505
		if ($this->User->delete()) {
506
			$this->Session->setFlash(__('User deleted'));
507
			$this->redirect(array('action' => 'index'));
508
		}
509
		$this->Session->setFlash(__('User was not deleted'));
510
		$this->redirect(array('action' => 'index'));
511
	}
512
 
513
	public function dashboard() {
514
		App::uses('CakeTime', 'Utility');
515
		$user = $this->User->read(null,$this->Auth->user('id'));
516
		$this->set('user',$user);
517
		$this->set('title_for_layout', "Dashboard");
518
	}
519
 
520
/**
521
* user authentication funtions
522
*/
523
	public function register() {
524
		$referrer = $this->request->query('referrer');
525
		$this->log('referrer = '.$referrer);
526
		$this->Cookie->write('referrer',$referrer);
527
		$this->layout = 'auth';
528
		$this->set('title_for_layout','Register your free letushaggle.com account');
529
		$this->SignMeUp->register();
530
	}
531
 
532
	public function activate() {
13714 anikendra 533
		$this->layout = 'auth';
13532 anikendra 534
		$this->set('title_for_layout','Activate your copublish.in account');
13714 anikendra 535
		$this->SignMeUp->activate();
13532 anikendra 536
	}
537
 
538
	public function forgotten_password() {
13714 anikendra 539
		$this->layout = 'auth';
13532 anikendra 540
		$this->set('title_for_layout','Reset your copublish.in password');
13714 anikendra 541
		$this->SignMeUp->forgottenPassword();
13532 anikendra 542
	}	
543
 
544
	public function login() {
545
		$this->layout = 'auth';
546
		if (!empty($this->data['User']['next'])) {
547
		    $next = $this->data['User']['next'];
548
		    $this->Session->write('next', $next);
549
		} elseif (!empty($this->params['url']['next'])) {
550
		    $next = $this->params['url']['next'];
551
		    $this->Session->write('next', $next);
552
		}
553
		if ($this->Auth->login()) {
554
		    $next = $this->Session->read('next');
555
		    if (!empty($next)) {
556
				header('location:' . $next);
557
				exit();
558
		    }
13736 anikendra 559
		    $user = $this->User->read(null, $this->Auth->User('id'));		 
13532 anikendra 560
		    if ($user['User']['group_id'] == 2) {
561
				$this->redirect(array('controller' => 'administration', 'action' => 'dashboard'));
562
				exit();
563
		    }
564
			if ($user['User']['group_id'] == 1) {
13736 anikendra 565
				$this->redirect(array('controller' => 'deals', 'action' => 'mine?user_id='.$user['User']['id']));
13532 anikendra 566
				exit();
567
			}
568
		} else {
569
		    if (!empty($this->data)) {                
13736 anikendra 570
				$this->Session->setFlash(__('Invalid username or password'),'error_message');
13532 anikendra 571
		    }
572
		}
573
		$this->set('title_for_layout', "Login to letushaggle.com");
574
	}
575
 
576
	public function logout() {
577
		$this->Session->setFlash(__('You have been logged out now'),'success_message');
578
		$this->redirect($this->Auth->logout());
579
	}
580
 
581
	public function updatetimezone() {
582
		$this->layout = 'ajax';		
583
		$timezone = $_GET['tz'];
584
		Configure::load('constant');
585
		$timeZones = Configure::read("timeZones");
586
		$query = "UPDATE users SET user_timezone = $timezone WHERE id = ".$this->Auth->User('id');
587
		if($this->User->query($query)){
588
			$result = array('success' => true,'tz' => $timeZones[$timezone]);
589
		}else{
590
			$result = array('success' => false);
591
		}
592
		$this->set('result',$result);
593
	}
594
 
13736 anikendra 595
	public function verifymobile() {
596
		$this->layout = 'innerpages';
597
	}
13532 anikendra 598
 
13736 anikendra 599
	public function getdial2verifynumber() {
600
		$TelNumber=substr($this->request->data("phone_number"),-10);
601
 
602
	  // Replace with your Dial2Verify API Passkey generated using ( http://kb.dial2verify.in/?q=5 )
603
	    $API_KEY = Configure::read("dial2verifyapikey");
604
 
605
	  	//Get API Image Response
606
	    $url ="http://engine.dial2verify.in/Integ/API.dvf?mobile=$TelNumber&passkey=$API_KEY&notify=http://engine.dial2verify.in/Integ/CatchAll.dvf&e-notify=support@dial2verify.in&out=JSON&cn=IN";
607
	    // $json=file_get_contents($APIUrl);
608
	    $json = json_encode($this->make_request($url,null));
609
	  	$this->response->type('json');
610
		$this->layout = 'ajax';
611
	    echo($json);die;
612
	}
613
 
614
	public function getdial2verifystatus() { 
615
 
616
		$SID=$_REQUEST["SID"];
617
 
618
	    $json = array();
619
		$VerificationCall="http://engine.dial2verify.in/Integ/UserLayer/DataFeed_APIV2.dvf?SID=$SID";
620
 
621
	   // Make a call to Dial2Verify API & Parse The JSON Response
622
		// $RequestPayload=json_decode(file_get_contents($VerificationCall),true);
623
		$RequestPayload = $this->make_request($VerificationCall,null);
624
		// $RequestPayload = json_decode($response,true);
625
 
626
		$VerifStatus=$RequestPayload["VerificationStatus"];
627
 
628
		$json["VerificationStatus"]=$VerifStatus;
629
 
630
	   	$this->response->type('json');
631
		$this->layout = 'ajax';
632
	    echo(json_encode($json));die;
633
	}
634
 
635
	public function skipmobileverification() {
636
		$this->Session->write('skipmobileverification',1);
13739 anikendra 637
		$this->redirect(array('controller'=>'store_products','action'=>'mine',"?" => array( "user_id" => $this->Auth->User('id'))));
13736 anikendra 638
	}
639
 
640
	public function reauthenticate($userId) {
641
		$user = $this->User->read(null,$userId);
642
		$this->Auth->login($user['User']);
643
		$json = array('success'=>true);
644
		$this->response->type('json');
645
		$this->layout = 'ajax';
14150 anikendra 646
	    echo(json_encode($json));die;
13736 anikendra 647
	}
13739 anikendra 648
}