Hi, I have this function for password recovery
public function postForgotPassword()
{
$validator = Validator::make(Input::all(), array(
'email' => 'required|email'
));
if($validator->fails())
{
return Redirect::route('account-forgot-password')
->withErrors($validator)
->withInput();
}
else
{
$user = User::where('email', '=', Input::get('email'));
if($user->count())
{
$user = $user->first();
$code = str_random(60);
$password = str_random(10);
$user->$code = $code;
$user->$password_temp = Hash::make($password);
if($user->save())
{
Mail::send('emails.auth.forgot', array('link' => URL::route('account-recover', $code), 'username' =>$user->username, 'password' => $password), function($message) use($user){
$message ->to($user->email, $user->username)->subject('Your new password');
});
return Redirect::route('home')
->with('global','We have sent you new password');
}
}
}
return Redirect::route('account-forgot-password')
->with('global', "Could not request new password");
}
But when I try to recover I get the error - ErrorException (E_UNKNOWN) Undefined variable: password_temp? $password_temp is valid row from table users..
You need to get rid of your $,
You are trying to render a variable called $password_temp, which would work if the value was a field name but that isn't what you want.... What you want is to access a field named password_temp.
Change this
$user->$code = $code;
$user->$password_temp = Hash::make($password);
To this
$user->code = $code;
$user->password_temp = Hash::make($password);
Well, now is working. Thank you for your help!
You might also want to validate if the email exists
'email' => 'required|email|exists:table,column'
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community