ResetPasswordController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\UserInfo;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Response;
  6. class ResetPasswordController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return Response
  12. */
  13. public function index()
  14. {
  15. //
  16. }
  17. /**
  18. * Store a newly created resource in storage.
  19. *
  20. * @return Response
  21. */
  22. public function store(Request $request)
  23. {
  24. //
  25. $user = UserInfo::where('reset_password_token', $request->input('token'))
  26. ->where('username', $request->input('username'))
  27. ->first();
  28. if (! $user) {
  29. return $this->error('no token', 404, 404);
  30. }
  31. if (mb_strlen($request->input('password'), 'UTF-8') < 6) {
  32. return $this->error('input is invalid', 402, 402);
  33. }
  34. $user->password = md5($request->input('password'));
  35. $user->reset_password_token = null;
  36. $ok = $user->save();
  37. if ($ok) {
  38. return $this->ok($user);
  39. } else {
  40. return $this->error('fail to set password', 500, 500);
  41. }
  42. }
  43. /**
  44. * 根据token获取用户名.
  45. *
  46. * @param string $token
  47. * @return Response
  48. */
  49. public function show($token)
  50. {
  51. //
  52. $user = UserInfo::where('reset_password_token', $token)
  53. ->select(['username'])->first();
  54. if (! $user) {
  55. return $this->error('no token', 404, 404);
  56. }
  57. return $this->ok($user);
  58. }
  59. /**
  60. * Update the specified resource in storage.
  61. *
  62. * @return Response
  63. */
  64. public function update(Request $request, UserInfo $userInfo)
  65. {
  66. //
  67. }
  68. /**
  69. * Remove the specified resource from storage.
  70. *
  71. * @return Response
  72. */
  73. public function destroy(UserInfo $userInfo)
  74. {
  75. //
  76. }
  77. }