/** * Change user password * Based on simple form. * * @param array $payload */ public static function changepassword($payload) { $token = $payload->reset_token; $user = User::email($payload->email)->whereHas('accounts', function ($q) use($token) { $q->where('account_user.reset_token', $token); })->first(); # e-mail and token validation if (!$user) { throw new \Cloudoki\InvalidParameterException('Invalid e-mail address or reset link.'); } # repeated password validation if ($payload->password !== $payload->password_confirmation) { throw new \Cloudoki\InvalidParameterException('The passwords do not match.'); } # Update user $user->setPassword($payload->password)->setResetToken(null)->save(); }