Пример #1
0
 public function RegisterWithGoogle()
 {
     $code = Input::get('code');
     $googleService = OAuth::consumer('Google');
     if (!empty($code)) {
         $token = $googleService->requestAccessToken($code);
         $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
         $user = User::firstOrCreate(array('email' => $result['email']));
         if ($user != null) {
             $user->nombre = $result['name'];
             $user->avatar = $result['picture'];
             $user->save();
             Auth::login($user, false);
             Session::flash('message', "<img src='" . $user->avatar . "' height='70' alt=''> Registrado  con Facebook <br> Bienvenido " . $result['name']);
             if (Auth::user()->residencia_id == null) {
                 return Redirect::to("register/completar-registro");
             } else {
                 return Redirect::to("/");
             }
         } else {
             Session::flash('message', "Error al Crear usuario");
             return Redirect::to("/");
         }
     } else {
         $url = $googleService->getAuthorizationUri();
         return Redirect::to((string) $url);
     }
 }
Пример #2
0
 public function loginWithGoogle(Request $request)
 {
     // get data from request
     $code = $request->get('code');
     // get google service
     $googleService = \OAuth::consumer('Google');
     // check if code is valid
     // if code is provided get user data and sign in
     if (!is_null($code)) {
         // This was a callback request from google, get the token
         $token = $googleService->requestAccessToken($code);
         // Send a request with it
         $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
         $message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
         echo $message . "<br/>";
         //Var_dump
         //display whole array.
         dd($result);
     } else {
         // get googleService authorization
         $url = $googleService->getAuthorizationUri();
         // return to google login url
         return redirect((string) $url);
     }
 }
Пример #3
0
 public function twitterAuth($token = NULL, $verify = NULL)
 {
     // get twitter service
     $tw = OAuth::consumer('Twitter');
     // check if code is valid
     // if code is provided get user data and sign in
     if (!empty($token) && !empty($verify)) {
         // This was a callback request from twitter, get the token
         $token = $tw->requestAccessToken($token, $verify);
         // Send a request with it
         $result = json_decode($tw->request('account/verify_credentials.json'));
         try {
             $user = User::where('twitter_id', '=', $result->id)->firstOrFail();
         } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             //if user is not yet registered we have to store existing twitter id and ask for more details
             Session::put('twitterAccount', $result);
             throw new UserNotRegisteredException();
         }
         // login the user
         Sentry::login($user);
         return $user;
     } else {
         // get request token
         $reqToken = $tw->requestRequestToken();
         // get Authorization Uri sending the request token
         $url = $tw->getAuthorizationUri(array('oauth_token' => $reqToken->getRequestToken()));
         // return to twitter login url
         return (string) $url;
     }
 }
Пример #4
0
 public function loginWithFacebook()
 {
     // get data from input
     $code = Input::get('code');
     // get fb service
     $fb = OAuth::consumer('Facebook');
     // check if code is valid
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from facebook, get the token
         $token = $fb->requestAccessToken($code);
         // Send a request with it
         $result = json_decode($fb->request('/me'), true);
         $message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
         echo $message . "<br/>";
         //Var_dump
         //display whole array().
         dd($result);
     } else {
         // get fb authorization
         $url = $fb->getAuthorizationUri();
         // return to facebook login url
         return Redirect::to((string) $url);
     }
 }
Пример #5
0
 public function getLogin()
 {
     if (Input::has('code')) {
         return App::make('Lio\\Github\\GithubAuthenticator')->authByCode($this, Input::get('code'));
     }
     // redirect to the github authentication url
     return $this->redirectTo((string) OAuth::consumer('GitHub')->getAuthorizationUri());
 }
Пример #6
0
 /**
  * Authenticate with github
  */
 public function login()
 {
     // Redirect from Github
     if (Input::has('code')) {
         return App::make('Phphub\\Github\\GithubAuthenticator')->authByCode($this, Input::get('code'));
     }
     // redirect to the github authentication url
     return Redirect::to((string) OAuth::consumer('GitHub')->getAuthorizationUri());
 }
