/** * Get any auth available. * * @param T_User_Gateway $user_gw * @param T_Role_Gateway $role_gw * @return T_Auth|false auth if available or false if not */ function get($user_gw, $role_gw) { if (!$this->cookie->exists($this->key)) { return false; } // lookup token in db $token = $this->cookie->asScalar($this->key)->filter(new T_Validate_HexHash())->uncage(); if (mt_rand(1, 20) == 10) { // 1/20 clear old records $sql = 'DELETE FROM person_auth_token WHERE expiry<' . time(); $this->db->master()->query($sql); } $sql = 'SELECT person,expiry ' . 'FROM person_auth_token ' . 'WHERE expiry>? AND token=?'; $result = $this->db->slave()->query($sql, array(time(), $token)); // if the token has not been found, remove it // (it has probably expired). if (count($result) != 1) { $this->destroy(); return false; } // token has been found, so get the user and roles associated // with the token and create auth package $row = $result->fetch(); $user = $user_gw->getById($row['person']); $role = $role_gw->getCollectionByUser($user); $auth = new T_Auth(T_Auth::TOKEN, $user, $role); // delete the use once token $sql = 'DELETE FROM person_auth_token ' . 'WHERE token=?'; $this->db->master()->query($sql, array($token)); // add a new persistent login token $this->createToken($user, $row['expiry']); return $auth; }
/** * Delete user. * * @param T_User $user * @return T_User_Gateway fluent interface */ function delete(T_User $user) { $sql = "DELETE FROM " . $this->getTable() . " WHERE id=" . (int) $user->getId(); $this->db->master()->query($sql); $user->setId(null); return $this; }
/** * Gets all the countries. * * @return T_Geo_Country[] */ function getAll() { $sql = 'SELECT id,code,name,url FROM country ' . 'ORDER BY name ASC'; $result = $this->db->slave()->query($sql); $world = array(); foreach ($result as $row) { $world[$row['id']] = $this->fromRow($row); } return $world; }
/** * Deny a user all roles. * * @param T_User $user * @return T_Role_Gateway fluent interface */ function denyAll(T_User $user) { $sql = 'DELETE FROM person_role ' . 'WHERE person=?'; $this->db->master()->query($sql, array($user->getId())); return $this; }