12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Http\Controllers\Mobile\Auth;
- use Aix\Sms\Contracts\Smser;
- use App\Exceptions\ResponseException;
- use App\Http\Controllers\Mobile\MobileBaseController;
- use App\Services\Auth\AuthService;
- use App\Services\Common\EmailService;
- use App\Services\Common\SmsService;
- use App\Validators\ResetPasswordValidatorRequest;
- class ResetPasswordController extends MobileBaseController
- {
- /**
- * @var SmsService
- */
- private $smsService;
- /**
- * @var AuthService
- */
- private $authService;
- /**
- * @var EmailService
- */
- private $emailService;
- /**
- * ResetPasswordController constructor.
- * @param SmsService $smsService
- * @param AuthService $authService
- * @param EmailService $emailService
- */
- public function __construct(SmsService $smsService, AuthService $authService, EmailService $emailService)
- {
- $this->smsService = $smsService;
- $this->authService = $authService;
- $this->emailService = $emailService;
- }
- public function passwordRequest()
- {
- return view('mobile.app.auth.password', ['wap_title'=>'重置密码']);
- }
- public function passwordRequestMobile($utype)
- {
- return view('mobile.app.auth.password_mobile', ['utype'=>$utype, 'wap_title'=>'重置密码']);
- }
- public function passwordRequestEmail($utype)
- {
- return view('mobile.app.auth.password_email', ['utype'=>$utype, 'wap_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('mobile.password.reset', ['token'=>$token])]);
- } elseif ($request->type == 'email') {
- $token=$this->authService->resetPasswordToken($request->all());
- $this->emailService->setCallback('App\Services\Auth\AuthService', 'sendEmailHook', [$request->email, $token])
- ->setCheckRoute("mobile.email.check")
- ->sendAuthMail($request->email, EmailService::TEMPLATE_PASSWORD_RESET);
- return $this->sendSuccessResponse(['url'=>route('mobile.password.reset', ['token'=>$request->email])]);
- }
- }
- public function passwordReset($token)
- {
- $data['token']=$token;
- $data['wap_title']="重置密码";
- if (validator_check($token, 'email')) {
- return view('mobile.app.auth.password_reset_email', $data);
- }
- if (!$data=$this->authService->checkResetPasswordToken($token)) {
- throw new ResponseException("who are you?", [], 404);
- }
- $data['token']=$token;
- $data['wap_title']="重置密码";
- return view('mobile.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('mobile.login.company'):route('mobile.login');
- return view('mobile.app.auth.password_reset_success', ['wap_title'=>'重置密码', 'login_url'=>$login_url]);
- }
- }
|