public function index() { if (isset($_POST["search"])) { $s = $_POST["search"]; } $users = UserQuery::create()->where('User.Username like ?', '%' . $s . '%')->orderByPermissions('desc')->join('Image')->withColumn('Image.Path', 'AvatarPath')->select('Username', 'AvatarPath')->find(); $articles = ArticleQuery::create()->where('Article.Title like ?', '%' . $s . '%')->_or()->where('Article.Keywords like ?', '%' . $s . '%')->orderByCreatedAt('desc')->join('User')->withColumn('User.Username', 'Author')->join('Category')->withColumn('Category.Name', 'CatgName')->join('Image')->withColumn('Image.Path', 'ImgPath')->select(array('Author', 'CatgName', 'ImgPath', 'Id', 'Title'))->find(); if ($articles->isEmpty() && $users->isEmpty()) { $this->addPopup('danger', 'Nebyl nalezen žádný článek ani uživatel.'); } $this->view('Search/index', 'base_template', ['active' => 'search', 'title' => 'Vyhledávání', 'recent' => ArticleQuery::recent(), 'articles' => $articles, 'users' => $users]); }
public function __construct() { $this->params['title'] = "Tasker"; $this->addBeforeFilter(function () { $this->params["flashes"] = isset($_SESSION['flashes']) ? $_SESSION['flashes'] : array(); $_SESSION['flashes'] = array(); }, "init_flashes"); $this->addBeforeFilter(function () { if (isset($_SESSION['user'])) { $this->params['user'] = UserQuery::create()->findPK(isset($_SESSION['user'])); $this->params['user_logged'] = true; } else { $this->params['user_logged'] = false; $_SESSION['user'] = 1; $this->params['user'] = UserQuery::create()->findPK(isset($_SESSION['user'])); $this->params['user_logged'] = true; } }, "load_user"); }
protected function loadUser() { $user = null; if (isset($_SESSION["userId"])) { $user = UserQuery::create()->findPK($_SESSION["userId"]); } else { if (isset($_COOKIE["identityId"]) && isset($_COOKIE["identityToken"])) { $identity = IdentityQuery::create()->findPK($_COOKIE["identityId"]); if ($identity && $identity->checkToken($_COOKIE["identityToken"])) { $user = UserQuery::create()->filterByIdentity($identity)->findOne(); if ($user) { $_SESSION["userId"] = $user->getId(); $token = generateRandomString(32); $identity->setToken($token)->setExpiresAt(time() + 86400 * 120)->save(); setcookie("identityId", $identity->getId(), time() + 86400 * 120); setcookie("identityToken", $token, time() + 86400 * 120); } } } } if ($user && !$user->getEmailConfirmedAt()) { unset($_SESSION["userId"]); if (isset($_COOKIE["identityId"])) { $identity = IdentityQuery::create()->findPK($_COOKIE["identityId"]); if ($identity) { $identity->delete(); setcookie("identityId", "", time() - 86400); setcookie("identityToken", "", time() - 86400); } } $this->sendFlashMessage('You email adress has not been confirmed yet. <a class="link" href="/user/' . $user->getUsername() . '/send-email-confirm-email">Send new email confirm link?</a>', "error"); $this->redirect("/"); } $this->data["loggedUser"] = $user; return true; }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @throws LogicException if no primary key is defined * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = ChildUserQuery::create(); $criteria->add(UserTableMap::COL_ID, $this->id); return $criteria; }
public function index() { $participants = array(2, 1); $users = UserQuery::create()->filterByIdMember($participants)->joinWith('Image')->joinWith('Member')->useMemberQuery()->joinWith('Quote')->endUse()->find(); $this->view('Landing/index', 'base_template', ['active' => 'landing', 'title' => 'Hlavní stránka', 'recent' => ArticleQuery::recent(), 'js' => array('plugins/fotorama/fotorama', 'scripts/landingpagemembers'), 'css' => 'plugins/fotorama/fotorama', 'users' => $users]); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Image is new, it will return * an empty collection; or if this Image has previously * been saved, it will retrieve related Users from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Image. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return ObjectCollection|ChildUser[] List of ChildUser objects */ public function getUsersJoinMember(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildUserQuery::create(null, $criteria); $query->joinWith('Member', $joinBehavior); return $this->getUsers($query, $con); }
/** * Performs an INSERT on the database, given a User or Criteria object. * * @param mixed $criteria Criteria or User object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(UserTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from User object } if ($criteria->containsKey(UserTableMap::COL_ID) && $criteria->keyContainsValue(UserTableMap::COL_ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . UserTableMap::COL_ID . ')'); } // Set the correct dbName $query = UserQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }
protected function updatePermissions() { if ($this->data["permission"] != 3) { $this->sendFlashMessage("You do not have permission to update pack with ID " . $this->data["pack"]->getId() . ".", "error"); $this->redirect("/"); } if (isset($_POST["user"])) { foreach ($_POST["user"] as $user) { if (!isset($user["username"]) || $user["username"] == "") { continue; } $u = UserQuery::create()->findOneByUsername($user["username"]); if ($u) { if ($u == $this->data["loggedUser"]) { $this->sendFlashMessage("You can not add permission to yourself.", "error"); continue; } $permission = PackPermissionQuery::create()->filterByUser($u)->filterByPack($this->data["pack"])->findOneOrCreate(); if (isset($user["permission"])) { $permission->setValue($user["permission"]); } else { $permission->delete(); continue; } $permission->setPack($this->data["pack"]); $permission->setUser($u); $permission->save(); } else { $this->sendFlashMessage("User " . $user["username"] . " does not exist.", "error"); } } } if (isset($_POST["group"])) { foreach ($_POST["group"] as $group) { if (!isset($group["name"]) || $group["name"] == "") { continue; } $g = GroupQuery::create()->filterByOwner($this->data["loggedUser"])->filterByName($group["name"])->findOne(); if ($g && $g->getOwnerId() == $this->data["loggedUser"]->getId()) { $permission = PackPermissionQuery::create()->filterByGroup($g)->filterByPack($this->data["pack"])->findOneOrCreate(); if (isset($group["permission"])) { $permission->setValue($group["permission"]); } else { $permission->delete(); continue; } $permission->setPack($this->data["pack"]); $permission->setGroup($g); $permission->save(); } else { $this->sendFlashMessage("Group with name" . $group["name"] . " is not your or does not exist.", "error"); } } } $this->sendFlashMessage("Permissions was updated.", "info"); $this->redirect("/pack/" . $this->data["pack"]->getId() . "/settings"); }
public function index() { $participants = UserQuery::create()->joinWith("Member")->joinWith("Image")->find(); $this->view('Info/index', 'base_template', ['active' => 'info', 'title' => 'Informace', 'recent' => ArticleQuery::recent(), 'participants' => $participants]); }
public function userUpdate() { if ($this->isLogged()) { $_SESSION["user"] = UserQuery::create()->joinWith("Image")->leftJoinWith("Member")->findPk($_SESSION["user"]->getId()); } }
public function emailTokenChange($username, $token, $email) { $user = UserQuery::create()->filterByUsername($username)->filterByEmailChangeToken($token)->findOne(); if (!$user) { $this->addPopup('danger', 'Uživatel se zadaným uživatelským jménem a kódem pro změnu emailu se v databázi nenachází.'); redirectTo('/'); } $user->setEmailChangeToken(NULL); $user->setEmail($email); $user->save(); $this->addPopup('success', 'Váš email byl úspěšně změněn.'); redirectTo('/'); }
protected function search() { $this->data['title'] = 'Starling'; $this->data['keywords'] .= 'search, results'; $this->data['description'] .= 'Results of searching.'; if (isset($_GET["q"]) && $_GET["q"] != "") { $q = urldecode($_GET["q"]); $page = 1; $perPage = 10; $this->data["q"] = $q; $this->data["search"] = "pack"; if (isset($_GET["search"])) { $this->data["search"] = $_GET["search"]; } if (isset($_GET["page"]) && $_GET["page"] >= 1) { $page = $_GET["page"]; } $qParts = preg_split("/\\s+/", $q); for ($i = 0; $i < count($qParts); $i++) { $qParts[$i] = $qParts[$i] . "%"; } $qMatch = $q . "*"; $likeQuery = ""; if ($this->data["search"] == "user") { for ($i = 0; $i < count($qParts); $i++) { if ($i > 0) { $likeQuery .= " OR "; } $likeQuery .= 'user.username LIKE ?'; } for ($i = 0; $i < count($qParts); $i++) { $likeQuery .= ' OR user.name LIKE ?'; } for ($i = 0; $i < count($qParts); $i++) { $likeQuery .= ' OR user.surname LIKE ?'; } $qParts = array_merge($qParts, $qParts, $qParts); $this->data["items"] = UserQuery::create()->condition("cond1", "MATCH(user.username, user.name, user.surname) AGAINST(? IN BOOLEAN MODE)", $qMatch)->condition("cond2", "user.deleted_at IS NULL")->condition("cond3", $likeQuery, $qParts)->combine(array("cond1", "cond3"), "or", "cond13")->where(array("cond13", "cond2"), "and")->paginate($page, $perPage); $this->viewFile($this->template); return; } if ($this->data["search"] == "pack") { for ($i = 0; $i < count($qParts); $i++) { if ($i > 0) { $likeQuery .= " OR "; } $likeQuery .= 'pack.name LIKE ?'; } if (count($qParts) == 1) { $qParts = $qParts[0]; } $this->data["items"] = PackQuery::create()->condition("cond1", "MATCH(pack.name, pack.description) AGAINST(? IN BOOLEAN MODE)", $qMatch)->condition("cond2", "pack.private=false")->condition("cond3", $likeQuery, $qParts)->combine(array("cond1", "cond3"), "or", "cond13")->where(array("cond13", "cond2"), "and")->paginate($page, $perPage); $this->viewFile($this->template); return; } else { $this->redirect("/"); } } else { $this->redirect("/"); } }
public function setPermissions($username, $permissions) { if (!$this->isAdmin()) { $this->addPopup('danger', 'Pro změnu práv uživatelů nemáte dostatečná práva.'); redirectTo('/administrace'); } $user = UserQuery::create()->filterByUsername($username)->findOne(); if (!isset($user)) { $this->addPopup('danger', 'Uživatel se zadaným uživatelským jménem neexistuje.'); redirectTo('/administrace/uzivatele'); } if ($permissions == 1) { if ($user->getPermissions() == 2 || $user->getPermissions() == 3) { $this->addPopup('danger', 'Uživatel se zadaným uživatelským jménem již nemůže být dále povýšen.'); redirectTo('/administrace/uzivatele'); } else { $user->setPermissions(2); $user->save(); $this->addPopup('success', 'Uživatel ' . $user->getUsername() . ' byl úspěšné povýšen na redaktora.'); redirectTo('/administrace/uzivatele'); } } else { if ($user->getPermissions() == 2 || $user->getPermissions() == 3) { if ($user->getIdMember() != NULL) { $user->setPermissions(1); } else { $user->setPermissions(2); } $user->save(); $this->addPopup('success', 'Uživatel ' . $user->getUsername() . ' byl zbaven práv redaktora.'); redirectTo('/administrace/uzivatele'); } else { $this->addPopup('danger', 'Uživatel se zadaným uživatelským jménem nemůže být zbaven práv redaktora.'); redirectTo('/administrace/uzivatele'); } } }
protected function removeUser($params) { setContentType("json"); $response["messages"] = array(); if (isset($params["username"])) { $user = UserQuery::create()->findOneByUsername($params["username"]); if ($user) { $userGroup = UserGroupQuery::create()->filterByUser($user)->filterByGroup($this->data["group"])->findOne(); if ($userGroup) { $userGroup->delete(); } else { $response["messages"][] = "User " . $user["username"] . " is not in group " . $this->data["group"]->getId() . "."; } } else { $response["messages"][] = "User " . $user["username"] . " does not exist."; } } $this->viewString(json_encode($response)); }
protected function signIn() { if (isset($_POST["username"]) && isset($_POST["password"])) { $user = UserQuery::create()->findOneByUsername($_POST["username"]); if (!$user) { $this->sendFlashMessage("You have not been signed in. User does not exist.", "error"); } else { if ($user->getDeletedAt()) { $this->sendFlashMessage("Your account was deleted on " . $user->getDeletedAt("j M o") . '. <a class="link" href="/user/' . $user->getUsername() . '/send-restore-account-email">Send restore link?</a>', "error"); $this->redirect("/404"); } else { if ($user->checkPassword($_POST["password"])) { $_SESSION["userId"] = $user->getId(); if (isset($_POST["rememberMe"])) { if (isset($_COOKIE["identityId"])) { $identity = IdentityQuery::create()->filterById($_COOKIE["identityId"])->delete(); } $token = generateRandomString(32); $identity = new Identity(); $identity->setToken($token)->setUser($user)->save(); setcookie("identityId", $identity->getId(), time() + 86400 * 120); setcookie("identityToken", $token, time() + 86400 * 120); } } else { $this->sendFlashMessage("You have not been signed in. You entered wrong password.", "error"); } } } $this->redirect($this->data["referersURI"]); } else { setHTTPStatusCode("400"); } }
/** * Get the associated ChildUser object * * @param ConnectionInterface $con Optional Connection object. * @return ChildUser The associated ChildUser object. * @throws PropelException */ public function getUser(ConnectionInterface $con = null) { if ($this->aUser === null && $this->user_id !== null) { $this->aUser = ChildUserQuery::create()->findPk($this->user_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aUser->addComments($this); */ } return $this->aUser; }
/** * Gets the number of User objects related by a many-to-many relationship * to the current object by way of the user_group cross-reference table. * * @param Criteria $criteria Optional query object to filter the query * @param boolean $distinct Set to true to force count distinct * @param ConnectionInterface $con Optional connection object * * @return int the number of related User objects */ public function countUsers(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collUsersPartial && !$this->isNew(); if (null === $this->collUsers || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collUsers) { return 0; } else { if ($partial && !$criteria) { return count($this->getUsers()); } $query = ChildUserQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByGroup($this)->count($con); } } else { return count($this->collUsers); } }
/** * Get the associated ChildUser object * * @param ConnectionInterface $con Optional Connection object. * @return ChildUser The associated ChildUser object. * @throws PropelException */ public function getOriginUser(ConnectionInterface $con = null) { if ($this->aOriginUser === null && ($this->origin_type === 'user' && $this->origin_id !== null)) { $this->aOriginUser = ChildUserQuery::create()->findPk($this->origin_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aOriginUser->addNotificationsRelatedByOriginTypeOriginId($this); */ } return $this->aOriginUser; }