Subversion Repositories SmartDukaan

Rev

Rev 13633 | Rev 13673 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13633 Rev 13659
Line 65... Line 65...
65
			$this->layout = 'ajax';
65
			$this->layout = 'ajax';
66
			$conditions = array('social_id'=>$this->request->data['id'],'type'=>$this->request->data['type']);
66
			$conditions = array('social_id'=>$this->request->data['id'],'type'=>$this->request->data['type']);
67
			$socialProfile = $this->SocialProfile->find('first',array('conditions'=>$conditions));
67
			$socialProfile = $this->SocialProfile->find('first',array('conditions'=>$conditions));
68
			if(empty($socialProfile)){
68
			if(empty($socialProfile)){
69
				//Check if user with same email is registered and if so just add his profile
69
				//Check if user with same email is registered and if so just add his profile
-
 
70
				if(!empty($this->request->data['email'])) {
70
				$conditions = array('email'=>$this->request->data['email']);
71
					$conditions = array('email'=>$this->request->data['email']);
71
				$user = $this->SocialProfile->User->find('first',array('conditions'=>$conditions));
72
					$user = $this->SocialProfile->User->find('first',array('conditions'=>$conditions));
72
				if(!empty($user)) {
-
 
73
					$data['user_id'] = $user['User']['id'];	
-
 
74
				}else{
-
 
75
					//Create a new user and then insert user_id in social_profiles table
-
 
76
					$userData = array('email'=>$this->request->data['email'],'username'=>$this->request->data['email'],'first_name'=>$this->request->data['name'],'gender'=>$this->request->data['gender'],'mobile_number'=>$this->request->data['mobile_number'],'referrer'=>$this->request->data['referrer']);
73
 
77
					if($this->SocialProfile->User->save($userData)) {
74
					if(!empty($user)) {
78
						$data['user_id'] = $this->SocialProfile->User->getLastInsertId();
75
						$data['user_id'] = $user['User']['id'];	
79
					}else{
76
					}else{
-
 
77
						//Create a new user and then insert user_id in social_profiles table
-
 
78
						$userData = array('email'=>$this->request->data['email'],'username'=>$this->request->data['email'],'first_name'=>$this->request->data['name'],'gender'=>$this->request->data['gender'],'mobile_number'=>$this->request->data['mobile_number'],'referrer'=>$this->request->data['referrer']);
-
 
79
						if($this->SocialProfile->User->save($userData)) {
-
 
80
							$data['user_id'] = $this->SocialProfile->User->getLastInsertId();
-
 
81
						}else{
80
						$result = array('success' => false, 'message' => $this->SocialProfile->User->validationErrors);
82
							$result = array('success' => false, 'message' => $this->SocialProfile->User->validationErrors);
81
						break;
83
							break;
-
 
84
						}
-
 
85
					}
-
 
86
					$this->SocialProfile->create();
-
 
87
					if ($this->SocialProfile->save($data)) {
-
 
88
						$result = array('success' => true, 'message' => 'Social Profile Created','id' => $data['user_id']);
-
 
89
					} else {
-
 
90
						$result = array('success' => false, 'message' => 'Social Profile Could Not Be Created','id' => -1);
82
					}
91
					}
83
				}
-
 
84
				$this->SocialProfile->create();
-
 
85
				if ($this->SocialProfile->save($data)) {
-
 
86
					$result = array('success' => true, 'message' => 'Social Profile Created','id' => $data['user_id']);
-
 
87
				} else {
92
				} else {
88
					$result = array('success' => false, 'message' => 'Social Profile Could Not Be Created','id' => -1);
93
					$result = array('success' => false, 'message' => "Email is missing");
-
 
94
					break;
89
				}
95
				}				
90
			} else {
96
			} else {
91
				$result = array('success' => true, 'message' => 'Existing Social Profile','id' => $socialProfile['SocialProfile']['user_id']);
97
				$result = array('success' => true, 'message' => 'Existing Social Profile','id' => $socialProfile['SocialProfile']['user_id']);
92
			}
98
			}
93
		}
99
		}
94
		$this->set(array(
100
		$this->set(array(