Пример #7
0
 public function login()
 {
     $fb = OAuth::consumer('Facebook');
     $code = Input::get('code');
     if (!empty($code)) {
         $FBToken = $fb->requestAccessToken($code)->getAccessToken();
         $_SESSION['FBToken'] = $FBToken;
         return Redirect::to('/');
     } else {
         $url = $fb->getAuthorizationUri();
         return Response::make()->header('Location', (string) $url);
     }
 }
Пример #8
0
 public function facebookpages()
 {
     $code = Input::get('code');
     $fb = OAuth::consumer('Facebook');
     if (!empty($code)) {
         $token = $fb->requestAccessToken($code);
         $a = $token->getAccessToken();
         $result = json_decode($fb->request('/me/accounts'), true);
         $pid = $this->savePages($result);
         return Redirect::to('/pages')->withCookie(Cookie::make('pid', $pid, 10));
     } else {
         $url = $fb->getAuthorizationUri();
         return Redirect::to((string) $url);
     }
 }
Пример #9
0
 private function _getUser()
 {
     $fb = OAuth::consumer('Facebook');
     if (Cookie::get('uid')) {
         $accessToken = $this->_getAccessTokenByUser(Cookie::get('uid'));
         if ($accessToken) {
             $token = new OAuth\OAuth2\Token\StdOAuth2Token();
             $token->setAccessToken($accessToken);
             $token->setEndOfLife(time());
             $fb->getStorage()->storeAccessToken('Facebook', $token);
             $user = json_decode($fb->request('/me'), true);
             $user['access_token'] = $accessToken;
             return $user;
         }
     }
     return false;
 }
Пример #10
0
 public function getVklogin()
 {
     $code = Input::get('code');
     //OAuth::setHttpClient('CurlClient');
     $vk = OAuth::consumer('Vkontakte', 'http://localhost/study_barter/public/users/vklogin');
     //var_dump($code);
     if (!empty($code)) {
         $token = $vk->requestAccessToken($code);
         $result = json_decode($vk->request('users.get?lang=ru&fields=photo_100,photo_200'), true);
         $result = $result['response'][0];
         //echo "<pre>";
         //var_dump($result);
         //echo "</pre>";
         //die();
         if ($user = User::where('vk_id', '=', $result['uid'])->first()) {
             //die(var_dump($result));
             $member = Member::where('user_id', '=', $user->id)->first();
             $member->name = $result['first_name'];
             $member->surname = $result['last_name'];
             $member->avatar_url = $result['photo_100'];
             $member->avatar_url_big = $result['photo_200'];
             $member->save();
             Auth::login($user);
             return Redirect::to('/');
         } else {
             $user = new User();
             $user->vk_id = $result['uid'];
             $user->is_active = 1;
             $user->save();
             $member = new Member();
             $member->user_id = $user->id;
             $member->name = $result['first_name'];
             $member->surname = $result['last_name'];
             $member->avatar_url = $result['photo_100'];
             $member->avatar_url_big = $result['photo_200'];
             $member->save();
             Auth::login($user);
             Log::info("User [{$result['first_name']}] successfully logged in.");
             return Redirect::to('/');
         }
     } else {
         $url = $vk->getAuthorizationUri();
         return Redirect::to((string) $url);
     }
 }
Пример #11
0
 public function _remap($method, $args)
 {
     if ($method == 'linked') {
         $this->linked();
         return;
     }
     // Invalid method or no provider = BOOM
     if (!in_array($method, array('session', 'callback')) or empty($args)) {
         show_404();
     }
     // Get the provider (facebook, twitter, etc)
     list($provider) = $args;
     // This provider is not supported by the module
     if (!isset($this->providers[$provider])) {
         show_404();
     }
     // Look to see if we have this provider in the db?
     if (!($credentials = $this->credential_m->get_active_provider($provider))) {
         $this->ion_auth->is_admin() ? show_error('Social Integration: ' . $provider . ' is not supported, or not enabled.') : show_404();
     }
     // oauth or oauth 2?
     $strategy = $this->providers[$provider];
     switch ($strategy) {
         case 'oauth':
             include $this->module_details['path'] . '/oauth/libraries/OAuth.php';
             $oauth = new OAuth();
             // Create an consumer from the config
             $consumer = $oauth->consumer(array('key' => $credentials->client_key, 'secret' => $credentials->client_secret));
             // Load the provider
             $provider = $oauth->provider($provider);
             break;
         case 'oauth2':
             include $this->module_details['path'] . '/oauth2/libraries/OAuth2.php';
             $oauth2 = new OAuth2();
             // OAuth2 is the honey badger when it comes to consumers - it just dont give a shit
             $consumer = null;
             $provider = $oauth2->provider($provider, array('id' => $credentials->client_key, 'secret' => $credentials->client_secret, 'scope' => $credentials->scope));
             break;
         default:
             exit('Something went properly wrong!');
     }
     // Call session or callback, with lots of handy details
     call_user_func(array($this, '_' . $method), $strategy, $provider, $consumer);
 }
Пример #12
0
 public function loginGithub()
 {
     $code = Input::get('code');
     $email = Input::get('email');
     $github = OAuth::consumer('GitHub');
     if (!empty($email)) {
         $user = User::where('email', '=', $email)->first();
         if (isset($user)) {
             Session::flash('warning', trans('user.register.social.already-exists'));
             return Redirect::route('user.register');
         }
         $user = Sentry::createUser(array('email' => $email, 'password' => md5(time() . uniqid()), 'activated' => true));
         UserGitHub::create(array('user_id' => $user->id, 'access_token' => Input::get('access_token'), 'refresh_token' => !empty(Input::get('refresh_token')) ? Input::get('refresh_token') : null, 'end_of_life' => !empty(Input::get('end_of_life')) ? Input::get('end_of_life') : null));
         $user = Sentry::findUserByLogin($user->email);
         Sentry::login($user, false);
         Session::flash('success', trans('user.register.social.success'));
         return Redirect::route('home');
     } elseif (empty($code)) {
         $url = $github->getAuthorizationUri(array('state' => md5(time() . uniqid()), 'redirect_uri' => URL::route('user.login.github')));
         return Response::make()->header('Location', (string) $url);
     } else {
         $token = $github->requestAccessToken($code);
         $emails = json_decode($github->request('/user/emails'), true);
         if (!is_array($emails) || count($emails) === 0) {
             Session::flash('error', trans('user.register.social.no-emails'));
             return Redirect::route('user.register');
         }
         if (count($emails) <= 1) {
             $user = User::where('email', '=', $emails[0])->first();
             if (isset($user)) {
                 Session::flash('warning', trans('user.register.social.already-exists'));
                 return Redirect::route('user.register');
             }
             $user = Sentry::createUser(array('email' => $emails[0], 'password' => md5(time() . uniqid()), 'activated' => true));
             UserGitHub::create(array('user_id' => $user->id, 'access_token' => $token->getAccessToken(), 'refresh_token' => !empty($token->getRefreshToken()) ? $token->getRefreshToken() : null, 'end_of_life' => !empty($token->getEndOfLife()) ? $token->getEndOfLife() : null));
             Sentry::login($user, false);
             Session::flash('success', trans('user.register.social.success'));
             return Redirect::route('home');
         }
         return View::make('user.social', array('emails' => $emails, 'token' => $token));
     }
 }
