public static function CreateCurrentUser() { $currentUser = null; if (isset($_COOKIE['login_hash']) && $_COOKIE['login_hash'] != '') { $currentUser = new CurrentUser($_COOKIE['login_hash']); } else { if (isset($_SESSION['login_hash']) && $_SESSION['login_hash'] != "") { $currentUser = new CurrentUser($_SESSION['login_hash']); } else { $currentUser = new GuestUser(); } } if ($currentUser->isLogged()) { if ($currentUser->isBanned()) { $_SESSION['login_hash'] = null; setcookie('login_hash', '', 0, '/'); } } else { $_SESSION['login_hash'] = null; } return $currentUser; }
/** * Creates the User-Object and the $session['user'] Array * * @param $user_id The ID of the User. * @param $email The email of the User. * @param $nick The nick of the User. */ public function createUserSession($user_id = '', $email = '', $nick = '') { // Initialize the User Object $this->user = null; /** * Get User via DB Queries * * 1) user_id * 2) email * 3) nick */ if (empty($user_id) === false) { // Get the user from the user_id $this->user = Doctrine_Query::create()->from('CsUsers u')->leftJoin('u.CsOptions o')->where('u.user_id = ?')->fetchOne(array($user_id), Doctrine::HYDRATE_ARRAY); } elseif (empty($email) === false) { // Get the user from the email $this->user = Doctrine_Query::create()->from('CsUsers u')->leftJoin('u.CsOptions o')->where('u.email = ?')->fetchOne(array($email), Doctrine::HYDRATE_ARRAY); } elseif (empty($nick) === false) { // Get the user from the nick $this->user = Doctrine_Query::create()->from('CsUsers u')->leftJoin('u.CsOptions o')->where('u.nick = ?')->fetchOne(array($nick), Doctrine::HYDRATE_ARRAY); } /** * Check if this user is activated, * else reset cookie, session and redirect */ if (is_array($this->user) and $this->user['activated'] == 0) { $this->logoutUser(); // redirect Clansuite_CMS::getInjector()->instantiate('Koch_HttpResponse')->redirect('/account/activation_email', 5, 403, _('Your account is not yet activated.')); } /** * Create $_SESSION['user'] array, containing user data */ if (is_array($this->user)) { /** * Transfer User Data into Session */ #Koch_Debug::firebug($_SESSION); #Koch_Debug::firebug($this->config); $_SESSION['user']['authed'] = 1; $_SESSION['user']['user_id'] = $this->user['user_id']; $_SESSION['user']['passwordhash'] = $this->user['passwordhash']; $_SESSION['user']['email'] = $this->user['email']; $_SESSION['user']['nick'] = $this->user['nick']; $_SESSION['user']['disabled'] = $this->user['disabled']; $_SESSION['user']['activated'] = $this->user['activated']; /** * SetLanguage * * At this position the language might already by set by * the language_via_get filter. the language value set via GET * precedes over the user config and the general config * the full order is * a) language_via_get filter * a) user['language'] from database / personal user setting * b) standard language / fallback as defined by $this->config['locale']['locale'] */ if (false === isset($_SESSION['user']['language_via_url'])) { if (false === empty($this->user['language'])) { $_SESSION['user']['language'] = $this->user['language']; } else { $_SESSION['user']['language'] = $this->config['locale']['default']; } } /** * Frontend-Theme * * first take standard theme as defined by $config->theme * @todo remove $_REQUEST, frontend theme is selectable via frontend */ if (false === isset($_REQUEST['theme'])) { $_SESSION['user']['frontend_theme'] = !empty($this->user['frontend_theme']) ? $this->user['frontend_theme'] : $this->config['template']['frontend_theme']; } /** * Backend-Theme */ if (empty($this->user['backend_theme']) === false) { $_SESSION['user']['backend_theme'] = $this->user['backend_theme']; } else { $_SESSION['user']['backend_theme'] = $this->config['template']['backend_theme']; } /** * Permissions * * Get Group & Rights of user_id */ /** User-Datensatz beinhaltet ein CsGroups-Array user => Array ( [user_id] => 1 ... [CsGroups] => Array ( [0] => Array ( [group_id] => 3 ... [role_id] => 5 ) ) ) */ // Initialize User Session Arrays $_SESSION['user']['group'] = ''; $_SESSION['user']['rights'] = ''; if (false === empty($this->user['CsGroups'])) { $_SESSION['user']['group'] = $this->user['CsGroups'][0]['group_id']; $_SESSION['user']['role'] = $this->user['CsGroups'][0]['role_id']; $_SESSION['user']['rights'] = Koch\ACL::createRightSession($_SESSION['user']['role'], $this->user['user_id']); } #Koch_Debug::firebug($_SESSION); } else { // this resets the $_SESSION['user'] array GuestUser::instantiate(); #Koch\Debug\Debug::printR($_SESSION); } }