Exemplo n.º 1
0
 public function loadUserByUsername($username)
 {
     $user = UserQuery::create()->findOneByUsername($username);
     if (!$user) {
         throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
     }
     return $user;
 }
Exemplo n.º 2
0
 /**
  * Get the associated User object
  *
  * @param      PropelPDO $con Optional Connection object.
  * @return                 User The associated User object.
  * @throws PropelException
  */
 public function getUser(PropelPDO $con = null)
 {
     if ($this->aUser === null && $this->user_id !== null) {
         $this->aUser = UserQuery::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->addWatchlists($this);
            */
     }
     return $this->aUser;
 }
Exemplo n.º 3
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(UserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = UserQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Exemplo n.º 4
0
 * ----------------------
 *  route /admin/password POST
 * ----------------------
 */
$app->post("/admin/password", function (Request $request) use($app) {
    $user_id = $request->get('user_id');
    $username = $request->get('username');
    $email = $request->get('email');
    if ($user_id) {
        $user = UserQuery::create()->findPk($user_id);
    } else {
        if ($username) {
            $user = UserQuery::create()->findOneByUsername($username);
        } else {
            if ($email) {
                $user = UserQuery::create()->findOneByEmail($email);
            } else {
                $user = null;
            }
        }
    }
    if (!$user) {
        return $app->redirect($app['url_generator']->generate('admin_password', array('flash' => "no_user")));
    }
    $reset = bin2hex(openssl_random_pseudo_bytes(16));
    $user->setResetPassword($reset);
    $user->save();
    return $app->redirect($app['url_generator']->generate('admin_password', array('flash' => "ok [{$reset}]")));
})->bind('admin_password_post');
/**
 * ----------------------
Exemplo n.º 5
0
 */
$app->get("/reset-password/{reset}", function (Request $request, $reset) use($app) {
    $app->setLoginActive();
    if (!$reset || !($user = UserQuery::create()->findOneByResetPassword($reset))) {
        return $app->redirect($app['url_generator']->generate('login'));
    }
    return $app['twig']->render('reset_password.html.twig', array('reset' => $reset, 'error' => ''));
})->bind('reset_password');
/**
 * ----------------------
 *  route /reset-password POST
 * ----------------------
 */
$app->post("/reset-password/{reset}", function (Request $request, $reset) use($app) {
    $app->setLoginActive();
    if (!$reset || !($user = UserQuery::create()->findOneByResetPassword($reset))) {
        return $app->redirect($app['url_generator']->generate('login'));
    }
    $error = null;
    if ($request->getMethod() == 'POST') {
        if (!($password = $request->get('password'))) {
            $error = "Password is required";
        } else {
            if (preg_match("/\\s/", $password)) {
                $error = "Password can't contain whitespaces";
            } else {
                if (!($password2 = $request->get('password2'))) {
                    $error = "Repeating your password is required";
                } else {
                    if ($password != $password2) {
                        $error = "Please repeat your password";
Exemplo n.º 6
0
 /**
  * Returns a new UserQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     UserQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return UserQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof UserQuery) {
         return $criteria;
     }
     $query = new UserQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Exemplo n.º 7
0
 /**
  * Gets the number of User objects related by a many-to-many relationship
  * to the current object by way of the watchlist cross-reference table.
  *
  * @param      Criteria $criteria Optional query object to filter the query
  * @param      boolean $distinct Set to true to force count distinct
  * @param      PropelPDO $con Optional connection object
  *
  * @return int the number of related User objects
  */
 public function countUsers($criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collUsers || null !== $criteria) {
         if ($this->isNew() && null === $this->collUsers) {
             return 0;
         } else {
             $query = UserQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByItem($this)->count($con);
         }
     } else {
         return count($this->collUsers);
     }
 }