/** * Logs the current user out. * * @param \Cartalyst\Sentinel\Users\UserInterface $user * @param bool $everywhere * @return bool */ public function logout(UserInterface $user = null, $everywhere = false) { $user = $user ?: $this->getUser(); if ($user === null) { return true; } $method = $everywhere === true ? 'flush' : 'forget'; $this->persistences->{$method}($user); return $this->users->recordLogout($user); }
/** * Logs the current user out. * * @param \Cartalyst\Sentinel\Users\UserInterface $user * @param bool $everywhere * @return bool */ public function logout(UserInterface $user = null, $everywhere = false) { $currentUser = $this->check(); if ($user && $user !== $currentUser) { $this->persistences->flush($user, false); return true; } $user = $user ?: $currentUser; if ($user === false) { return true; } $method = $everywhere === true ? 'flush' : 'forget'; $this->persistences->{$method}($user); $this->user = null; return $this->users->recordLogout($user); }
/** * {@inheritDoc} */ public function complete(UserInterface $user, $code, $password) { $expires = $this->expires(); $reminder = $this->createModel()->newQuery()->where('user_id', $user->getUserId())->where('code', $code)->where('completed', false)->where('created_at', '>', $expires)->first(); if ($reminder === null) { return false; } $credentials = compact('password'); $valid = $this->users->validForUpdate($user, $credentials); if ($valid === false) { return false; } $this->users->update($user, $credentials); $reminder->fill(['completed' => true, 'completed_at' => Carbon::now()]); $reminder->save(); return true; }
/** * Processes the form. * * @param string $mode * @param int $id * @return \Illuminate\Http\RedirectResponse */ protected function processForm($mode, $id = null) { $rules = ['email' => 'required|unique:users', 'password' => 'sometimes|required', 'password_confirm' => 'required_with:password|same:password']; if ($id) { $user = $this->users->createModel()->find($id); $rules['email'] .= ",email,{$user->email},email"; $input = $this->prepareInput(Input::all(), $mode === 'update' ? true : false); $messages = $this->validateUser($input, $rules); if ($messages->isEmpty()) { try { // Update the user $this->users->update($user, array_except($input, 'roles')); // Get the new user roles $roles = array_get($input, 'roles', []); // Get the user roles $userRoles = $user->roles->lists('id'); // Prepare the roles to be added and removed $toAdd = array_diff($roles, $userRoles); $toDel = array_diff($userRoles, $roles); // Detach the user roles if (!empty($toDel)) { $user->roles()->detach($toDel); } // Attach the user roles if (!empty($toAdd)) { $user->roles()->attach($toAdd); } } catch (NotUniquePasswordException $e) { return Redirect::back()->withInput()->withErrors('This password was used before. You must choose a unique password.'); } } } else { $input = $this->prepareInput(Input::all(), true); $messages = $this->validateUser($input, $rules); if ($messages->isEmpty()) { $user = $this->users->create($input); $activation = Activation::create($user); Activation::complete($user, $activation->code); } } if ($messages->isEmpty()) { return Redirect::route('users.index')->withSuccess(trans("users/messages.success.{$mode}")); } return Redirect::back()->withInput()->withErrors($messages); }