/** * NStack hook. * * @author Casper Rasmussen <*****@*****.**> * @return \Illuminate\Http\RedirectResponse */ public function hook() { $this->guardUserPermissions(); // Retrieve NStack config $config = $this->getConfig(); $default = !empty($config['defaults']['application']) ? $config['defaults']['application'] : 'default'; $application = \Request::get('application', $default); $credentials = !empty($config['credentials'][$application]) ? $config['credentials'][$application] : $config['credentials']; // For backwards compatibility // Validate NStack credentials if (empty($config['url']) || empty($credentials['appId']) || empty($credentials['masterKey']) || empty($config['role'])) { return redirect()->back()->with('error', 'NStack hook is not configured, setup keys in (config/nodes/backend/nstack.php)'); } // Retrieve backend user $backendUser = backend_user(); // Create message $encryptedMessage = $this->encrypt(json_encode(['appId' => $credentials['appId'], 'masterKey' => $credentials['masterKey'], 'role' => $config['role'], 'accessToAllApps' => isset($config['accessToAllApps']) ? filter_var($config['accessToAllApps'], FILTER_VALIDATE_BOOLEAN) : true, 'url' => url('/'), 'user' => ['name' => $backendUser->name, 'email' => $backendUser->email]])); return redirect()->away($config['url'] . '?message=' . urlencode($encryptedMessage)); }
/** * 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'); } }
/** * Redirect user upon successful authentication. * * @author Casper Rasmussen <*****@*****.**> * * @param \Nodes\Backend\Support\FlashRestorer $flashAlert * @param string|null $urlToRedirectToAfterUserLogin * @return \Illuminate\Http\RedirectResponse */ protected function redirectSuccess($flashAlert = null, $urlToRedirectToAfterUserLogin = null) { // Retrieve authenticated backend user $backendUser = backend_user(); // If backend user is required to change his/her password // we'll redirect the user to the "change password" form // // Otherwise we'll redirect the user to the designated route // based on the route alias from the backend config file if ($backendUser->change_password) { $redirectResponse = redirect()->route('nodes.backend.users.change-password')->with('info', 'Please update your password'); } else { if ($urlToRedirectToAfterUserLogin) { // redirect to previously visited page if available $redirectResponse = redirect()->to($urlToRedirectToAfterUserLogin)->with('success', 'Logged in as: ' . $backendUser->email); } else { // redirect to success route from config $route = config('nodes.backend.auth.routes.success'); $redirectResponse = !empty($route) ? redirect()->route($route)->with('success', 'Logged in as: ' . $backendUser->email) : redirect()->to('/admin'); } } // Apply flash messages from previous route, if they are passed if ($flashAlert && $flashAlert instanceof FlashRestorer) { $flashAlert->apply($redirectResponse); } return $redirectResponse; }