Пример #13
0
 /**
  * Login user with facebook
  *
  * @return void
  */
 public function loginWithFacebook()
 {
     // get data from input
     $code = Input::get('code');
     // get fb service
     $fb = OAuth::consumer('Facebook');
     // check if code is valid
     //$user = $this->userRepository->findByFacebookId($code);
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from facebook, get the token
         $token = $fb->requestAccessToken($code);
         // Send a request with it
         $result = json_decode($fb->request('/me?fields=id,first_name,last_name,name,email'), true);
         $user = $this->userRepository->findByFacebookId($result['id']);
         if (!$user) {
             $user = $this->userRepository->findByEmail($result['email']);
             if ($user) {
                 $user->facebook_id = $result['id'];
                 $user->save();
             } else {
                 $user = $this->userRepository->newUser();
                 $user->first_name = $result['first_name'];
                 $user->last_name = $result['last_name'];
                 $user->email = $result['email'];
                 $user->facebook_id = $result['id'];
                 $user->role_id = 3;
                 $user->enabled = 1;
                 $user->user_created_id = 1;
                 $user->save();
             }
         }
         Auth::login($user, true);
         return Redirect::route('app.index')->with(['successMessage' => 'Bienvenido ' . Auth::user()->first_name . ' ' . Auth::user()->last_name . '!', 'showSideBar' => true, 'showProfile' => true]);
     } else {
         // get fb authorization
         $url = $fb->getAuthorizationUri();
         // return to facebook login url
         return Redirect::to((string) $url);
     }
 }
Пример #14
0
 public function facebookLogin()
 {
     // get data from input
     $code = \Input::get('code');
     $redirect = $this->currentURL(\Input::get('url-back'));
     // get fb service
     $fb = \OAuth::consumer('Facebook');
     // check if code is valid
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from facebook, get the token
         $token = $fb->requestAccessToken($code);
         // Send a request with it
         $result = json_decode($fb->request('/me'), true);
         try {
             $user = \Sentry::findUserByLogin($result['email']);
             if ($user) {
                 // Log the user in
                 \Sentry::login($user, false);
                 return \Redirect::to($redirect);
             } else {
                 $register = \Sentry::createUser(array('first_name' => $result['first_name'], 'last_name' => $result['last_name'], 'username' => $result['username'], 'provider' => 'facebook', 'email' => $result['email'], 'password' => $result['email'], 'activated' => true));
                 if ($register) {
                     $login = \Sentry::findUserById($register->id);
                     // Log the user in
                     \Sentry::login($login, false);
                     return \Redirect::to($redirect);
                 } else {
                     return \Redirect::to($redirect)->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
                 }
             }
         } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) {
             echo 'Wrong password, try again.';
         }
     } else {
         // get fb authorization
         $url = $fb->getAuthorizationUri();
         // return to facebook login url
         return \Redirect::to((string) $url);
     }
 }
Пример #15
0
 public function loginOAuth()
 {
     $code = Input::get("code");
     $google = OAuth::consumer("Google");
     if (!empty($code)) {
         $token = $google->requestAccessToken($code);
         $userdata = json_decode($google->request("https://www.googleapis.com/oauth2/v1/userinfo"), true);
         $user = User::firstOrNew(array("google_id" => $userdata['id']));
         $user->name = $userdata['name'];
         $user->email = $userdata['email'];
         $user->refresh_token = $code;
         //$user->access_token = $;
         //dd($token);
         //if ($user->name == "Marcin Gordziejewski")
         //    $user->topaccess = 1;
         $user->save();
         Auth::loginUsingId($user->id);
         return Redirect::route("Home");
     } else {
         $url = $google->getAuthorizationUri();
         return Redirect::to((string) $url);
     }
 }
Пример #16
0
 public function getFacebook($m_id)
 {
     // get data from input
     $code = Input::get('code');
     // get fb service
     $fb = OAuth::consumer('Facebook');
     // check if code is valid
     $data = Missing::find($m_id);
     $message = "A Kid Having a \n Name " . $data->name . " \n Age : '.{$data->age}.'\n State : " . $data->state . " \n City : " . $data->city . " \n Is Missing. Please Report On Our Website http://example.com. If You Got Any Information About It";
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from facebook, get the token
         $token = $fb->requestAccessToken($code);
         // Send a request with it
         $result = json_decode($fb->request('/me'), true);
         $postMessage = json_decode($fb->request("/me/feed?access_token", 'POST', array('message' => $message)), true);
         return Redirect::to('organization/report/show-missing?success=true');
     } else {
         // get fb authorization
         $url = $fb->getAuthorizationUri();
         // return to facebook login url
         return Redirect::to((string) $url);
     }
 }
