Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
LoginController
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 login
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
6
 logout
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Controllers\Api\user\authentication;
4
5use App\Http\Controllers\Controller;
6use App\Http\Requests\Api\user\loginRequest;
7use App\Http\Resources\userResource;
8use App\Traits\response;
9use Illuminate\Http\Request;
10use Illuminate\Support\Facades\Validator;
11use Tymon\JWTAuth\Exceptions\JWTException;
12use Illuminate\Support\Facades\Auth;
13
14class LoginController extends Controller
15{
16    public function login(loginRequest $request){
17        $credentials = ['username' => $request->username, 'password' => $request->password];
18        
19        if (! $token = auth('user_api')->attempt($credentials))
20            return $this->failed(trans('api.passwored or username is wrong'), 404, 'E04');
21
22        $response = [
23            'user'  => new userResource(auth('user_api')->user()),
24            'token' => $token,
25        ];
26
27        return $this->success(trans('api.success'),
28                200,
29                'data',
30                $response
31        );
32    }
33
34    public function logout(){
35        auth('user_api')->logout();
36
37        return response::success(trans('auth.success'));
38    }
39}