示例#1
0
 /**
  * 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();
 }
示例#2
0
 /**
  * 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')));
 }
示例#3
0
 /**
  * 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);
 }
示例#4
0
 /**
  * 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')));
 }
示例#5
0
 /**
  * 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));
 }
示例#7
0
 /**
  * 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);
     }
 }
示例#8
0
 /**
  * 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);
 }
示例#10
0
 /**
  * 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);
 }
示例#11
0
 /**
  * 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());
     }
 }
示例#12
0
 /**
  * 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());
 }
示例#13
0
 /**
  * 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());
 }
示例#14
0
 /**
  * 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;
 }
示例#16
0
 /**
  * Regenerates the users API key.
  *
  * @return \Illuminate\View\View
  */
 public function regenerateApiKey(User $user)
 {
     $user->api_key = User::generateApiKey();
     $user->save();
     return Redirect::back();
 }
示例#17
0
 /**
  * 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;
 }
示例#19
0
 /**
  * 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);
     }
 }
示例#20
0
 /**
  * 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');
 }