Пример #17
0
 /**
  * Login with google
  * @return \Illuminate\Http\RedirectResponse
  */
 public function loginWithGoogle()
 {
     // get data from input
     $code = Input::get('code');
     // get google service
     $googleService = OAuth::consumer('Google');
     // check if code is valid
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from google, get the token
         $token = $googleService->requestAccessToken($code);
         // Send a request with it
         $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
         //Login with user
         $username = sprintf("%s@%s", $result['id'], 'google');
         $user = User::whereUsername($username)->first();
         if ($user) {
             $user->last_seen = time();
             $user->os = 3;
         } else {
             // Create the user.
             $user = new User();
             $user->full_name = $result['name'];
             $user->email = $result['email'];
             $user->password = '******';
             $user->os = 3;
             $user->api_key = md5(uniqid(mt_rand(), true));
             $user->image = $result['picture'];
             $user->cover_image = "https://lh6.googleusercontent.com/-3WJKEy6n7OQ/U09V1Pwz0rI/AAAAAAAAAls/EBoDipK8as4/w909-h455-no/5.jpg";
             $user->last_seen = time();
             $user->username = $username;
         }
         $user->save();
         Auth::login($user);
         return Redirect::home();
     } else {
         // get googleService authorization
         $url = $googleService->getAuthorizationUri();
         // return to google login url
         return Redirect::to((string) $url);
     }
 }
Пример #18
0
 /**
  * getFacebookLogin.
  *
  *	Handles OAuth communication with Facebook for signup / login
  *		Calls $this->oauthLogin() if the oauth code is passed via Input
  *		Otherwise calls $linkedinService->getAuthorizationUri()
  *
  *	@param void
  *
  *	@return Illuminate\Http\RedirectResponse || $this->oauthLogin($user_info)
  *
  *	@todo clean up this doc block
  */
 public function getLinkedinLogin()
 {
     // get data from input
     $code = Input::get('code');
     $linkedinService = OAuth::consumer('Linkedin');
     if (!empty($code)) {
         // retrieve the CSRF state parameter
         $state = isset($_GET['state']) ? $_GET['state'] : null;
         // This was a callback request from linkedin, get the token
         $token = $linkedinService->requestAccessToken($_GET['code'], $state);
         // Send a request with it. Please note that XML is the default format.
         $result = json_decode($linkedinService->request('/people/~:(id,first-name,last-name,email-address)?format=json'), true);
         // Remap the $result to something that matches our schema.
         $user_info = array('fname' => $result['firstName'], 'lname' => $result['lastName'], 'email' => $result['emailAddress'], 'oauth_vendor' => 'linkedin', 'oauth_id' => $result['id']);
         return $this->oauthLogin($user_info);
     } else {
         // get linkedinService authorization
         $url = $linkedinService->getAuthorizationUri();
         $res = ['authUrl' => urldecode($url)];
         // return to linkedin login url
         return Response::json($res);
     }
 }
