public function login($uid = null) { if (null !== $uid) { $this->user->login(models\User::get($uid)); } if ($this->user->isLoggedIn()) { $this->_redirect('/blog'); } if ($this->POST) { $post = options($_POST); $get = options($_GET); try { // get user object $user = models\User::withCredentials(array('username' => (string) $post->username, 'password' => (string) $post->password)); // log user in(to SessionUser) $this->user->login($user); // debug direct logged in status Session::message('<pre>' . var_export($this->user->isLoggedIn(), 1) . '</pre>'); // message OK Session::success('Alright, alright, alright, you\'re logged in...'); // back to blog return $this->_redirect($post->get('goto', $get->get('goto', 'blog'))); } catch (\Exception $ex) { } // message FAIL Session::error('Sorry, buddy, that\'s not your username!'); } $messages = Session::messages(); return get_defined_vars(); }
public function logout() { if (parent::logout()) { Session::success('You are now logged out.'); } }
public function add_comment($post) { $post = $this->getPost($post); $anonymous = $this->user->isLoggedIn() ? '' : '_anonymous'; $validator = models\Comment::validator('add' . $anonymous); //echo '<pre>'; //print_r($validator); exit; if (!empty($_POST)) { if ($validator->validate($_POST, $context)) { $insert = $validator->output; if (!$this->user->isLoggedIn() && isset($context['user'])) { $this->user->login($context['user']); } //print_r($insert); print_r($context); exit; $insert['post_id'] = $post->post_id; $insert['created_on'] = time(); $insert['created_by_ip'] = $_SERVER['REMOTE_ADDR']; //print_r($insert); exit; try { $cid = models\Comment::insert($insert); //var_dump($cid); exit; $comment = models\Comment::get($cid); //print_r($comment); exit; Session::success('Comment created'); $this->_redirect($comment->url()); } catch (\Exception $ex) { Session::error('Didn\'t save... Try again!?'); } } else { Session::error('See input errors below:'); } } $messages = Session::messages(); return $this->tpl->display('blog/comment_form', get_defined_vars()); }
private function approved($conditions, $params = array()) { try { // existing openid user $openid = UserOpenID::one($conditions); if ($this->user->isLoggedIn()) { Session::warning('That account is already connected.'); return $this->_redirect('pages/restricted'); } // get user object $user = User::get($openid->user_id); } catch (ModelException $ex) { // remove potential openid user UserOpenID::_delete($conditions); // new user if (!$this->user->isLoggedIn()) { // insert $user = array('signed_up_at' => time(), 'first_login' => time()); $uid = User::insert($user); // get user object $user = User::get($uid); } else { $user = $this->user->user; } // new openid user $conditions['user_id'] = $user->user_id; $conditions['params'] = json_encode($params); UserOpenID::insert($conditions); } if (!$this->user->isLoggedIn()) { $this->user->login($user); } else { Session::success('Account connected!'); } return $this->_redirect('pages/restricted'); }
public function logoutAction() { $this->user->logout(); Session::success(t('You logged out...')); $this->_redirect('user'); }