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