コード例 #1
0
ファイル: AuthController.php プロジェクト: nodes-php/backend
 /**
  * Authenticate Nodes Manager.
  *
  * @author Casper Rasmussen <*****@*****.**>
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function manager()
 {
     // Check for disabled feature
     if (!config('nodes.backend.manager.active', true)) {
         return redirect()->route('nodes.backend.login.form')->with('error', 'Manager auth is disabled.');
     }
     // Check the passed token vs a hash of email, constant and server token for current build
     if (hash('sha256', sprintf(env('NODES_MANAGER_SALT'), Request::get('email'), env('NODES_MANAGER_TOKEN'))) != Request::get('token')) {
         return redirect()->route('nodes.backend.login.form')->with('error', 'Manager token did not match');
     }
     try {
         // Retrieve the Nodes user
         $user = $this->userRepository->loginUserFromManager(Request::all());
         // Authenticate user
         backend_user_login($user);
         // Redirect into backend
         return $this->redirectSuccess(Cookie::get('url_to_redirect_to_after_user_login'));
     } catch (Exception $e) {
         try {
             // Notify bugsnag
             app('nodes.bugsnag')->notifyException($e, null, 'error');
         } catch (Exception $e) {
             // Fail silent
         }
         // Redirect to login form
         return redirect()->route('nodes.backend.login.form')->with('error', 'Failed to login through manager');
     }
 }
コード例 #2
0
ファイル: UsersController.php プロジェクト: nodes-php/backend
 /**
  * Update user's password.
  *
  * @author Casper Rasmussen <*****@*****.**>
  *
  * @param  \Nodes\Backend\Models\User\Validation\UserValidator $userValidator
  * @return \Illuminate\Http\RedirectResponse
  */
 public function updatePassword(UserValidator $userValidator)
 {
     // Retrieve posted data
     $data = Request::all();
     // Retrieve user to update
     $user = $this->userRepository->getById($data['id']);
     if (empty($user) || $user->id != backend_user()->id) {
         return redirect()->route('nodes.backend.users')->with('error', 'User was not found');
     }
     // Validate user
     if (!$userValidator->with($data)->group('update-password')->validate()) {
         return redirect()->back()->withInput()->with(['error' => $userValidator->errorsBag()]);
     }
     try {
         // Update user's password
         $this->userRepository->updateUser($user, array_merge($data, ['change_password' => false]));
         return redirect()->route('nodes.backend.dashboard')->with('success', 'Password is updated');
     } catch (Exception $e) {
         return redirect()->back()->withInput()->with('error', 'Could not update password');
     }
 }