ForgotPasswordController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Controllers\Auth\Front;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Controllers\Traits\ApiResponseTrait;
  5. use App\Http\Requests\Front\ForgotPasswordRequest;
  6. use App\Models\Member;
  7. use App\Servers\SmsServer;
  8. class ForgotPasswordController extends Controller
  9. {
  10. use ApiResponseTrait;
  11. // 修改密码
  12. public function modify(ForgotPasswordRequest $request)
  13. {
  14. $phone = $request->input('phone', '');
  15. $password = $request->input('password', '');
  16. $member = Member::where('phone', $phone)->first();
  17. $type = $request->input('type', '');
  18. if( empty($member) ){
  19. return $this->apiResponseError(null,'账号不存在');
  20. }
  21. if( empty($type) ){
  22. return $this->apiResponseError(null,'接口类型必传');
  23. }
  24. // 短信验证码验证
  25. $sms = $request->input('sms', 'sms');
  26. // 短信验证码是否通过
  27. $result = (new SmsServer())->checkSms($sms, $phone, $type);
  28. if( $result['errcode'] === false ){
  29. return $this->apiResponseError(null,$result['errmsg']);
  30. }
  31. $member->{'password'} = bcrypt($password);
  32. $member->{'y_password'} = $password;
  33. $result = $member->save();
  34. if( !$result ){
  35. return $this->apiResponseError(null,"修改失败");
  36. }
  37. return $this->apiResponseSuccess(null, "修改成功");
  38. }
  39. }