Browse Source

implement remember me

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
dbc5421318
  1. 11
      app/Http/Controllers/AuthController.php

11
app/Http/Controllers/AuthController.php

@ -19,6 +19,7 @@ class AuthController extends Controller
{ {
$username = $request->username; $username = $request->username;
$password = $request->password; $password = $request->password;
$remember = $request->remember;
$is_mobile = $request->is_mobile; $is_mobile = $request->is_mobile;
if(empty($username) || empty($password)){ if(empty($username) || empty($password)){
@ -46,6 +47,7 @@ class AuthController extends Controller
} }
} }
$dataRole = Role::find($user->role_id); $dataRole = Role::find($user->role_id);
if($dataRole){ if($dataRole){
@ -57,18 +59,21 @@ class AuthController extends Controller
return response()->json(['error' => 'Unauthorized'], 401); return response()->json(['error' => 'Unauthorized'], 401);
} }
return $this->respondWithToken($token, $user); return $this->respondWithToken($token, $user, $remember);
} }
protected function respondWithToken($token, $user) protected function respondWithToken($token, $user, $remember)
{ {
$ttl = 60;
if($remember)
$ttl = 10080;
return response()->json([ return response()->json([
'code' => 200, 'code' => 200,
'data' => array( 'data' => array(
'data_user' => $user, 'data_user' => $user,
'access_token' => $token, 'access_token' => $token,
'token_type' => 'bearer', 'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 360 'expires_in' => auth()->factory()->getTTL() * $ttl,
), ),
]); ]);
} }

Loading…
Cancel
Save