/** * Register page action * POST-request after form submit */ public function postRegister() { $this->app->log->debug(get_class($this) . '->postRegister()'); // clean the input $user_email = strip_tags($this->app->request->post('user_email')); $user_name = null; // strip_tags($this->app->request->post('user_name')); if (!$user_name) { // Se non specificato, utilizzo l'indirizzo email come username $user_name = $user_email; } $user_email_repeat = NULL; // potrei usare strip_tags($this->app->request->post('user_email_repeat')); $user_password_new = $this->app->request->post('user_password_new'); $user_password_repeat = $this->app->request->post('user_password_repeat'); $captcha = $this->app->request->post('g-recaptcha-response'); $redirect = ltrim(urldecode($this->app->request->post('redirect'))); $registration_successful = RegistrationModel::registerNewUser($user_name, $user_email, $user_email_repeat, $user_password_new, $user_password_repeat, $captcha, UserModel::PROVIDER_TYPE_DEFAULT); if ($registration_successful) { $login_successful = LoginModel::login($user_name, $user_password_new, true, UserModel::PROVIDER_TYPE_DEFAULT); $this->redirectAfterLogin($login_successful); } else { $app->redirect($app->config('app.baseurl') . '/register'); } }
/** * Login with cookie */ public function getLoginWithCookie() { $this->app->log->debug(get_class($this) . '->getLoginWithCookie()'); // run the loginWithCookie() method in the login-model, put the result in $login_successful (true or false) $login_successful = LoginModel::loginWithCookie($this->app->getCookie('remember_me')); // if login successful, redirect to dashboard/index ... if ($login_successful) { $this->redirectAfterSuccessfullyLogin(); } else { // if not, delete cookie (outdated? attack?) and route user to login form to prevent infinite login loops LoginModel::deleteCookie(); $this->redirectToLogin(); } }
/** * Index, default action (shows the login form), when you do login/index */ public function getLogin() { $this->app->log->debug(get_class($this) . '->getLogin()'); $logged_in = LoginModel::isUserLoggedIn(); $redirect = $this->getRedirectUrl(); // Auto login if (!$logged_in) { if (Session::getDecoded(Session::FB_ACCESS_TOKEN)) { // In questo caso posso evitare di visualizzare la form di login "server-side" // e provare a loggare direttamente l'utente $this->app->log->debug("Access token is in session, go directly to the callback route"); $this->app->redirect($this->app->config('app.baseurl') . '/login/fb/callback' . '?redirect=' . urlencode($redirect)); } else { $loginUrl = FacebookModel::getLoginUrl(); $this->app->render($this->app->config('app.templates.path') . '/login/external/fb_login_server_side.twig', array('redirect' => urlencode($redirect), 'login_url' => $loginUrl, 'feedback_positive' => $this->getFeedbackPositiveMessages(), 'feedback_negative' => $this->getFeedbackNegativeMessages())); } } else { $redirect_url = $this->app->config('auth.route.afterlogin'); if ($redirect) { $redirect_url .= '?redirect=' . urlencode($redirect); } $this->app->redirect($redirect_url); } }
/** * Detects if there is concurrent session (i.e. another user logged in with the same current user credentials), * If so, then logout. * */ public function checkSessionConcurrency() { if (Session::userIsLoggedIn()) { // $this->app->log->debug("userIsLoggedIn"); if (Session::isConcurrentSessionExists()) { // TODO: log something... LoginModel::logout(); $this->redirectHome(); exit; } } }