Пример #19
0
 /**
  * Handle the Github log in/sign up.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function github()
 {
     // get data from input
     $code = Input::get('code');
     // get gh service
     $gh = OAuth::consumer('GitHub');
     // check if code is valid
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from facebook, get the token
         $gh->requestAccessToken($code);
         $result = json_decode($gh->request('user'), true);
         $user = $this->users->findByGithubID($result['id']);
         if (!$user) {
             $user = $this->users->createWithGithub($result);
         }
         Auth::login($user);
         return Redirect::route('contacts.index');
     } else {
         // get fb authorization
         $url = $gh->getAuthorizationUri();
         // return to facebook login url
         return Redirect::to((string) $url);
     }
 }
 public function loginWithGithub()
 {
     $code = Input::get('code');
     $githubService = OAuth::consumer('Github');
     if (!empty($code)) {
         try {
             $token = $githubService->requestAccessToken($code);
             $result = json_decode($githubService->request('user'), true);
         } catch (Exception $e) {
             die("Too many requests, access denied by Github. Please wait a while.");
         }
         $profile = Profile::where('uid', '=', $result['id'])->first();
         if (empty($profile)) {
             $user = new User();
             $user->name = $result['name'];
             $user->email = $result['email'];
             $user->photo = $result['avatar_url'];
             $user->save();
             $profile = new Profile();
             $profile->uid = $result['id'];
             // $profile->access_token = $fb->requestAccessToken( $code );
             $profile->username = $result['login'];
             $profile->gender = $result['bio'];
             $profile = $user->profiles()->save($profile);
         }
         $profile->save();
         $user = $profile->user;
         Auth::login($user);
         return Redirect::to('/')->with('message', 'Logged in with Facebook');
     } else {
         // get githubService authorization
         $url = $githubService->getAuthorizationUri();
         return Redirect::to((string) $url);
     }
 }
Пример #21
0
 public function loginWithLinkedin()
 {
     // get data from input
     $code = Input::get('code');
     $linkedinService = OAuth::consumer('Linkedin', url('auth/linkedin'));
     if (!empty($code)) {
         // This was a callback request from linkedin, get the token
         $token = $linkedinService->requestAccessToken($code);
         // Send a request with it. Please note that XML is the default format.
         $result = json_decode($linkedinService->request('/people/~?format=json'), true);
         // Show some of the resultant data
         echo 'Your linkedin first name is ' . $result['firstName'] . ' and your last name is ' . $result['lastName'];
         //Var_dump
         //display whole array().
         dd($result);
     } else {
         // get linkedinService authorization
         $url = $linkedinService->getAuthorizationUri(array('state' => 'DCEEFWF45453sdffef424'));
         // return to linkedin login url
         return Redirect::to((string) $url);
     }
 }
Пример #22
0
 public function loginWithGoogle()
 {
     // get data from input
     $code = Input::get('code');
     // get google service
     $googleService = OAuth::consumer('Google');
     // check if code is valid
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from google, get the token
         $token = $googleService->requestAccessToken($code);
         // Send a request with it
         $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
         $message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
         echo $message . "<br/>";
         //Var_dump
         //display whole array().
         dd($result);
     } else {
         // get googleService authorization
         $url = $googleService->getAuthorizationUri();
         // return to facebook login url
         return Redirect::to(htmlspecialchars_decode($url));
         // return Response::make()->header( 'Location: ', (string)$url );
     }
 }
Пример #23
0
 public function google()
 {
     $settings = Setting::first();
     if ($settings->user_registration) {
         // get data from input
         $code = Input::get('code');
         // get google service
         $googleService = OAuth::consumer('Google');
         // check if code is valid
         // if code is provided get user data and login
         if (!empty($code)) {
             // This was a callback request from google, get the token
             $token = $googleService->requestAccessToken($code);
             // Send a request with it
             $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
             // $message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
             // dd($result);
             $oauth_userid = $result['id'];
             $oauth_username = Helper::slugify($result['name']);
             $oauth_email = $result['email'];
             if (!isset($result['picture'])) {
                 $oauth_picture = NULL;
             } else {
                 $oauth_picture = $result['picture'];
             }
             if (isset($oauth_userid) && isset($oauth_username) && isset($oauth_email)) {
                 $google_auth = OauthGoogle::where('oauth_userid', '=', $oauth_userid)->first();
                 if (isset($google_auth->id)) {
                     $user = User::find($google_auth->user_id);
                 } else {
                     // Execute Add or Login Oauth User
                     $user = User::where('email', '=', $oauth_email)->first();
                     if (!isset($user->id)) {
                         $username = $this->create_username_if_exists($oauth_username);
                         $email = $oauth_email;
                         $password = Hash::make($this->rand_string(15));
                         $avatar = $oauth_picture != NULL ? ImageHandler::uploadImage($oauth_picture, 'avatars', $username, 'url') : NULL;
                         $user = $this->new_user($username, $email, $password, $avatar);
                         $this->new_user_points($user->id);
                         $new_oauth_user = new OauthGoogle();
                         $new_oauth_user->user_id = $user->id;
                         $new_oauth_user->oauth_userid = $oauth_userid;
                         $new_oauth_user->save();
                     } else {
                         // Redirect and send error message that email already exists. Let them know that they can request to reset password if they do not remember
                         return Redirect::to('/')->with('error', Lang::get('lang.oauth_email_used'));
                     }
                 }
                 // Redirect to new User Login;
                 Auth::login($user);
                 $this->add_user_login_point();
                 return Redirect::to('/')->with('success', Lang::get('lang.google_success'));
             } else {
                 // Something went wrong, redirect and send error msg
                 echo Lang::get('lang.oauth_error');
                 echo '<br />Info retrieved:<br />';
                 echo '<br />userid: ' . $oauth_userid;
                 echo '<br />username: '******'<br />email: ' . $oauth_email;
                 echo '<br />picture: ' . $oauth_picture;
             }
         } else {
             // get googleService authorization
             $url = $googleService->getAuthorizationUri();
             // return to facebook login url
             return Response::make()->header('Location', (string) $url);
         }
     } else {
         return Redirect::to('/')->with(array('note' => Lang::get('lang.signup_reg_closed'), 'note_type' => 'error'));
     }
 }
Пример #24
0
<div class="container">

    <?php 
if (Session::has('notification')) {
    ?>
        <span class="notification"><?php 
    echo Session::get('notification');
    ?>
</span>
    <?php 
}
?>

    <?php 
$googleService = OAuth::consumer('Google');
?>
     

    <form method="POST" action="<?php 
echo URL::to('password_reset');
?>
" accept-charset="UTF-8" class="form-signin" style="top: 34px; display: block;">
        <?php 
if (Session::has('error')) {
    ?>
          <span class="error"><?php 
    echo trans(Session::get('reason'));
    ?>
</span>
        <?php 
} elseif (Session::has('success')) {
Пример #25
0
 public function loginWithGoogle()
 {
     // get data from input
     $code = Input::get('code');
     // get google service
     $googleService = OAuth::consumer('Google');
     // check if code is valid
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from google, get the token
         $token = $googleService->requestAccessToken($code);
         $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
         // Send a request with it
         $user = User::where('email', $result['email'])->first();
         if (is_null($user)) {
             return Redirect::to('/')->with('failure', 'Usuario no registrado');
         } else {
             Auth::login($user);
             Flash::success('Bienvenido nuevamente ' . Auth::user()->first_name);
             return Redirect::route('feed_path');
         }
     } else {
         // get googleService authorization
         $url = $googleService->getAuthorizationUri();
         // return to facebook login url
         return Redirect::to((string) $url);
     }
 }
Пример #26
0
 public function loginWithYahoo(Request $request)
 {
     // get data from request
     $token = $request->get('oauth_token');
     $verify = $request->get('oauth_verifier');
     \OAuth::setHttpClient('CurlClient');
     // get yahoo service
     $yh = \OAuth::consumer('Yahoo');
     // if code is provided get user data and sign in
     if (!is_null($token) && !is_null($verify)) {
         // This was a callback request from yahoo, get the token
         $token = $yh->requestAccessToken($token, $verify);
         $xid = [$token->getExtraParams()];
         $result = json_decode($yh->request('https://social.yahooapis.com/v1/user/' . $xid[0]['xoauth_yahoo_guid'] . '/profile?format=json'), true);
         //Var_dump
         //display whole array.
         dd($result);
     } else {
         // get request token
         $reqToken = $yh->requestRequestToken();
         // get Authorization Uri sending the request token
         $url = $yh->getAuthorizationUri(['oauth_token' => $reqToken->getRequestToken()]);
         // return to yahoo login url
         return redirect((string) $url);
     }
 }
Пример #27
0
 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);
     }
 }
Пример #28
0
 public function loginWithGoogle()
 {
     // get data from input
     $code = Input::get('code');
     // get google service
     $googleService = OAuth::consumer('Google');
     // check if code is valid
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from google, get the token
         $token = $googleService->requestAccessToken($code);
         // Send a request with it
         $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
         if (!empty($token)) {
             try {
                 // Find the user using the user id
                 $user = Sentry::findUserByLogin($result['email']);
                 // Log the user in
                 Sentry::login($user, false);
                 return Redirect::route('home');
             } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
                 // Register the user
                 $user = Sentry::register(array('activated' => 1, 'email' => $result['email'], 'password' => Hash::make(uniqid(time())), 'first_name' => $result['name'], 'avatar' => $result['picture'], 'country' => !empty($result['location']) ? $result['location'] : false));
                 $usergroup = Sentry::getGroupProvider()->findById(2);
                 $user->addGroup($usergroup);
                 Sentry::login($user, false);
                 return Redirect::route('account');
             }
         }
     } else {
         // get googleService authorization
         $url = $googleService->getAuthorizationUri();
         // return to facebook login url
         return Redirect::to((string) $url);
     }
 }
Пример #29
0
 /**
  * Login user with Google
  *
  * @return void
  */
 public function oauthGoogle()
 {
     // get data from input
     $code = Input::get('code');
     // get google service
     //$googleService = OAuth::consumer( 'Google' );
     $googleService = OAuth::consumer('Google', 'http://dev.thelobbi.com/oauth/session/google');
     // if code is provided get user data and sign in
     if (!empty($code)) {
         // This was a callback request from google, get the token
         $token = $googleService->requestAccessToken($code);
         // Send a request with it
         $response = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
         // dd($response)
         // check if user already exists
         $user_id = $this->getUserIdGivenSocialId('google', (string) $response['id']);
         if ($user_id) {
             // user already exists, sign them in
             Auth::login($user_id);
             return Redirect::back();
         } else {
             // put google data into session var from use later
             $this->packSocialData('google', $response['id'], null, $response['email'], $response['gender'], 1);
             // send user to account create screen
             return Redirect::to('users/create');
         }
     } else {
         // get googleService authorization
         $url = $googleService->getAuthorizationUri();
         // return to google login url
         return Redirect::to((string) $url);
     }
 }
