diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 8dabcfd..67ad016 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use Illuminate\Support\Facades\Auth; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Hash; use App\Models\User; use App\Models\Role; @@ -22,19 +23,16 @@ class AuthController extends Controller $remember = $request->remember; $is_mobile = $request->is_mobile; - if(empty($username) || empty($password)){ + if(empty($username) || empty($password)) return response()->json(['status'=>'error','message'=>'You must fill all the fields'], 400); - } $user = User::where('username', $username)->where('password', md5($password))->first(); if($is_mobile){ $fcm_token = $request->fcm_token; - if(!$fcm_token || $fcm_token==""){ + if(!$fcm_token || $fcm_token=="") return response()->json(['status'=>'error','message'=>'FCM Token is required'], 400); - die(); - } $dataUpdateFcm = array( "fcm_token"=>$fcm_token @@ -42,31 +40,26 @@ class AuthController extends Controller $hr = User::find($user->id); - if($hr){ + if($hr) $hr->update($dataUpdateFcm); - } } - $dataRole = Role::find($user->role_id); - if($dataRole){ + if($dataRole) $user->role = $dataRole; - } - - if (! $token =Auth::login($user)) { + if (! $token =Auth::login($user)) return response()->json(['error' => 'Unauthorized'], 401); - } - return $this->respondWithToken($token, $user, $remember); - } - - protected function respondWithToken($token, $user, $remember) - { $ttl = 60; if($remember) $ttl = 10080; + + // todo : change existing md5 hashed function to laravel's originally bcrypt + /* $token = auth()->setTTL($ttl)->attempt(['username' => $username, 'password' => Hash::make($password)]); */ + /* dd(response()->json(['code'=>'200', 'token' => $token, 'ttl' => $ttl])); */ + return response()->json([ 'code' => 200, 'data' => array(