public function actionLogout() { $this->user = new Fari_AuthenticatorSimple(); $this->user->signOut(); $this->flashSuccess = 'You have been logged out'; $this->renderAction('login'); }
public function filterStartup() { $this->user = new Fari_AuthenticatorSimple(); if (!$this->user->isAuthenticated()) { $this->redirectTo('/login/'); } $this->albums = new Albums(); }
function __construct($username, $password, $token = NULL) { $authenticator = new Fari_AuthenticatorSimple(); // authenticator authenticates... if ($authenticator->authenticate($username, $password, $token) != TRUE) { throw new UserNotAuthenticatedException(); } else { // return the sweet beans return new User(); } }
/** * Check that user is authenticated. * @throws AuthUserNotAuthenticatedException */ public function __construct() { // construct the db table $this->table = new Table('users'); // call the authenticator parent::__construct($this->table); // no entry, we are not logged in, fail the constructor if (!$this->isAuthenticated()) { throw new AuthUserNotAuthenticatedException(); } }
/** * Create object for authenticated user */ function __construct($roles = NULL) { $this->db = Fari_Db::getConnection(); parent::__construct(); // no entry, we are not logged in, fail the constructor if (!$this->isAuthenticated()) { throw new UserNotAuthenticatedException(); } // fetch the database entry for us $dbUser = $this->db->selectRow('users', 'id, role, name, surname, short, long, invitation', array('username' => $this->getCredentials())); // user has been inactivated, throw them away if ($dbUser['role'] == 'inactive') { throw new UserNotAuthenticatedException(); } // ORM much? effectively map db entry into an identity Fari_Bag object $this->identity = new Fari_Bag(); foreach ($dbUser as $key => $value) { $this->identity->{$key} = $value; } // get an array of room permissions for us $q = $this->db->select('user_permissions', 'room', array('user' => $dbUser['id']), 'room ASC'); foreach ($q as $room) { array_push($this->permissions, $room['room']); } // which rooms are we in? $q = $this->db->select('room_users JOIN rooms ON room_users.room=rooms.id', 'rooms.id, name', array('user' => $dbUser['id']), 'room ASC'); foreach ($q as $room) { $this->inRoom[$room['name']] = $room['id']; } // optionally check the roles if (isset($roles)) { if (!$this->isAuthorized(&$roles, $dbUser['role'])) { throw new UserNotAuthorizedException(); } } }
/** * Get code and name from the form and create a new user for us (generate username) */ public function actionCreate() { $name = Fari_Decode::accents($this->request->getPost('name')); $code = $this->request->getPost('code'); if (!empty($name)) { $name = explode(' ', $name); // do we have a 'long' name? if (count($name) > 1) { $short = $name[0] . ' ' . substr(end($name), 0, 1) . '.'; $long = implode(' ', $name); $surname = end($name); $name = $name[0]; } else { $short = $long = $name = $name[0]; $surname = ''; } // generate a username $username = Fari_Escape::slug($long) . Fari_Tools::randomCode(10); $db = Fari_Db::getConnection(); // insert the user in a guest role $userId = $db->insert('users', array('short' => $short, 'long' => $long, 'name' => $name, 'surname' => $surname, 'role' => 'guest', 'username' => $username)); // log them in automatically Fari_AuthenticatorSimple::forceAuthenticate($username); // give them permissions to enter this room $room = $db->selectRow('rooms', 'id', array('guest' => $code)); if (!empty($room)) { $db->insert('user_permissions', array('room' => $room['id'], 'user' => $userId)); } } // redirect to the room, if we've ailed will be asked for guest's name again $this->redirectTo('/g/' . $code); }