1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Api\v1\Auth; |
4
|
|
|
|
5
|
|
|
use App\Helpers\Interfaces\ResponseCodesInterface; |
6
|
|
|
use App\Helpers\JsonApiResponseHelper; |
7
|
|
|
use App\Http\Controllers\Controller; |
8
|
|
|
use Illuminate\Foundation\Auth\ResetsPasswords; |
9
|
|
|
use Illuminate\Http\Request; |
10
|
|
|
use Illuminate\Support\Facades\Password; |
11
|
|
|
use Illuminate\Http\JsonResponse; |
12
|
|
|
use Validator; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class ResetPasswordController |
16
|
|
|
* @package App\Http\Controllers\Api\v1\Auth |
17
|
|
|
*/ |
18
|
|
|
class ResetPasswordController extends Controller implements ResponseCodesInterface |
19
|
|
|
{ |
20
|
|
|
use ResetsPasswords, JsonApiResponseHelper; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* ResetPasswordController constructor. |
24
|
|
|
*/ |
25
|
|
|
public function __construct() |
26
|
|
|
{ |
27
|
|
|
$this->middleware('guest'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @SWG\Post(path="/password/reset", |
32
|
|
|
* tags={"User actions"}, |
33
|
|
|
* summary="Perform user password reset", |
34
|
|
|
* description="reset user password", |
35
|
|
|
* produces={"application/json"}, |
36
|
|
|
* consumes={"application/json"}, |
37
|
|
|
* @SWG\Parameter( |
38
|
|
|
* in="body", |
39
|
|
|
* name="reset password", |
40
|
|
|
* description="JSON Object which reset user password", |
41
|
|
|
* required=true, |
42
|
|
|
* @SWG\Schema( |
43
|
|
|
* type="object", |
44
|
|
|
* @SWG\Property(property="email", type="string", example="[email protected]"), |
45
|
|
|
* @SWG\Property(property="password", type="string", example="87654321"), |
46
|
|
|
* @SWG\Property(property="password_confirmation", type="string", example="87654321"), |
47
|
|
|
* @SWG\Property(property="token", type="string", example="87654321") |
48
|
|
|
* ) |
49
|
|
|
* ), |
50
|
|
|
* @SWG\Response(response="200", description="Return message") |
51
|
|
|
* ) |
52
|
|
|
*/ |
53
|
|
|
|
54
|
|
|
public function reset(Request $request) |
55
|
|
|
{ |
56
|
|
|
$errors = $this->validateRequest($request->all())->errors(); |
57
|
|
|
|
58
|
|
|
if (!empty($errors->all())) { |
59
|
|
|
return $this->sendFailedResponse($errors->toArray(), self::HTTP_CODE_UNPROCESSABLE_ENTITY); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$response = $this->broker()->reset( |
63
|
|
|
$this->credentials($request), |
64
|
|
|
function ($user, $password) { |
65
|
|
|
$this->resetPassword($user, $password); |
66
|
|
|
} |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
return |
70
|
|
|
$response == Password::PASSWORD_RESET |
71
|
|
|
? $this->sendSuccessResponse() |
72
|
|
|
: $this->sendFailedResponse( |
73
|
|
|
['token' => 'Your reset link has expired. Please try to resend it again.'], |
74
|
|
|
self::HTTP_CODE_BAD_REQUEST |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param array $data |
80
|
|
|
* @return \Illuminate\Validation\Validator |
81
|
|
|
*/ |
82
|
|
|
protected function validateRequest(array $data) |
83
|
|
|
{ |
84
|
|
|
$messages = [ |
85
|
|
|
'required' => ':Attribute can\'t be blank', |
86
|
|
|
'password_confirmation.same' => 'Your passwords don\'t match' |
87
|
|
|
]; |
88
|
|
|
|
89
|
|
|
return Validator::make($data, [ |
90
|
|
|
'token' => 'required', |
91
|
|
|
'email' => 'required|email', |
92
|
|
|
'password' => 'required|min:6', |
93
|
|
|
'password_confirmation' => 'required|min:6|same:password' |
94
|
|
|
], $messages); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|