/** * A simple helper to insert an entry in the admin log * * @param $resource * @param $action * @param $message * @param Request $request * @param UserInterface $adminUser * @param bool $withRequestContent */ public static function append($resource, $action, $message, Request $request, UserInterface $adminUser = null, $withRequestContent = true) { $log = new AdminLog(); $log->setAdminLogin($adminUser !== null ? $adminUser->getUsername() : '<no login>')->setAdminFirstname($adminUser !== null && $adminUser instanceof Admin ? $adminUser->getFirstname() : '<no first name>')->setAdminLastname($adminUser !== null && $adminUser instanceof Admin ? $adminUser->getLastname() : '<no last name>')->setResource($resource)->setAction($action)->setMessage($message)->setRequest($request->toString($withRequestContent)); try { $log->save(); } catch (\Exception $ex) { Tlog::getInstance()->err("Failed to insert new entry in AdminLog: {ex}", array('ex' => $ex)); } }
public function checkLoginAction() { $request = $this->getRequest(); $adminLoginForm = new AdminLogin($request); try { $form = $this->validateForm($adminLoginForm, "post"); $authenticator = new AdminUsernamePasswordFormAuthenticator($request, $adminLoginForm); $user = $authenticator->getAuthentifiedUser(); // Success -> store user in security context $this->getSecurityContext()->setAdminUser($user); // Log authentication success AdminLog::append("admin", "LOGIN", "Authentication successful", $request, $user, false); $this->applyUserLocale($user); /** * we have tou find a way to send cookie */ if (intval($form->get('remember_me')->getData()) > 0) { // If a remember me field if present and set in the form, create // the cookie thant store "remember me" information $this->createRememberMeCookie($user, $this->getRememberMeCookieName(), $this->getRememberMeCookieExpiration()); } $this->dispatch(TheliaEvents::ADMIN_LOGIN); // Redirect to the success URL, passing the cookie if one exists. return $this->generateSuccessRedirect($adminLoginForm); } catch (FormValidationException $ex) { // Validation problem $message = $this->createStandardFormValidationErrorMessage($ex); } catch (AuthenticationException $ex) { // Log authentication failure AdminLog::append("admin", "LOGIN", sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request); $message = $this->getTranslator()->trans("Login failed. Please check your username and password."); } catch (\Exception $ex) { // Log authentication failure AdminLog::append("admin", "LOGIN", sprintf("Undefined error: %s", $ex->getMessage()), $request); $message = $this->getTranslator()->trans("Unable to process your request. Please try again (%err).", array("%err" => $ex->getMessage())); } $this->setupFormErrorContext("Login process", $message, $adminLoginForm, $ex); // Display the login form again return $this->render("login"); }
/** * @param $request * @param $session */ protected function getRememberMeAdmin(Request $request, Session $session) { // try to get the remember me cookie $cookieAdminName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn'); $cookie = $this->getRememberMeKeyFromCookie($request, $cookieAdminName); if (null !== $cookie) { // try to log $authenticator = new AdminTokenAuthenticator($cookie); try { // If have found a user, store it in the security context $user = $authenticator->getAuthentifiedUser(); $session->setAdminUser($user); $this->applyUserLocale($user, $session); AdminLog::append("admin", "LOGIN", "Authentication successful", $request, $user, false); } catch (TokenAuthenticationException $ex) { AdminLog::append("admin", "LOGIN", "Token based authentication failed.", $request); // Clear the cookie $this->clearRememberMeCookie($cookieAdminName); } } }
/** * Helper to append a message to the admin log. * * @param string $resource * @param string $action * @param string $message */ public function adminLogAppend($resource, $action, $message, $resourceId = null) { AdminLog::append($resource, $action, $message, $this->getRequest(), $this->getSecurityContext()->getAdminUser(), true, $resourceId); }
/** * Exclude object from result * * @param ChildAdminLog $adminLog Object to remove from the list of results * * @return ChildAdminLogQuery The current query, for fluid interface */ public function prune($adminLog = null) { if ($adminLog) { $this->addUsingAlias(AdminLogTableMap::ID, $adminLog->getId(), Criteria::NOT_EQUAL); } return $this; }