| Total Complexity | 6 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | class TokenRepository extends InitRepository |
||
| 16 | { |
||
| 17 | public function __construct() |
||
| 18 | { |
||
| 19 | parent::__construct(); |
||
| 20 | } |
||
| 21 | |||
| 22 | protected function getModelClass() |
||
| 25 | } |
||
| 26 | |||
| 27 | public function setToken($user_id) |
||
| 28 | { |
||
| 29 | $token = new Model(); |
||
| 30 | |||
| 31 | $ipAddress = new CaptureIpTrait(); |
||
| 32 | $agent = new Agent(); |
||
| 33 | |||
| 34 | $browser = $agent->browser(); |
||
| 35 | $platform = $agent->platform(); |
||
| 36 | |||
| 37 | $token->device = $agent->device(); |
||
| 38 | $token->browser = $browser.'('.$agent->version($browser).')'; |
||
|
|
|||
| 39 | $token->system = $platform.'('.$agent->version($platform).')'; |
||
| 40 | |||
| 41 | $token->user_id = $user_id; |
||
| 42 | $token->last_ip = $ipAddress->getClientIp(); |
||
| 43 | $unique_token = Str::random(60); |
||
| 44 | |||
| 45 | do { |
||
| 46 | $unique_token = Str::random(60); |
||
| 47 | } while (!empty(Model::where('api_token', $unique_token)->first())); |
||
| 48 | |||
| 49 | $token->api_token = $unique_token; |
||
| 50 | $token->login_at = Carbon::now(); |
||
| 51 | $token->save(); |
||
| 52 | |||
| 53 | return $token; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function clear_token($token) |
||
| 68 | } |
||
| 69 | } |
||
| 70 |