예제 #1
0
 public function deleteRole($id)
 {
     PermApi::access_check('manage_permissions');
     try {
         DB::beginTransaction();
         // start the DB transaction
         $group = Sentry::findGroupById($id);
         $authenticatedGroup = Sentry::findGroupById(3);
         // super admin group cannot be deleted
         if ($id == 1 || $id == 3) {
             SentryHelper::setMessage('This role cannot be deleted.', 'warning');
             return Redirect::to('user/permission/list');
         }
         // assign authenticated user group
         $users = Sentry::findAllUsersInGroup($group);
         foreach ($users as $user) {
             $user->addGroup($authenticatedGroup);
         }
         // delete group
         $group->delete();
         // clear permission in group mapping
         DB::table('permission_in_group')->where('group_id', $id)->delete();
         DB::table('users_groups')->where('user_id', $id)->update(array('group_id' => $authenticatedGroup->id));
         DB::commit();
         // commit the DB transaction
         SentryHelper::setMessage('Role deleted, all users of this role are now Authenticated users.');
         return Redirect::to('user/permission/list');
     } catch (\Exception $e) {
         DB::rollback();
         // something went wrong
     }
 }
예제 #2
0
 /**
  * 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);
     }
 }
예제 #3
0
 /**
  * Handle the role delete. Need to check
  * @return mixed
  */
 public function handleRoleUpdate()
 {
     PermApi::access_check('manage_permissions');
     $roleName = Input::get('role');
     $roleId = Input::get('roleId');
     $SentryPermission = new SentryPermission();
     if ($SentryPermission->updateRole($roleId, $roleName)) {
         SentryHelper::setMessage('Role updated');
     } else {
         SentryHelper::setMessage('Role not updated', 'warning');
     }
     return Redirect::to('user/role/edit/' . $roleId);
 }
예제 #4
0
 public function handleOAuthLogin($OAuthData)
 {
     if (!$this->checkIfUserExist($OAuthData['email'])) {
         // user should login
         $user = Sentry::findUserByLogin($OAuthData['email']);
         // get the sentry user object
         Sentry::login($user, true);
         // log in the user using sentry
         // calling the event of setting user session
         $subscriber = new SentryuserEventHandler();
         Event::subscribe($subscriber);
         Event::fire('sentryuser.login', array($user, $OAuthData));
     } else {
         // creating the user
         $newUser = Sentry::createUser(array('email' => $OAuthData['email'], 'password' => time() . rand(0, 99), 'activated' => true, 'first_name' => $OAuthData['given_name'] ? $OAuthData['given_name'] : "", 'last_name' => $OAuthData['family_name'] ? $OAuthData['family_name'] : ""));
         // insert extra details about the user
         DB::table('user_details')->insert(array('user_id' => $newUser->id, 'user_type' => 'o-auth', 'oauthid' => $OAuthData['id'], 'oauth_link' => isset($OAuthData['link']) ? $OAuthData['link'] : "", 'oauth_pic' => isset($OAuthData['picture']) ? $OAuthData['picture'] : "", 'gender' => isset($OAuthData['gender']) ? $OAuthData['gender'] : "", 'locale' => isset($OAuthData['locale']) ? $OAuthData['locale'] : ""));
         // assign the group to the user
         $group = Sentry::findGroupById(3);
         // authenticated user group
         $newUser->addGroup($group);
         // login in the user
         $user = Sentry::findUserById($newUser->id);
         // get the sentry user object
         Sentry::login($user, true);
         // log in the user using sentry
         // calling the event of setting user session
         $subscriber = new SentryuserEventHandler();
         Event::subscribe($subscriber);
         Event::fire('sentryuser.login', array($user, $OAuthData));
         SentryHelper::setMessage('Welcome to Focalworks Intranet', 'success');
         return true;
     }
 }