Пример #30
0
 public function getLoginWithFacebook()
 {
     $code = Input::get('code');
     $fb = OAuth::consumer('Facebook');
     if (!empty($code)) {
         $token = $fb->requestAccessToken($code);
         $result = json_decode($fb->request('/me'), true);
         $message = "Your unique facebook user id is : " . $result['id'] . " and your name is " . $result['name'];
         // echo $message . "<br>";
         $info = json_encode($result);
         // echo $info;
         // return $result;
         $user = new User();
         $un = ucfirst(strtolower($result['last_name'] . $result['first_name']));
         $pw = 'alumnidefault';
         $user->username = strtolower($result['last_name'] . $result['first_name']);
         $user->firstname = ucfirst(strtolower($result['first_name']));
         $user->midname = ucfirst(strtolower($result['middle_name']));
         $user->lastname = ucfirst(strtolower($result['last_name']));
         $user->email = strtolower($result['email']);
         $user->password = Hash::make('alumnidefault');
         $user->save();
         $userdata = array('username' => $un, 'password' => $pw, 'is_active' => 1);
         if (Auth::attempt($userdata, false)) {
             return Redirect::to('/');
         } else {
             return Redirect::to('login')->with('loginmsg', 'Incorrect Password/Username.');
         }
         // return Redirect::to('/register')->with('result', $result);
     } else {
         $url = $fb->getAuthorizationUri();
         return Redirect::to((string) $url);
     }
 }