| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 | <?phpnamespace App\Http\Controllers\Web\Auth;use Aix\Sms\Contracts\Smser;use App\Exceptions\ResponseException;use App\Http\Controllers\Web\WebBaseController;use App\Services\Auth\AuthService;use App\Services\Common\EmailService;use App\Services\Common\SmsService;use App\Services\Common\TencentCaptchaService;use App\Validators\ResetPasswordValidatorRequest;class ResetPasswordController extends WebBaseController{    /**     * @var SmsService     */    private $smsService;    /**     * @var AuthService     */    private $authService;    /**     * @var EmailService     */    private $emailService;    private $tencentCaptchaService;    /**     * ResetPasswordController constructor.     * @param SmsService $smsService     * @param AuthService $authService     * @param EmailService $emailService     */    public function __construct(SmsService $smsService, AuthService $authService, EmailService $emailService, TencentCaptchaService $tencentCaptchaService)    {        $this->smsService = $smsService;        $this->authService = $authService;        $this->emailService = $emailService;        $this->tencentCaptchaService = $tencentCaptchaService;    }    public function passwordRequest()    {        return view('app.auth.password_request', ['title'=>'重置密码']);    }    public function passwordRequestPost(ResetPasswordValidatorRequest $request)    {        if ($request->type == 'mobile') {            if (!$this->smsService->checkAuthSms($request->mobile, Smser::TEMPLATE_AUTH_CHECK, $request->mobile_vcode)) {                return $this->sendErrorResponse("短信验证码不对");            }            $token=$this->authService->resetPasswordToken($request->all());            return $this->sendSuccessResponse(['url'=>route('password.reset', ['token'=>$token])]);        } elseif ($request->type == 'email') {            if(!$this->tencentCaptchaService->check(request()->input('randstr'),request()->input('ticket'),request()->ip())){                return $this->sendErrorResponse("验证码不通过,请重新验证");            }            $token=$this->authService->resetPasswordToken($request->all());            $this->emailService->setCallback('App\Services\Auth\AuthService', 'sendEmailHook', [$request->email, $token])            ->sendAuthMail($request->email, EmailService::TEMPLATE_PASSWORD_RESET);            return $this->sendSuccessResponse(['url'=>route('password.reset', ['token'=>$request->email])]);        }    }    public function passwordReset($token)    {        $data['token']=$token;        $data['title']="重置密码";        if (validator_check($token, 'email')) {            return view('app.auth.password_reset_email', $data);        }        if (!$data=$this->authService->checkResetPasswordToken($token)) {            throw new ResponseException("who are you?", [], 404);        }        $data['token']=$token;        $data['title']="重置密码";        return view('app.auth.password_reset', $data);    }    public function passwordResetPost(ResetPasswordValidatorRequest $request, $token)    {        if (!$data=$this->authService->checkResetPasswordToken($token)) {            throw new ResponseException("who are you?", [], 404);        }        $utype=$this->authService->resetPassword($token, $request->password);        $login_url =$utype==1?route('login.company'):route('login');        return view('app.auth.password_reset_success', ['login_url'=>$login_url]);    }}
 |