public function updateFromGoogleAccount() { $client = GoogleSessionController::getClient(); $oauth2 = new \Google_Auth_OAuth2($client); if ($this->google_token && $oauth2->isAccessTokenExpired() == false) { $oauth2->refreshToken($this->google_token); $client->setAccessToken($oauth2->getAccessToken()); $oauth2 = new \Google_Service_Oauth2($client); $google_user = $oauth2->userinfo->get(); // update the photo GoogleSessionController::saveGoogleProfileImage($google_user, $this); // other things later.. return true; } return false; }
public function createAccountFromGoogleAccount(&$google_user, $token) { $wantsJson = Request::wantsJson(); $email = $google_user->email; $username = explode("@", $email)[0]; $user = new User(); $user->username = $username; $user->email = $email; $password = Hash::make($username); // <-- temp... $user->firstname = $google_user->givenName; $user->lastname = $google_user->familyName; $user->password = $password; $user->password_confirmation = $password; $user->confirmation_code = md5($user->username . time('U')); $user->google_token = $token; $user->google_id = $google_user->id; if ($user->save()) { // profile image GoogleSessionController::saveGoogleProfileImage($google_user, $user); // Default Roles if ($username == 'tvanderlin' || $username == 'kmiller' || $username == 'Admin') { // <--- $adminRole = Role::where('name', '=', 'Admin')->first(); $user->attachRole($adminRole); } else { $role = $role = Role::where('name', '=', 'Reader')->first(); if ($role) { $user->attachRole($role); $user->save(); } } // fire a new notification to the system Notification::fire($user, Notification::NOTIFICATION_HALP_WELCOME); Auth::login($user); return Redirect::to('/'); } else { return $wantsJson ? Response::json(['errors' => $user->errors()->all()]) : Redirect::to('register')->with(['errors' => $user->errors()->all()]); } return Response::json(['user' => $user]); }