/** * Regenerates the users API key. * * @return \Illuminate\View\View */ public function regenerateApiKey(User $user) { segment_track('User Management', ['event' => 'regenrated_api_token']); $user->api_key = User::generateApiKey(); $user->save(); return Redirect::back(); }
/** * Updates a user. * * @param \CachetHQ\Cachet\Models\User $user * * @return \Illuminate\View\View */ public function postUpdateUser(User $user) { $userData = array_filter(Binput::only(['username', 'email', 'password', 'level'])); try { $user->update($userData); } catch (ValidationException $e) { return Redirect::route('dashboard.team.edit', ['id' => $user->id])->withInput($userData)->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.team.edit', ['id' => $user->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success'))); }
/** * Updates a user. * * @param \CachetHQ\Cachet\Models\User $user * * @return \Illuminate\View\View */ public function postUpdateUser(User $user) { $items = Binput::all(); $passwordChange = array_get($items, 'password'); if (trim($passwordChange) === '') { unset($items['password']); } $user->update($items); if (!$user->isValid()) { return Redirect::back()->withInput(Binput::except('password'))->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))->with('errors', $user->getErrors()); } $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')); return Redirect::back()->with('success', $successMsg); }
/** * Updates a user. * * @param \CachetHQ\Cachet\Models\User $user * * @return \Illuminate\View\View */ public function postUpdateUser(User $user) { $items = Binput::all(); $passwordChange = array_get($items, 'password'); if (trim($passwordChange) === '') { unset($items['password']); } try { $user->update($items); } catch (ValidationException $e) { return Redirect::back()->withInput(Binput::except('password'))->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::back()->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success'))); }
/** * Shows the settings security view. * * @return \Illuminate\View\View */ public function showSecurityView() { $this->subMenu['security']['active'] = true; $unsecureUsers = User::whereNull('google_2fa_secret')->orWhere('google_2fa_secret', '')->get(); Session::flash('redirect_to', $this->subMenu['security']['url']); return View::make('dashboard.settings.security')->withPageTitle('Security - Dashboard')->withSubMenu($this->subMenu)->withUnsecureUsers($unsecureUsers); }
/** * Handle the generate api key command. * * @param \CachetHQ\Cachet\Bus\Commands\User\GenerateApiTokenCommand $command * * @return void */ public function handle(GenerateApiTokenCommand $command) { $user = $command->user; $user->api_key = User::generateApiKey(); $user->save(); //event(new GeneratedApiTokenEvent($user)); }
/** * Run the database seeding. */ public function run() { $users = [['username' => 'test', 'password' => 'test123', 'email' => '*****@*****.**', 'level' => 1, 'api_key' => '9yMHsdioQosnyVK4iCVR']]; User::truncate(); foreach ($users as $user) { User::create($user); } }
/** * Run the database seeding. * * @return void */ public function run() { Model::unguard(); $users = [["username" => "admin", "password" => "admin", "email" => "*****@*****.**", "level" => "1"], ["username" => "user", "password" => "user", "email" => "*****@*****.**"]]; foreach ($users as $user) { User::create($user); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { if ($this->auth->guest()) { if ($apiToken = $request->header('X-Cachet-Token')) { try { $this->auth->onceUsingId(User::findByApiToken($apiToken)->id); } catch (ModelNotFoundException $e) { // } } } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param bool $required * * @return mixed */ public function handle($request, Closure $next, $required = false) { if ($this->auth->guest()) { if ($apiToken = $request->header('X-Cachet-Token')) { try { $this->auth->onceUsingId(User::findByApiToken($apiToken)->id); } catch (ModelNotFoundException $e) { if ($required) { throw new HttpException(401); } } } elseif ($required) { throw new HttpException(401); } } return $next($request); }
/** * Handles the actual app setup. * * @return \Illuminate\Http\RedirectResponse */ public function postIndex() { $postData = Binput::all(); $v = Validator::make($postData, ['settings.app_name' => 'required', 'settings.app_domain' => 'required', 'settings.show_support' => 'boolean', 'user.username' => 'alpha_dash|required', 'user.email' => 'email|required', 'user.password' => 'required']); if ($v->passes()) { // Pull the user details out. $userDetails = array_pull($postData, 'user'); // TODO: Do we want to just use Model::unguard() here? $user = User::create(['username' => $userDetails['username'], 'email' => $userDetails['email'], 'password' => $userDetails['password'], 'level' => 1]); Auth::login($user); $settings = array_get($postData, 'settings'); foreach ($settings as $settingName => $settingValue) { Setting::create(['name' => $settingName, 'value' => $settingValue]); } return Redirect::to('dashboard'); } else { // No good, let's try that again. return Redirect::back()->withInput()->with('errors', $v->messages()); } }
/** * Handles the actual app setup, including user, settings and env. * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response */ public function postStep3() { $postData = Binput::all(); $v = Validator::make($postData, ['env.cache_driver' => 'required|in:' . implode(',', array_keys($this->cacheDrivers)), 'env.session_driver' => 'required|in:' . implode(',', array_keys($this->cacheDrivers)), 'settings.app_name' => 'required', 'settings.app_domain' => 'required', 'settings.app_timezone' => 'required', 'settings.app_locale' => 'required', 'settings.show_support' => 'boolean', 'user.username' => ['required', 'regex:/\\A(?!.*[:;]-\\))[ -~]+\\z/'], 'user.email' => 'email|required', 'user.password' => 'required']); if ($v->passes()) { // Pull the user details out. $userDetails = array_pull($postData, 'user'); $user = User::create(['username' => $userDetails['username'], 'email' => $userDetails['email'], 'password' => $userDetails['password'], 'level' => 1]); Auth::login($user); $settings = array_pull($postData, 'settings'); foreach ($settings as $settingName => $settingValue) { Setting::create(['name' => $settingName, 'value' => $settingValue]); } $envData = array_pull($postData, 'env'); // Write the env to the .env file. foreach ($envData as $envKey => $envValue) { $this->writeEnv($envKey, $envValue); } Session::flash('setup.done', true); if (Request::ajax()) { return Response::json(['status' => 1]); } return Redirect::to('dashboard'); } if (Request::ajax()) { return Response::json(['errors' => $v->getMessageBag()], 400); } return Redirect::back()->withInput()->withErrors($v->getMessageBag()); }
/** * Handles the actual app setup, including user, settings and env. * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response */ public function postStep3() { $postData = Binput::all(); $v = Validator::make($postData, $this->rulesStep1 + $this->rulesStep2 + $this->rulesStep3); if ($v->passes()) { // Pull the user details out. $userDetails = array_pull($postData, 'user'); $user = User::create(['username' => $userDetails['username'], 'email' => $userDetails['email'], 'password' => $userDetails['password'], 'level' => User::LEVEL_ADMIN]); Auth::login($user); $setting = app('setting'); $settings = array_pull($postData, 'settings'); foreach ($settings as $settingName => $settingValue) { $setting->set($settingName, $settingValue); } $envData = array_pull($postData, 'env'); // Write the env to the .env file. foreach ($envData as $envKey => $envValue) { $this->writeEnv($envKey, $envValue); } Session::flash('setup.done', true); if (Request::ajax()) { return Response::json(['status' => 1]); } return Redirect::to('dashboard'); } if (Request::ajax()) { return Response::json(['errors' => $v->getMessageBag()], 400); } return Redirect::route('setup.index')->withInput()->withErrors($v->getMessageBag()); }
/** * Shows the settings security view. * * @return \Illuminate\View\View */ public function showSecurityView() { $this->subMenu['security']['active'] = true; $unsecureUsers = User::whereNull('google_2fa_secret')->orWhere('google_2fa_secret', '')->get(); return View::make('dashboard.settings.security')->with(['page_title' => 'Security - Dashboard', 'sub_menu' => $this->subMenu, 'unsecureUsers' => $unsecureUsers]); }
/** * Handle the add team member command. * * @param \CachetHQ\Cachet\Commands\User\AddTeamMemberCommand $command * * @return \CachetHQ\Cachet\Models\User */ public function handle(AddTeamMemberCommand $command) { $user = User::create(['username' => $command->username, 'password' => $command->password, 'email' => $command->email, 'level' => $command->level]); event(new UserWasAddedEvent($user)); return $user; }
/** * Regenerates the users API key. * * @return \Illuminate\View\View */ public function regenerateApiKey(User $user) { $user->api_key = User::generateApiKey(); $user->save(); return Redirect::back(); }
/** * Delete a user. * * @param \CachetHQ\Cachet\Models\User $user * * @return \Illuminate\Http\RedirectResponse */ public function deleteUser(User $user) { $user->delete(); return Redirect::route('dashboard.team')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.delete.success'))); }
/** * Handle the signup user command. * * @param \CachetHQ\Cachet\Bus\Commands\User\SignupUserCommand $command * * @return \CachetHQ\Cachet\Models\User */ public function handle(SignupUserCommand $command) { $user = User::create(['username' => $command->username, 'password' => $command->password, 'email' => $command->email, 'level' => User::LEVEL_USER]); event(new UserWasAddedEvent($user)); return $user; }
/** * Seed the users table. * * @return void */ protected function seedUsers() { $users = [['username' => 'test', 'password' => 'test123', 'email' => '*****@*****.**', 'level' => User::LEVEL_ADMIN, 'api_key' => '9yMHsdioQosnyVK4iCVR']]; User::truncate(); foreach ($users as $user) { User::create($user); } }
/** * Regenerates the users API key. * * @param \CachetHQ\Cachet\Models\User $user * * @return \Illuminate\View\View */ public function regenerateApiKey(User $user) { $user->api_key = User::generateApiKey(); $user->save(); return Redirect::route('dashboard.user'); }