I'm new to Laravel 4.
Want to know if I can reset the password of users, when logged as administrator. In that case I don't need a token to allow to change password as when the user receives an email to change her password. I'am inspiring myself in ReminderController class postReset method:
/**
* Handle a POST request to reset a user's password.
*
* @return Response
*/
public function postReset()
{
$credentials = Input::only(
'email', 'password', 'password_confirmation', 'token'
);
$response = Password::reset($credentials, function ($user, $password) {
$user->password = Hash::make($password);
$user->save();
Auth::login($user);
});
switch ($response) {
case Password::INVALID_TOKEN:
return Redirect::to('/login')->with('error', Lang::get($response));
case Password::INVALID_PASSWORD:
case Password::INVALID_USER:
return Redirect::back()->with('error', Lang::get($response));
case Password::PASSWORD_RESET:
return Redirect::to('/')->with('message', Lang::get($response));
}
}
But this method deal with token string
in $credetials
variable when calling Password::reset
. Bellow is the method that updates the user data.
public function update($colaborador)
{
$credentials = Input::only(
'nome_completo', 'email', 'password', 'password_confirmation', 'token'
);
$emailGestor = Input::get('email-gestor');
$enviarEmail = Input::get('enviar-email');
$user = $colaborador->user;
if (User::where('email', $email)->where('id', '!=', $user->id)->count() > 0) {
$mensagem = 'O endereço de e-mail ' . $email . ' já está sendo utilizado.';
} else {
$response = Password::reset($credentials, function ($credentials, $user, $password, $enviarEmail) {
$user->nome_completo = $credentials['nome_completo'];
$user->email = $credentials['email'];
$user->password = Hash::make($password);
$user->save();
$mensagem = 'Colaborador alterado.';
if ($enviarEmail == 1) {
PrimeiroAcesso::remind(['email' => $email], function ($msg) {
$msg->subject('Assessment – Mapeamento de Competências Funcionais Natura');
});
$mensagem .= ' E-mail de primeiro acesso enviado.';
}
});
switch ($response) {
case Password::INVALID_TOKEN:
$mensagem = 'Token inválido.'; break;
case Password::INVALID_PASSWORD:
$mensagem = 'Senha inválida.'; break;
case Password::INVALID_USER:
$mensagem = 'Nome de usuário inválido'; break;
default: break;
}
}
if ($emailGestor == '' && $colaborador->gestor) {
$colaborador->gestor()->dissociate();
$colaborador->save();
$mensagem .= ' Gestor removido.';
} else {
$gestor = User::with('colaborador')->where('email', $emailGestor)->first();
if ($gestor) {
$colaborador->gestor()->associate($gestor->colaborador);
$colaborador->save();
$mensagem .= ' Gestor alterado para ' . $emailGestor . '.';
}
}
return Redirect::route('admin.colaborador.index')->with('flash_message', $mensagem);
}
In
$credentials = Input::only(
'nome_completo', 'email', 'password', 'password_confirmation', 'token'
);
I get token
from the form in the view.