Ejemplo n.º 1
0
 public static function login($input)
 {
     $validation = Validator::make($input, Users::$loginRules);
     if ($validation->fails()) {
         return Response::json(array('status' => '0', 'msg' => $validation->getMessageBag()->first()), 200);
     } else {
         $email = $input['email'];
         $password = $input['password'];
         $lat = isset($input['lat']) ? $input['lat'] : '0';
         $lng = isset($input['lng']) ? $input['lng'] : '0';
         $device_token = isset($input['device_token']) ? $input['device_token'] : '';
         $reg_id = isset($input['reg_id']) ? $input['reg_id'] : '';
         $current_time = new DateTime();
         $user_check = DB::table('users')->select('id', 'email', 'password')->where('email', $email)->first();
         if (isset($user_check)) {
             if (Hash::check($password, $user_check->password)) {
                 // Updating the user Token
                 $token = Users::updateUserToken($user_check->id);
                 if ($token) {
                     $all_skillset = Users::Getskillset();
                     if ($reg_id || $device_token) {
                         Users::setDeviceToken($user_check->id, $reg_id, $device_token);
                     }
                     if ($lat && $lng && $lat != 0.0 && $lng != 0.0) {
                         Users::updateLatLng($user_check->id, $lat, $lng);
                         // $place=Users::getLocation($lat,$lng);
                         $place = self::Get_Address_From_Google_Maps($lat, $lng);
                         Users::updateLocation($user_check->id, $place);
                     }
                     //$user_details = User::find($user_check->id);
                     /* $user_details=DB::table('users')
                          			  ->selectRaw('users.*,COALESCE(masters,"") as masters,COALESCE(college,"") as college,COALESCE(company_name,"") as company,COALESCE(designation,"") as designation')
                          			  /*->leftJoin('user_qualification', function($join)
                        {
                            $join->on('user_qualification.user_id', '=', 'user.id');
                            //$join->on('user_qualification.active', '=', 1);
                        })*/
                     /* ->leftJoin('user_qualification','users.id','=','user_qualification.user_id')
                     		            			  ->leftJoin('company','users.id','=','company.user_id')
                     								  ->selectRaw('*')
                     		            			  ->Where('users.id','=',$user_check->id)
                     		            			  ->get();	
                     
                     		            		if($user_details[0]->profile_pic)
                                                 $user_details[0]->profile_pic = Users::getFormattedImage($user_details[0]->profile_pic);
                                             	else
                                             	$user_details[0]->image='';	
                                               */
                     $user_details = Users::LoginTypeResponse($user_check->id);
                     $profile_setup_status = Users::ProfileSetupStatus($user_check->id);
                     return Response::json(array('status' => '1', 'msg' => 'Login Success', 'all_skillset' => $all_skillset, 'user_details' => $user_details, 'profile_complete_status' => $profile_setup_status), 200);
                 } else {
                     return Response::json(array('status' => '0', 'msg' => 'User not found in database!'), 200);
                 }
             } else {
                 return Response::json(array('status' => '0', 'msg' => 'Password Incorrect!'), 200);
             }
         } else {
             return Response::json(array('status' => '0', 'msg' => 'Email and Password do not match'), 200);
         }
     }
 }