/** * This function is checking if the email address is already associated with any user. * @param $attribute * @param $value * @param $parameters * @return bool */ public function validateCheckemailexist($attribute, $value, $parameters) { $SentryUser = new \SentryUser(); if ($SentryUser->checkIfUserExist($value)) { return true; } else { return false; } }
/** * Get all the user groups that a user lies in * @param SentryUser $user The user * @param string $value Value * @param key $key Key * @return array */ public function getUserGroups($user, $value = null, $key = null) { if (!$value) { // If no value is passed return Sentry Object return $user->getGroups(); } $groups = array(); foreach ($user->getGroups() as $group) { if ($key) { $groups[$group->{$key}] = $group->{$value}; } else { $groups[] = $group->{$value}; } } return $groups; }
/** * Handling the OAuth login */ public function handleOAuthLogin() { // 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); $SentryUser = new SentryUser(); // checking if the email domain is allowed if ($SentryUser->validateOAuthAllowedDomains($result['email'])) { $SentryUser->handleOAuthLogin($result); return Redirect::to($this->dashboard); } else { SentryHelper::dsm('This domain is not allowed on this site.', 'warning'); } } else { // get googleService authorization $url = $googleService->getAuthorizationUri(); // return to google login url return Redirect::to((string) $url); } }
public function onUserProfileChange($user) { $SentryUser = new SentryUser(); $SentryUser->setUserSession($user->id); }