Exemplo n.º 1
0
 /**
  * The "booting" method of the model.
  *
  * @return void
  */
 protected static function bootRoleable()
 {
     User::creating(function ($user) {
         $user->attributes = array_merge(['role_id' => self::ROLE_USER], $user->attributes);
     });
 }
Exemplo n.º 2
0
 /**
  * Device Authentication login.
  *
  * @param  DeviceLoginUserRequest   $request
  *
  * @return Response
  *
  * @api               {post} /v1/auth/devicelogin User Login with device
  * @apiVersion        1.0.0
  * @apiName           AuthDeviceLogin
  * @apiGroup          Authentication
  *
  * @apiParam {String} id            The unique device identifier.
  *
  * @apiSuccess {String}   token      Authentication token.
  *
  * @apiUse ApiLimitError
  */
 public function deviceLogin(DeviceLoginUserRequest $request, LaravelFacebookSdk $fb)
 {
     $deviceId = $request->input('id');
     $user = User::firstOrCreate(['device_id' => $deviceId, 'facebook_user_id' => 0]);
     if ($user->name == '') {
         // First connection, we generate a name
         $guestCount = User::whereNotNull('device_id')->count();
         // We add 50 to start from 50 and avoid like Guest 1 or guest 15, it can be frustrating
         $guestCount += 50;
         $user->name = 'Guest ' . $guestCount;
         $user->save();
     }
     try {
         if (!($token = JWTAuth::fromUser($user))) {
             return $this->response->errorUnauthorized();
         }
     } catch (JWTException $e) {
         return $this->response->error('could_not_create_token', 500);
     }
     return response()->json(compact('token'));
 }