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