Exemplo n.º 1
0
 /**
  * Handles authenticating that a user/character is still valid.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function postAuthorized()
 {
     // Get the neccessary headers from the request.
     $service = $this->request->header('service', false);
     $username = $this->request->header('username', '');
     $character = $this->request->header('character', '');
     $this->log->info('A service is attempting to validate a user.', ['username' => $username, 'character' => $character, 'service' => $service]);
     // Verify that the external service exists in the configuration.
     if (!$service || !$this->config->get("addon.auth.{$service}")) {
         $this->log->info(self::ERROR_INVALID_EXTERNAL_SERVICE, ['service' => $service]);
         return $this->failure(self::ERRNO_INVALID_EXTERNAL_SERVICE, self::ERROR_INVALID_EXTERNAL_SERVICE);
     }
     // Check the cache first so the api isn't hammered too badly.
     $key = 'auth:session:' . sha1("{$service}:{$username}");
     if ($this->cache->has($key)) {
         $this->log->info('Returning the cached authorization result.');
         return $this->cache->get($key);
     }
     // Attempt to find the requested user.
     $identifier = filter_var($username, FILTER_VALIDATE_EMAIL) ? 'email' : 'name';
     $user = $this->users->where($identifier, $username)->first() ?: false;
     if (!$user) {
         $this->log->info(self::ERROR_USER_NOT_FOUND);
         return $this->failure(self::ERRNO_USER_NOT_FOUND, self::ERROR_USER_NOT_FOUND);
     }
     // Get and cache the response for 15 minutes.
     $response = $this->getLoginResult($user, $service, $character);
     $this->cache->put($key, $response, $this->carbon->now()->addMinutes(15));
     return $response;
 }
Exemplo n.º 2
0
 public function handle()
 {
     $token = Seat::get('slack_token');
     if ($token == null) {
         throw new SlackSettingException("missing slack_token in settings");
     }
     // get members list from slack team
     $api = new SlackApi($token);
     $members = $api->members();
     // iterate over each member, check if the user mail match with a seat account and update the relation table
     foreach ($members as $m) {
         if ($m['id'] != 'USLACKBOT' && $m['deleted'] == false && $m['is_bot'] == false && !key_exists('api_app_id', $m['profile'])) {
             $user = User::where('email', '=', $m['profile']['email'])->first();
             if ($user != null) {
                 $slackUser = SlackUser::find($user->id);
                 if ($slackUser == null) {
                     $slackUser = new SlackUser();
                     $slackUser->user_id = $user->id;
                     $slackUser->invited = true;
                 }
                 $slackUser->slack_id = $m['id'];
                 $slackUser->save();
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @param $user_identifier
  * @param $permission_identifier
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function getPermissionCheck($user_identifier, $permission_identifier)
 {
     $user = User::where(is_numeric($user_identifier) ? 'id' : 'name', $user_identifier)->first();
     if (!$user) {
         abort(404);
     }
     $access = $user->has($permission_identifier, false);
     return response()->json($access);
 }
Exemplo n.º 4
0
 public function handle(JobContainer $job)
 {
     User::where('active', true)->chunk(10, function ($users) use($job) {
         foreach ($users as $user) {
             $job->api = 'Slack';
             $job->scope = 'Update';
             $job->owner_id = $user->id;
             $job->user = $user;
             $jobId = $this->addUniqueJob(SlackUpdater::class, $job);
             $this->info('Job ' . $jobId . ' dispatched');
         }
     });
 }
Exemplo n.º 5
0
 /**
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postSsoConfirmation()
 {
     // Confirm the User credentials.
     if (auth()->attempt(['name' => session()->get('eve_sso')->name, 'password' => request()->input('password')])) {
         // Change to SeAT account to a SSO account.
         $user = User::where('name', session()->get('eve_sso')->name)->first();
         $user->update(['eve_id' => session()->get('eve_sso')->eve_id, 'token' => session()->get('eve_sso')->token, 'password' => bcrypt(str_random(128))]);
         // Authenticate the user.
         if (auth()->check() == false) {
             auth()->login($user, true);
         }
         // Set the main characterID based on the response.
         $this->setCharacterId(session()->get('eve_sso'));
         // Remove the SSO data from the session
         session()->forget('eve_sso');
         return redirect()->intended();
     }
     return redirect()->back()->with('error', trans('web::seat.failed'));
 }
Exemplo n.º 6
0
 /**
  * Give an array of usernames a role
  *
  * @param array $user_names
  * @param       $role_id
  */
 public function giveUsernamesRole(array $user_names, $role_id)
 {
     foreach ($user_names as $user_name) {
         $user = UserModel::where('name', $user_name)->first();
         $this->giveUserRole($user->id, $role_id);
     }
     return;
 }
Exemplo n.º 7
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     // Allow for both an id, or a name as an identifier
     User::where(is_numeric($id) ? 'id' : 'name', $id)->delete();
     return response()->json(['ok']);
 }