示例#1
0
 /**
  * Attempt to reset a user and send him a new password
  *
  * This will unsuspend a user and give him a new password.
  *
  * @param int $id The user id
  * @param string $reset_code The password reset code
  * @throws PasswordResetFailedException Throws an exception without further information on failure
  * @throws PasswordResetCodeInvalidException Throws an exception without further information on failure
  * @throws MailException Throws an exception containing further information as message
  * @throws UserNotFoundException Throws an exception without further information on failure
  * @return void
  */
 public function sendNewPassword($id, $reset_code)
 {
     $user = $this->sentry->findUserById($id);
     $this->prepareResetResultMailData($user, $reset_code);
     $this->setMailErrorMessage('Sending the email containing the new password failed. ' . 'Please try again later or contact the administrator.');
     $this->sendMail();
 }
 /**
  * Finds a user by the given user ID.
  *
  * @author ZZK
  * @link   http://verecom.com
  *
  * @param $id
  *
  * @throws UserNotFoundException
  *
  * @return \Cartalyst\Sentry\Users\UserInterface
  */
 public function findById($id)
 {
     try {
         return $this->sentry->findUserById($id);
     } catch (SentryUserNotFoundException $e) {
         throw new UserNotFoundException($e->getMessage());
     }
 }
示例#3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($data)
 {
     try {
         // Find the group using the group id
         $group = $this->sentry->findGroupById($data['id']);
         foreach ($data['users'] as $id => $access) {
             $user = $this->sentry->findUserById($id);
             if ($access) {
                 $user->addGroup($group);
             } else {
                 $user->removeGroup($group);
             }
             // todo add error checking
         }
         // Update the group details
         $group->permissions = $data['permissions'];
         $group->name = $data['name'];
         // Update the group
         if ($group->save()) {
             // Group information was updated
             $result['success'] = true;
             $result['message'] = trans('groups.updated');
         } else {
             // Group information was not updated
             $result['success'] = false;
             $result['message'] = trans('groups.updateproblem');
         }
     } catch (\Cartalyst\Sentry\Groups\NameRequiredException $e) {
         $result['success'] = false;
         $result['message'] = trans('groups.namereq');
     } catch (\Cartalyst\Sentry\Groups\GroupExistsException $e) {
         $result['success'] = false;
         $result['message'] = trans('groups.groupexists');
     } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
         $result['success'] = false;
         $result['message'] = trans('groups.notfound');
     }
     return $result;
 }
 /**
  * Finds a user by the given user ID.
  *
  * @param mixed $id
  * @return \Cartalyst\Sentry\Users\UserInterface 
  * @throws \Cartalyst\Sentry\Users\UserNotFoundException
  * @static 
  */
 public static function findUserById($id)
 {
     return \Cartalyst\Sentry\Sentry::findUserById($id);
 }