Skip to content

Commit

Permalink
Update user controller for L5
Browse files Browse the repository at this point in the history
  • Loading branch information
rydurham committed Feb 8, 2015
1 parent 27aa4fa commit c629aa0
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 114 deletions.
116 changes: 47 additions & 69 deletions src/Sentinel/Repositories/User/SentryUserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public function store($data)
if (array_key_exists('activate', $data)) {
$activateUser = (bool)$data['activate'];
} else {
$activateUser = ! $this->config->get('sentinel.require_activation', true);
$activateUser = !$this->config->get('sentinel.require_activation', true);
}

//Prepare the user credentials
$credentials = [
'email' => e($data['email']),
'email' => e($data['email']),
'password' => e($data['password'])
];

Expand Down Expand Up @@ -99,7 +99,7 @@ public function store($data)

// Response Payload
$payload = [
'user' => $user,
'user' => $user,
'activated' => $activateUser
];

Expand All @@ -108,10 +108,9 @@ public function store($data)

// Return a response
return new SuccessResponse($message, $payload);
}
catch (UserExistsException $e)
{
} catch (UserExistsException $e) {
$message = trans('Sentinel::users.exists');

return new ExceptionResponse($message);
}
}
Expand Down Expand Up @@ -147,15 +146,13 @@ public function update($data)
}

return new FailureResponse(trans('Sentinel::users.notupdated'), ['user' => $user]);
}
catch (UserExistsException $e)
{
} catch (UserExistsException $e) {
$message = trans('Sentinel::users.exists');

return new ExceptionResponse($message);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}
Expand Down Expand Up @@ -183,18 +180,17 @@ public function destroy($id)

// Unable to delete the user
return new FailureResponse(trans('Sentinel::users.notdestroyed'), ['user' => $user]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}

/**
* Attempt activation for the specified user
*
* @param int $id
* @param int $id
* @param string $code
*
* @return bool
Expand All @@ -217,15 +213,13 @@ public function activate($id, $code)
}

return new FailureResponse(trans('Sentinel::users.notactivated'), ['user' => $user]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
catch (UserAlreadyActivatedException $e)
{
} catch (UserAlreadyActivatedException $e) {
$message = trans('Sentinel::users.alreadyactive');

return new ExceptionResponse($message);
}
}
Expand All @@ -244,10 +238,10 @@ public function resend($data)
$user = $this->sentry->getUserProvider()->findByLogin(e($data['email']));

// If the user is not currently activated resend the activation email
if ( ! $user->isActivated()) {
if (!$user->isActivated()) {

$this->dispatcher->fire('sentinel.user.resend', [
'user' => $user,
'user' => $user,
'activated' => $user->activated,
]);

Expand All @@ -256,13 +250,12 @@ public function resend($data)

// The user is already activated
return new FailureResponse(trans('Sentinel::users.alreadyactive'), ['user' => $user]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
// The user is trying to "reactivate" an account that doesn't exist. This could be
// a vector for determining valid existing accounts, so we will send a vague
// response without actually sending a new activation email.
$message = trans('Sentinel::users.emailconfirm');

return new SuccessResponse($message, []);
}
}
Expand All @@ -285,13 +278,12 @@ public function triggerPasswordReset($email)
]);

return new SuccessResponse(trans('Sentinel::users.emailinfo'), ['user' => $user]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
// The user is trying to send a password reset link to an account that doesn't
// exist. This could be a vector for determining valid existing accounts,
// so we will send a vague response without actually doing anything.
$message = trans('Sentinel::users.emailinfo');

return new SuccessResponse($message, []);
}
}
Expand All @@ -310,24 +302,22 @@ public function validateResetCode($id, $code)
try {
$user = $this->sentry->findUserById($id);

if (! $user->checkResetPasswordCode($code))
{
if (!$user->checkResetPasswordCode($code)) {
return new FailureResponse(trans('Sentinel::users.invalidreset'), ['user' => $user]);
}

return new SuccessResponse(null);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}

/**
* Process the password reset request
*
* @param int $id
* @param int $id
* @param string $code
*
* @return Array
Expand All @@ -348,10 +338,9 @@ public function resetPassword($id, $code, $password)
}

return new FailureResponse(trans('Sentinel::users.problem'), ['user' => $user]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}
Expand Down Expand Up @@ -388,10 +377,9 @@ public function changePassword($data)

// Password mismatch. Abort.
return new FailureResponse(trans('Sentinel::users.oldpassword'), ['user' => $user]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}
Expand Down Expand Up @@ -421,10 +409,9 @@ public function changePasswordWithoutCheck($data)

// User not Saved
return new FailureResponse(trans('Sentinel::users.passwordprob'), ['user' => $user]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}
Expand All @@ -443,10 +430,8 @@ public function changeGroupMemberships($userId, $selections)
$allGroups = $this->sentry->getGroupProvider()->findAll();

// Update group memberships
foreach ($allGroups as $group)
{
if (isset($selections[$group->name]))
{
foreach ($allGroups as $group) {
if (isset($selections[$group->name])) {
//The user should be added to this group
$user->addGroup($group);
} else {
Expand All @@ -456,10 +441,9 @@ public function changeGroupMemberships($userId, $selections)
}

return new SuccessResponse(trans('Sentinel::users.memberships'), ['user' => $user]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}
Expand All @@ -485,10 +469,9 @@ public function suspend($id)
$this->dispatcher->fire('sentinel.user.suspended', ['userId' => $id]);

return new SuccessResponse(trans('Sentinel::users.suspended'), ['userId' => $id]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}
Expand All @@ -514,10 +497,9 @@ public function unSuspend($id)
$this->dispatcher->fire('sentinel.user.unsuspended', ['userId' => $id]);

return new SuccessResponse(trans('Sentinel::users.unsuspended'), ['userId' => $id]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}
Expand All @@ -542,10 +524,9 @@ public function ban($id)
$this->dispatcher->fire('sentinel.user.banned', ['userId' => $id]);

return new SuccessResponse(trans('Sentinel::users.banned'), ['userId' => $id]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}
Expand All @@ -570,10 +551,9 @@ public function unBan($id)
$this->dispatcher->fire('sentinel.user.unbanned', ['userId' => $id]);

return new SuccessResponse(trans('Sentinel::users.unbanned'), ['userId' => $id]);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
$message = trans('Sentinel::sessions.invalid');

return new ExceptionResponse($message);
}
}
Expand All @@ -595,7 +575,7 @@ public function retrieveById($identifier)
/**
* Retrieve a user by by their unique identifier and "remember me" token.
*
* @param mixed $identifier
* @param mixed $identifier
* @param string $token
*
* @return \Illuminate\Auth\UserInterface|null
Expand Down Expand Up @@ -633,9 +613,7 @@ public function retrieveByCredentials(array $credentials)
{
try {
return $this->sentry->findUserByCredentials($credentials);
}
catch (UserNotFoundException $e)
{
} catch (UserNotFoundException $e) {
return null;
}
}
Expand Down Expand Up @@ -689,7 +667,7 @@ public function getUser()
* Validate a user against the given credentials.
*
* @param \Illuminate\Auth\UserInterface $user
* @param array $credentials
* @param array $credentials
*
* @return bool
*/
Expand Down

0 comments on commit c629aa0

Please sign in to comment.