|
|
@ -28,26 +28,32 @@ class AuthController extends Controller |
|
|
|
$password = $request->password; |
|
|
|
$password = $request->password; |
|
|
|
$remember = $request->remember; |
|
|
|
$remember = $request->remember; |
|
|
|
$is_mobile = $request->is_mobile; |
|
|
|
$is_mobile = $request->is_mobile; |
|
|
|
|
|
|
|
$usernameCheck = false; |
|
|
|
if (empty($username) || empty($password)) |
|
|
|
|
|
|
|
return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$usernameCheck = false; |
|
|
|
|
|
|
|
$passwordCheck = false; |
|
|
|
$passwordCheck = false; |
|
|
|
|
|
|
|
|
|
|
|
if (User::where('username', $username)->exists()) |
|
|
|
if (empty($username) || empty($password)) { |
|
|
|
$usernameCheck = true; |
|
|
|
return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (User::where('password', md5($password))->exists()) |
|
|
|
if (User::where('username', $username)->exists()) { |
|
|
|
$passwordCheck = true; |
|
|
|
$usernameCheck = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (User::where('password', md5($password))->exists()) { |
|
|
|
|
|
|
|
$passwordCheck = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($usernameCheck & $passwordCheck) { |
|
|
|
if ($usernameCheck & $passwordCheck) { |
|
|
|
$user = User::where('username', $username)->where('password', md5($password))->first(); |
|
|
|
$user = User::where([['username', $username],['password', md5($password)]])->first(); |
|
|
|
|
|
|
|
$checkExpiredOspro = $this->setExpiredTimeOspro($user['company_id']); |
|
|
|
|
|
|
|
if($checkExpiredOspro === false) { |
|
|
|
|
|
|
|
return response()->json(['status' => 'error', 'message' => 'Expired! Please update license!'], 201); |
|
|
|
|
|
|
|
} |
|
|
|
if ($is_mobile) { |
|
|
|
if ($is_mobile) { |
|
|
|
$fcm_token = $request->fcm_token; |
|
|
|
$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); |
|
|
|
return response()->json(['status' => 'error', 'message' => 'FCM Token is required'], 400); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$dataUpdateFcm = array( |
|
|
|
$dataUpdateFcm = array( |
|
|
|
"fcm_token" => $fcm_token |
|
|
|
"fcm_token" => $fcm_token |
|
|
@ -55,8 +61,9 @@ class AuthController extends Controller |
|
|
|
|
|
|
|
|
|
|
|
$hr = User::find($user->id); |
|
|
|
$hr = User::find($user->id); |
|
|
|
|
|
|
|
|
|
|
|
if ($hr) |
|
|
|
if ($hr) { |
|
|
|
$hr->update($dataUpdateFcm); |
|
|
|
$hr->update($dataUpdateFcm); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$dataRole = Role::find($user->role_id); |
|
|
|
$dataRole = Role::find($user->role_id); |
|
|
@ -71,21 +78,26 @@ class AuthController extends Controller |
|
|
|
$configApp->logo_header = $logoHeader; |
|
|
|
$configApp->logo_header = $logoHeader; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($configApp) |
|
|
|
if ($configApp) { |
|
|
|
$user->configApp = $configApp; |
|
|
|
$user->configApp = $configApp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($dataRole) |
|
|
|
if ($dataRole) { |
|
|
|
$user->role = $dataRole; |
|
|
|
$user->role = $dataRole; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($dataHierarchy) |
|
|
|
if ($dataHierarchy) { |
|
|
|
$user->hierarchy = $dataHierarchy; |
|
|
|
$user->hierarchy = $dataHierarchy; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!$token = Auth::login($user)) |
|
|
|
if (!$token = Auth::login($user)) { |
|
|
|
return response()->json(['error' => 'Unauthorized'], 401); |
|
|
|
return response()->json(['error' => 'Unauthorized'], 401); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$ttl = 60; |
|
|
|
$ttl = 60; |
|
|
|
if ($remember) |
|
|
|
if ($remember) { |
|
|
|
$ttl = 10080; |
|
|
|
$ttl = 10080; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// todo : change existing md5 hashed function to laravel's originally bcrypt |
|
|
|
// todo : change existing md5 hashed function to laravel's originally bcrypt |
|
|
|
/* $token = auth()->setTTL($ttl)->attempt(['username' => $username, 'password' => Hash::make($password)]); */ |
|
|
|
/* $token = auth()->setTTL($ttl)->attempt(['username' => $username, 'password' => Hash::make($password)]); */ |
|
|
@ -101,12 +113,15 @@ class AuthController extends Controller |
|
|
|
), |
|
|
|
), |
|
|
|
]); |
|
|
|
]); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (!$usernameCheck && !$passwordCheck) |
|
|
|
if (!$usernameCheck && !$passwordCheck) { |
|
|
|
return response()->json(['code' => 201, 'message' => "username and password doesn't match"], 201); |
|
|
|
return response()->json(['code' => 201, 'message' => "Username and password doesn't match"], 201); |
|
|
|
if (!$passwordCheck) |
|
|
|
} |
|
|
|
return response()->json(['code' => 201, 'message' => "password doesn't match"], 201); |
|
|
|
if (!$passwordCheck) { |
|
|
|
if (!$usernameCheck) |
|
|
|
return response()->json(['code' => 201, 'message' => "Password doesn't match"], 201); |
|
|
|
return response()->json(['code' => 201, 'message' => "username doesn't match"], 201); |
|
|
|
} |
|
|
|
|
|
|
|
if (!$usernameCheck) { |
|
|
|
|
|
|
|
return response()->json(['code' => 201, 'message' => "Username doesn't match"], 201); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|