ResetPasswordController.php 2.62 KB
Newer Older
Viral Solani's avatar
Viral Solani committed
1 2 3 4 5 6
<?php

namespace App\Http\Controllers\Frontend\Auth;

use App\Http\Controllers\Controller;
use App\Repositories\Frontend\Access\User\UserRepository;
7 8
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
Viral Solani's avatar
Viral Solani committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

/**
 * Class ResetPasswordController.
 */
class ResetPasswordController extends Controller
{
    use ResetsPasswords;

    /**
     * @var UserRepository
     */
    protected $user;

    /**
     * ChangePasswordController constructor.
     *
     * @param UserRepository $user
     */
    public function __construct(UserRepository $user)
    {
        $this->user = $user;
    }

    /**
     * Where to redirect users after resetting password.
     *
     * @return string
     */
    public function redirectPath()
    {
        return route('frontend.index');
    }

    /**
     * Display the password reset view for the given token.
     *
     * If no token is present, display the link request form.
     *
     * @param string|null $token
     *
     * @return \Illuminate\Http\Response
     */
    public function showResetForm($token = null)
    {
53
        if (!$token) {
54 55 56 57 58 59 60 61 62 63 64 65 66
            return redirect()->route('frontend.auth.password.email');
        }

        $user = $this->user->findByPasswordResetToken($token);

        if ($user && app()->make('auth.password.broker')->tokenExists($user, $token)) {
            return view('frontend.auth.passwords.reset')
                ->withToken($token)
                ->withEmail($user->email);
        }

        return redirect()->route('frontend.auth.password.email')
            ->withFlashDanger(trans('exceptions.frontend.auth.password.reset_problem'));
Viral Solani's avatar
Viral Solani committed
67 68 69 70 71 72 73 74 75 76
    }

    /**
     * Get the password reset validation rules.
     *
     * @return array
     */
    protected function rules()
    {
        return [
77 78 79
            'token'    => 'required',
            'email'    => 'required|email',
            'password' => 'required|min:8|confirmed|regex:"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$"',
Viral Solani's avatar
Viral Solani committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93
        ];
    }

    /**
     * Get the password reset validation error messages.
     *
     * @return array
     */
    protected function validationErrorMessages()
    {
        return [
            'password.regex' => 'Password must contain at least 1 uppercase letter and 1 number.',
        ];
    }
94 95 96 97

    /**
     * Get the response for a successful password reset.
     *
Vipul Basapati's avatar
Vipul Basapati committed
98 99
     * @param \Illuminate\Http\Request $request
     * @param string                   $response
100
     *
101 102
     * @return \Illuminate\Http\RedirectResponse
     */
Vipul Basapati's avatar
Vipul Basapati committed
103
    protected function sendResetResponse($request, $response)
104 105 106
    {
        return redirect()->route(homeRoute())->withFlashSuccess(trans($response));
    }
Viral Solani's avatar
Viral Solani committed
107
}