We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
15 | class AuthenticateController extends Controller |
||
16 | { |
||
17 | /** |
||
18 | * Authenticate the user |
||
19 | * |
||
20 | * @param Request $request |
||
21 | * @return \Illuminate\Http\JsonResponse |
||
22 | */ |
||
23 | 2 | public function authenticate(Request $request) |
|
24 | { |
||
25 | |||
26 | try { |
||
27 | |||
28 | // grab credentials from the request |
||
29 | // attempt to verify the credentials and create a token for the user |
||
30 | 2 | if (!$token = JWTAuth::attempt( |
|
31 | 2 | $request->only('email', 'password'), [ |
|
32 | 2 | 'exp' => Carbon::now()->addWeek()->timestamp, |
|
33 | ] |
||
34 | ) |
||
35 | ) { |
||
36 | 1 | return response()->json([ 'error' => 'invalid_credentials' ], 401); |
|
37 | } |
||
38 | } catch (JWTException $e) { |
||
39 | // something went wrong whilst attempting to encode the token |
||
40 | return response()->json([ 'error' => 'could_not_create_token' ], 500); |
||
41 | } |
||
42 | |||
43 | // all good so return the token |
||
44 | 1 | return response()->json( |
|
45 | [ |
||
46 | 1 | 'access_token' => $token, |
|
47 | 1 | 'token_type' => 'Bearer' |
|
48 | 1 | ], 200 |
|
49 | ); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Register a new User |
||
54 | * |
||
55 | * @param RegisterUserRequest $request |
||
56 | * @return \Illuminate\Http\JsonResponse |
||
57 | */ |
||
58 | 1 | public function register(RegisterUserRequest $request) |
|
59 | { |
||
60 | 1 | $user = User::create( |
|
61 | [ |
||
62 | 1 | 'first_name' => $request->first_name, |
|
|
|||
63 | 1 | 'last_name' => $request->last_name, |
|
64 | 1 | 'email' => $request->email, |
|
65 | 1 | 'username' => $request->username, |
|
66 | 1 | 'phone' => $request->phone, |
|
67 | 1 | 'country_code' => $request->country_code, |
|
68 | 1 | 'bio' => $request->bio, |
|
69 | 1 | 'blood_type_id' => $request->blood_type_id, |
|
70 | 1 | 'birthdate' => $request->birthdate, |
|
71 | 1 | 'password' => bcrypt($request->password), |
|
72 | ] |
||
73 | ); |
||
74 | |||
75 | // Send mail to user |
||
76 | 1 | Mail::to($user->email)->send(new UserCreated($user)); |
|
77 | |||
78 | |||
79 | |||
80 | 1 | $token = JWTAuth::attempt($request->only('email', 'password')); |
|
81 | |||
82 | // all good so return the token |
||
83 | 1 | return response()->json( |
|
84 | [ |
||
85 | 1 | 'access_token' => $token, |
|
86 | 1 | 'token_type' => 'Bearer' |
|
87 | 1 | ], 201 |
|
88 | ); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Invalidate and log out the user |
||
93 | * |
||
94 | * @return void |
||
95 | */ |
||
96 | public function logout() |
||
100 | |||
101 | } |
||
102 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.