Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Confide/ConfideUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ trait ConfideUser
*/
public $errors;

/**
* A boolean that store if a validation ocurring is for password resetting
* only
* @var bool
*/
private $isResetOnly;

/**
* Confirm the user (usually means that the user)
* email is valid. Sets the confirmed attribute of
Expand All @@ -46,6 +53,15 @@ public function forgotPassword()
return ConfideFacade::forgotPassword($this->email);
}

/**
* Set validation method to check only for fields related to password
* resetting
* @return void
*/
public function setResetOnly() {
$this->isResetOnly = true;
}

/**
* Checks if the current user is valid using the ConfideUserValidator.
*
Expand All @@ -61,6 +77,10 @@ public function isValid()
// If the model already exists in the database we call validate with
// the update ruleset
if ($this->exists) {
if ($this->isResetOnly) {
return $validator->validate($this, 'password_reset');
}

return $validator->validate($this, 'update');
}

Expand Down
7 changes: 7 additions & 0 deletions src/Confide/ConfideUserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ interface ConfideUserInterface extends UserInterface, RemindableInterface
*/
public function confirm();

/**
* Set validation method to check only for fields related to password
* resetting
* @return void
*/
public function setResetOnly();

/**
* Send email with information about password reset.
*
Expand Down
8 changes: 6 additions & 2 deletions src/Confide/UserValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class UserValidator implements UserValidatorInterface
'username' => 'alpha_dash',
'email' => 'required|email',
'password' => 'required|min:4',
],
'password_reset' => [
'password' => 'required|min:4',
]
];

Expand Down Expand Up @@ -90,6 +93,9 @@ public function validatePassword(ConfideUserInterface $user)

// Hashes password and unset password_confirmation field
$user->password = $hash->make($user->password);
unset($user->password_confirmation);

return true;
} else {
$this->attachErrorMsg(
$user,
Expand All @@ -100,8 +106,6 @@ public function validatePassword(ConfideUserInterface $user)
}
}

unset($user->password_confirmation);

return true;
}

Expand Down
6 changes: 4 additions & 2 deletions src/views/generators/controller.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,17 @@ public function {{ (! $restful) ? 'doResetPassword' : 'postReset' }}()
);

// By passing an array with the token, password and confirmation
if ($repo->resetPassword($input)) {
$result = $repo->resetPassword( $input );
if ( $result['status'] ) {
$notice_msg = Lang::get('confide::confide.alerts.password_reset');
return Redirect::action('{{ $namespace ? $namespace.'\\' : '' }}{{ $class }}{{ (! $restful) ? '@login' : '@getLogin' }}')
->with('notice', $notice_msg);
} else {
$error_msg = Lang::get('confide::confide.alerts.wrong_password_reset');
return Redirect::action('{{ $namespace ? $namespace.'\\' : '' }}{{ $class }}{{ (! $restful) ? '@resetPassword' : '@getReset' }}', array('token'=>$input['token']))
->withInput()
->with('error', $error_msg);
->with('error', $error_msg)
->withErrors($result['errors']);
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/views/generators/repository.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,19 @@ public function resetPassword($input)
{
$result = false;
$user = Confide::userByResetPasswordToken($input['token']);
$user->setResetOnly();

if ($user) {
$user->password = $input['password'];
$user->password_confirmation = $input['password_confirmation'];
$result = $this->save($user);
$result['status'] = $this->save($user);
}

// If result is positive, destroy token
if ($result) {
// If result status is positive, destroy token
if ($result['status']) {
Confide::destroyForgotPasswordToken($input['token']);
} else {
$result['errors'] = $user->errors;
}

return $result;
Expand Down