/** * The Login action allows a user to connect to his account. * * @param array $params Redirect is expected in this array * @return array Model containing the redirect link */ protected function login($params) { // Find redirect URL $referer = Route::getReferer(); $redirect_request = Request::get('redirect'); if (empty($params[0])) { $route = Route::getRoute(); if (!empty($redirect_request)) { $redirect = $redirect_request; } else { if ($route['app'] != 'user') { // Login form loaded from an external application $redirect = Route::getDir() . Route::getQuery(); } else { if (strpos($referer, 'user') === false) { $redirect = $referer; } else { $redirect = Route::getDir(); } } } } else { $redirect = $params[0]; } if ($this->session->isConnected()) { return array('errors' => array('Vous êtes déjà connecté !')); } // Vars given to trigger login process? $data = Request::getAssoc(array('email', 'password')); $cookie = true; // cookies accepted by browser? $errors = array(); if (!in_array(null, $data, true)) { $data += Request::getAssoc(array('remember', 'time')); if (!empty($data['email']) && !empty($data['password'])) { // User asks to be auto loged in => change the cookie lifetime to Session::REMEMBER_TIME $remember_time = !empty($data['remember']) ? Session::REMEMBER_TIME : abs(intval($data['time'])) * 60; // Start login process switch ($this->session->createSession($data['email'], $data['password'], $remember_time)) { case Session::LOGIN_SUCCESS: // Update activity if (empty($_COOKIE['wsid'])) { array_push($errors, 'Les cookies ne sont pas acceptés par votre navigateur !'); $cookie = false; } else { // Redirect return array('success' => true); } break; case Session::USER_BANNED: array_push($errors, 'Vous avez été banni du site ! <a href="' . Config::get('config.base') . '/contact">Contactez l\'administrateur</a>.'); break; case Session::NOT_VALIDATED: array_push($errors, 'Votre compte n\'a pas encore été activé !'); break; case 0: array_push($errors, 'Couple Login / Mot de passe incorrect.'); break; } } else { array_push($errors, 'Les champs requis n\'ont pas été rensignés.'); } } return array('redirect' => $redirect, 'errors' => $errors); }