public function login(Request $request)
 {
     //        dd(\Crypt::encrypt('*****@*****.**'));
     try {
         $email = \Crypt::decrypt($request->get('token'));
     } catch (\Exception $e) {
         return abort('403', 'Forbidden');
     }
     $user = User::whereEmail($email)->first();
     if (!$user) {
         return abort('403', 'Forbidden');
     }
     if (!$user->account) {
         $b2bCompany = \DB::connection('mysql-b2b')->table('companies')->where('user_id', '=', $user->id)->first();
         //            $b2bCompany = false;
         $accountName = $b2bCompany ? $b2bCompany->company_name : $user->email;
         $account = new Account();
         $account->ip = $request->getClientIp();
         $account->name = $accountName;
         $account->account_key = str_random(RANDOM_KEY_LENGTH);
         $account->save();
         $user->account_id = $account->id;
         $user->registered = true;
         $user->save();
         $exists = \DB::connection('mysql')->table('users')->whereId($user->id)->count();
         if (!$exists) {
             \DB::connection('mysql')->table('users')->insert(['id' => $user->id, 'account_id' => $user->account_id, 'created_at' => $user->created_at, 'updated_at' => $user->updated_at, 'deleted_at' => $user->deleted_at, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'phone' => $user->phone, 'username' => $user->username, 'email' => $user->email, 'password' => $user->password, 'confirmation_code' => $user->confirmation_code, 'registered' => $user->registered, 'confirmed' => $user->confirmed, 'notify_sent' => $user->notify_sent, 'notify_viewed' => $user->notify_viewed, 'notify_paid' => $user->notify_paid, 'public_id' => $user->public_id, 'force_pdfjs' => false, 'remember_token' => $user->remember_token, 'news_feed_id' => $user->news_feed_id, 'notify_approved' => $user->notify_approved, 'failed_logins' => $user->failed_logins, 'dark_mode' => $user->dark_mode, 'referral_code' => $user->referral_code]);
         }
     }
     \Auth::loginUsingId($user->id);
     return redirect('/');
 }
 public function handleFacebookCallback()
 {
     $facebookUser = Socialize::with('facebook')->user();
     $user = User::where('email', '=', $facebookUser->getEmail())->get();
     if ($user->count() > 0) {
         \Auth::loginUsingId($user[0]->id);
         return redirect()->intended();
     }
     return redirect('auth/login')->withErrors("User not found");
 }
 public function postLogin()
 {
     $username = \Request::get('username');
     $username_kemenkeu = "kemenkeu\\" . $username;
     $password = \Request::get('password');
     $ldapconn = ldap_connect('kemenkeu.go.id') or die('can not connect');
     if ($ldapconn) {
         $ldapbind = ldap_bind($ldapconn, $username_kemenkeu, $password) or die(' wrong credential');
         if ($ldapbind) {
             $user = \App\User::where('kemenkeu', $username)->first();
             \Auth::loginUsingId($user->id);
             return \Redirect::to('/');
         }
     }
 }
Beispiel #4
0
 /**
  * Obtain the user information from Google.
  *
  * @return Response
  */
 public function handleProviderCallbackGoogle()
 {
     $user = Socialite::driver('google')->user();
     $userDB = \DB::table('users')->where('email', $user->email)->first();
     if ($userDB != null && $user->email == $userDB->email) {
         \Auth::loginUsingId($userDB->id);
         return redirect("checkout");
     }
     $usuario = new User();
     $usuario->name = $user->name;
     $usuario->email = $user->email;
     $usuario->avatar = $user->avatar;
     $usuario->password = bcrypt($user->id);
     $usuario->save();
     \Auth::loginUsingId($usuario->id);
     return redirect("checkout");
     // $user->token;
 }
 public function loginDoneGoogle()
 {
     $code = Input::get('code');
     $googleService = OAuth::consumer('Google', 'http://www.obscuraconflu.com/google');
     $token = $googleService->requestAccessToken($code);
     // Send a request with it
     $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
     //Var_dump
     //display whole array().
     $userId = Users::getUserId($result['id']);
     if ($userId) {
         Auth::loginUsingId($userId);
         $firstname = Users::getFirstName($userId);
         Session::put('first_name', $firstname);
         $data = "Welcome ";
         return Redirect::to('/dashboard')->with('message', $data . " " . $firstname);
     } else {
         $newUserData['first_name'] = $result['given_name'];
         $newUserData['last_name'] = $result['family_name'];
         $newUserData['email'] = $result['email'];
         $newUserData['uid'] = $result['id'];
         $newUserData['signup_type'] = 3;
         //$newUserData['profile_image'] = "https://graph.facebook.com/"+$result['id']+"/picture?width=250&height=250";
         Session::put('fb', $newUserData);
         return View::make('fbgoogle')->with('newUserData', $newUserData);
     }
 }
Beispiel #6
0
 public function oauth2callback(Request $request)
 {
     $data = $request->all();
     if (isset($data['code'])) {
         /**/
         //\Session::put('_CodeGoogle',$data);
         //$this->client->addScope(array(\Google_Service_Oauth2::USERINFO_EMAIL,\Google_Service_Oauth2::USERINFO_PROFILE ));
         $rst = $this->client->authenticate($_GET['code']);
         $this->client->getAccessToken();
         \Session::put('_TokenGoogle', $rst);
         $service = new \Google_Service_Oauth2($this->client);
         \Session::put('_Auth2Google', $service);
         \Session::put('_ClientGoogle', $this->client);
         \Session::save();
         //dd($service->userinfo->get());
         //dd(\Session::all());
         //$serviceGoogle = \Session::get('_Auth2Google');
         $infoUser = $service->userinfo->get();
         //dd($infoUser->getEmail());
         $user = \App\User::where('email', $infoUser->getEmail())->get();
         //$user = \App\User::where('email','*****@*****.**')->get();
         if (count($user) > 0) {
             if ($user[0]->active) {
                 $userAuth = \Auth::loginUsingId($user[0]->id);
                 \Auth::login($userAuth);
                 return redirect('/admin/dashboard');
             } else {
                 $ClientG = \Session::get('_ClientGoogle');
                 $ClientG->revokeToken();
                 \Session::forget('_ClientGoogle');
                 \Session::forget('_Auth2Google');
                 \Session::forget('_CodeGoogle');
                 \Session::forget('_TokenGoogle');
                 return view('Errors.500');
             }
         } else {
             $ClientG = \Session::get('_ClientGoogle');
             $ClientG->revokeToken();
             \Session::forget('_ClientGoogle');
             \Session::forget('_Auth2Google');
             \Session::forget('_CodeGoogle');
             \Session::forget('_TokenGoogle');
             return view('Errors.500');
         }
     } elseif (isset($data['error'])) {
         return redirect('/auth/login');
     }
     /*
     $client = new Google_Client();
     $client->setClientId(MYCLIENTID);
     $client->setClientSecret(MYSECRET);
     $client->setRedirectUri(SOMEURLINMYSYSTEM);
     $service = new Google_Service_Oauth2($client);
     $client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
     $client->authenticate($_GET['code']);//I have the right code, and I am being authenticated
     
     $client->authenticate($code);
     $plus = new Google_Service_Plus($client);
     $person = $plus->people->get('me');
     var_dump($person);
     */
 }