Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function checkToken(Request $request){
- try {
- //code...
- $validator = Validator::make($request->all(), [
- 'token' => 'required',
- ]);
- if ($validator->fails()) {
- return $this->getResponse(406, $validator->errors()->first());
- }
- $token = Token::where('code', $request->token)->where('status', 1)->first();
- if (!$token) {
- return $this->getResponse(401, 'Token undefined');
- }
- $data = Crypt::decryptString($request->token);
- $data = json_decode($data);
- $diff = Carbon::createFromTimestamp($data->createdAt)->diffInHours(Carbon::now());
- if ($diff >= (int)env('TOKEN_DURATION_HOUR', '24')) {
- # code...
- return $this->getResponse(401, 'Token expired');
- }
- return $this->getResponse(200, false, $data);
- } catch (\Throwable $th) {
- //throw $th;
- return $this->getResponse(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement