/** * @param $token * * @return \Illuminate\Http\RedirectResponse */ public function confirmEmail($token) { $user = User::whereActivationToken($token)->firstOrFail(); $user->confirmEmail(); auth()->login($user); return redirect()->intended()->with('success', 'Email verified!'); }
/** * 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; }
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(); } } } }
/** * @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); }
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'); } }); }
public function getRelations() { $channelPublic = SlackChannelPublic::all(); $channelUsers = SlackChannelUser::all(); $channelRoles = SlackChannelRole::all(); $channelCorporations = SlackChannelCorporation::all(); $channelAlliances = SlackChannelAlliance::all(); $users = User::all(); $roles = Role::all(); $corporations = CorporationSheet::all(); $alliances = AllianceList::all(); $channels = SlackChannel::all(); return view('slackbot::list', compact('channelPublic', 'channelUsers', 'channelRoles', 'channelCorporations', 'channelAlliances', 'users', 'roles', 'corporations', 'alliances', 'channels')); }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->line('SeAT Admin Reset Tool'); $admin = User::firstOrNew(['name' => 'admin']); if (!$admin->exists) { $this->warn('User \'admin\' does not exist. It will be created.'); } $password = null; while (strlen($password) < 6) { $password = $this->secret('Please enter a min 6 character password for the \'admin\' user'); } $this->line('Setting password'); $admin->fill(['name' => 'admin', 'email' => '*****@*****.**', 'password' => bcrypt($password)])->save(); $this->line('Checking if \'admin\' is a super user'); if (!$admin->has('superuser')) { $this->line('Searching for the \'Superuser\' role'); $role = Role::where('title', 'Superuser')->first(); if (!$role) { $this->comment('Creating the Superuser role'); $role = Role::create(['title' => 'Superuser']); } $this->line('Checking if the Superuser role has the superuser permission'); $role_permissions = $this->getCompleteRole($role->id)->permissions; if (!$role_permissions->contains('superuser')) { $this->comment('Adding the superuser permission to the role'); $this->giveRolePermission($role->id, 'superuser', false); } $this->comment('Adding \'admin\' to the Superuser role'); $this->giveUserRole($admin->id, $role->id); } $this->line('Ensuring the \'admin\' user is enabled.'); if (!$admin->active) { $admin->active = true; $admin->save(); } // Analytics $this->dispatch((new Analytics((new AnalyticsContainer())->set('type', 'event')->set('ec', 'admin')->set('ea', 'password_reset')->set('el', 'console')))->onQueue('medium')); $this->info('Done'); }
public function testUser() { $slack = SlackUser::where('user_id', '=', 3)->first(); $artifact = User::find(3); $this->assertEquals($artifact, $slack->user); }
/** * @param \Illuminate\Http\Request $request * @param $key_id * * @return \Illuminate\Http\RedirectResponse */ public function transfer(Request $request, $key_id) { $key = ApiKeyModel::findOrFail($key_id); $user = User::findOrFail($request->user_id); $key->user_id = $user->id; $key->save(); return redirect()->back()->with('success', 'Key successfully transferred to ' . $user->name); }
/** * 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; }
/** * Create a new user instance after a valid registration. * * @param array $data * * @return User */ protected function create(array $data) { return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); }
/** * @param \Seat\Web\Http\Validation\NewUser $request * * @return mixed */ public function addUser(NewUser $request) { User::create(['name' => $request->input('username'), 'email' => $request->input('email'), 'password' => bcrypt($request->input('password')), 'active' => true]); return redirect()->back()->with('success', trans('web::seat.user_created')); }
/** * @param $user_id * * @return mixed */ public function getUser($user_id) { return UserModel::findOrFail($user_id); }
public function testUser() { $permission = SlackChannelUser::where('user_id', '=', 1)->first(); $artifact = User::find(1); $this->assertEquals($artifact, $permission->user); }
/** * Transfer an EVE API Key to a User * * @param $key_id * @param $user_id * * @return \Illuminate\Http\JsonResponse */ public function transfer($key_id, $user_id) { $key = ApiKey::findOrFail($key_id); User::findOrFail($user_id); $key->user_id = $user_id; $key->save(); return response()->json(['ok']); }
/** * @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')); }
/** * 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']); }
/** * Give a user a Role * * @param int $user_id * @param int $role_id */ public function giveUserRole(int $user_id, int $role_id) { $user = UserModel::find($user_id); $role = RoleModel::firstOrNew(['id' => $role_id]); // If the role does not already have the user // add it. if (!$role->users->contains($user->id)) { $role->users()->save($user); } return; }
/** * Determine all channels in which an user is allowed to be * * @param SlackUser $slackUser * @param boolean $private Determine if channels should be private (group) or public (channel) * @return array */ protected function allowedChannels(SlackUser $slackUser, $private) { $channels = []; $rows = User::join('slack_channel_users', 'slack_channel_users.user_id', '=', 'users.id')->join('slack_channels', 'slack_channel_users.channel_id', '=', 'slack_channels.id')->select('channel_id')->where('users.id', $slackUser->user_id)->where('slack_channels.is_group', (int) $private)->where('slack_channels.is_general', (int) false)->union(DB::table('role_user')->join('slack_channel_roles', 'slack_channel_roles.role_id', '=', 'role_user.role_id')->join('slack_channels', 'slack_channel_roles.channel_id', '=', 'slack_channels.id')->where('role_user.user_id', $slackUser->user_id)->where('slack_channels.is_group', (int) $private)->where('slack_channels.is_general', (int) false)->select('channel_id'))->union(ApiKey::join('account_api_key_info_characters', 'account_api_key_info_characters.keyID', '=', 'eve_api_keys.key_id')->join('slack_channel_corporations', 'slack_channel_corporations.corporation_id', '=', 'account_api_key_info_characters.corporationID')->join('slack_channels', 'slack_channel_corporations.channel_id', '=', 'slack_channels.id')->where('eve_api_keys.user_id', $slackUser->user_id)->where('slack_channels.is_group', (int) $private)->where('slack_channels.is_general', (int) false)->select('channel_id'))->union(CharacterSheet::join('slack_channel_alliances', 'slack_channel_alliances.alliance_id', '=', 'character_character_sheets.allianceID')->join('slack_channels', 'slack_channel_alliances.channel_id', '=', 'slack_channels.id')->join('account_api_key_info_characters', 'account_api_key_info_characters.characterID', '=', 'character_character_sheets.characterID')->join('eve_api_keys', 'eve_api_keys.key_id', '=', 'account_api_key_info_characters.keyID')->where('eve_api_keys.user_id', $slackUser->user_id)->where('slack_channels.is_group', (int) $private)->where('slack_channels.is_general', (int) false)->select('channel_id'))->union(SlackChannelPublic::join('slack_channels', 'slack_channel_public.channel_id', '=', 'slack_channels.id')->where('slack_channels.is_group', (int) $private)->where('slack_channels.is_general', (int) false)->select('channel_id'))->get(); foreach ($rows as $row) { $channels[] = $row->channel_id; } return $channels; }