Esempio n. 1
0
void UpdatePasswordWidget::updateView(const std::string& var,
				      RegistrationModel::Field field)
{
  WFormWidget *edit = resolve<WFormWidget *>(var);
  WText *info = resolve<WText *>(var + "-info");
  
  const WValidator::Result& v = model_->validationResult(field);
  info->setText(v.message());

  switch (v.state()) {
  case WValidator::InvalidEmpty:
  case WValidator::Invalid:
    edit->removeStyleClass("Wt-valid");
    if (validated_)
      edit->addStyleClass("Wt-invalid");
    info->addStyleClass("Wt-error");

    break;
  case WValidator::Valid:
    edit->removeStyleClass("Wt-invalid");
    if (validated_)
      edit->addStyleClass("Wt-valid");
    info->removeStyleClass("Wt-error");
  }
}
Esempio n. 2
0
void WsMenu::doLoadCurPath()
{
  std::string rootPath = asString(option("rootPath")).toUTF8();
  boost::algorithm::replace_all(rootPath, "&amp;",  "&");
  // Si pas de root path on prend l'internal Path
 
  if ( rootPath.size() < 1 ){
    m_sCurPath = WsApp->internalPath();
  }else
    m_sCurPath = rootPath;

  std::string sWithoutPrefix = WsApp->WsModules().pathWithoutPrefix(m_sCurPath);
  WsUser*         pUser     = WsApp->wsUser();
  NodePtr tmpNode = pUser->getAccessRoot().get()->eatPath(sWithoutPrefix);
  if ( !tmpNode.get() ) {
    wApp->log("notice") << "WsMenu::doLoadCurPath - eatPath return NULL ";
    return;
  }
  if ( tmpNode.get()->isRegularFile() ) {
    tmpNode = pUser->getAccessRoot().get()->eatPath(boost::filesystem::path(sWithoutPrefix).parent_path().string());
    if ( !tmpNode.get() ) {
      wApp->log("notice") << "WsMenu::doLoadCurPath - eatPath on parent return NULL ";
      return;
    }
  }
  NodePtr startNode = pUser->getAccessRoot();
  if ( !startNode.get() ) {
    wApp->log("notice") << "WsMenu::doLoadCurPath - startNode  = " << startNode;
    return;
  }
  NodePtr pNode = startNode.get()->eatPath(tmpNode.get()->getPath().string());
  if ( !pNode.get() ) return;
  if ( asString(option("useTitle")) == "true" )   {
    std::string sTitle(pNode.get()->getDisplayName());
    boost::algorithm::replace_all(sTitle, "&", "&amp;");
    WText* title = new WText(sTitle);
    title->addStyleClass("WsMenuTitle");
    addWidget(title);
  }
  WMenu*          menuParent = 0;
  if ( asString(option("useButtons")) != "true" )
    menuParent = new WMenu(this);
  if ( asString(option("showRoot")) == "true" )
    if ( pNode.get()->getPath() == "/" ) {
      createMenu(pNode, menuParent);
    }
  loadMenu(pNode, menuParent);
  if ( asString(option("useImages")) == "true" )
    loadImage(pNode);
}
Esempio n. 3
0
void Recaptcha::update_impl() {
    if (!implementation()) {
        setImplementation(new WContainerWidget());
    }
    get_impl()->clear();
    WText* title = new WText("reCAPTCHA", get_impl());
    title->addStyleClass("wc_recaptcha_title");
    if (js()) {
        WContainerWidget* image = new WContainerWidget(get_impl());
        image->setId("recaptcha_image");
        response_field_ = input_ ? input_ : new WLineEdit(get_impl());
        challenge_field_ = new WLineEdit(get_impl());
        // not challenge_field_->hide() to get its .text()
        doJavaScript("$(" + challenge_field_->jsRef() + ").hide();");
        response_field_->setId("recaptcha_response_field");
        doJavaScript("Recaptcha.create('" + public_key_  + "', '',"
                     "{theme: 'custom'});");
        if (buttons_enabled_) {
            add_buttons();
        }
        doJavaScript("clearTimeout($(" + jsRef() + ").data('timer'));");
        doJavaScript("$(" + jsRef() + ").data('timer',"
                     "setInterval(function() {"
                     "$(" + challenge_field_->jsRef() + ")"
                     ".val(Recaptcha.get_challenge());"
                     "}, 200));");
    } else {
        WTemplate* iframe = new WTemplate(get_impl());
        iframe->setTemplateText("<iframe src='https://www.google.com/recaptcha/"
                                "api/noscript?k=" + public_key_ +
                                "' height='300' width='500' frameborder='0'>"
                                "</iframe>", XHTMLUnsafeText);
        if (input_) {
            challenge_field_ = input_;
        } else {
            WTextArea* ta = new WTextArea(get_impl());
            ta->setColumns(40);
            ta->setRows(3);
            challenge_field_ = ta;
        }
        response_field_ = new WLineEdit("manual_challenge", get_impl());
        response_field_->hide();
    }
}
Esempio n. 4
0
void WsMenu::createMenu(NodePtr curNode, WMenu* menuParent)
{
  std::string path2Icon;
  WsUser*     pUser   = WsApp->wsUser();
  std::string sIcon   = curNode.get()->getProperties().get()->get("global", "icon", "");
  if ( sIcon.size() > 1 ) {
    NodePtr tmpNode = curNode;
    if ( tmpNode.get()->isRegularFile() )
      tmpNode   = curNode.get()->getParent();
    if ( tmpNode.get() ) {
      path2Icon = tmpNode.get()->getFullPath().string() + "/ws.res/icones/" + sIcon;
      if ( !boost::filesystem::exists(path2Icon) )
        path2Icon.clear();
      else {
        boost::algorithm::replace_first(path2Icon, WsApp->docRoot(), "");
      }
    }
  }
  if ( asString(option("useButtons")) == "true" ) {
    if ( curNode.get()->getPath().string() != "/" )
      if ( asString(option("useSeparator")) == "true" ) {
        WText* pText = new WText("|", this);
        pText->addStyleClass("WsMenuSep");
      }
    WPushButton* button = new WPushButton(curNode.get()->getDisplayName(true), this);
    m_vPushButton.push_back(button);
    if ( path2Icon.size() > 1 ) {
      button->setIcon(WLink(WLink::Url, path2Icon));
      if ( curNode.get()->getProperties().get()->get("global", "button_text", "true") == "false" )
        button->setText("");
    }
    // TODO : Ameliorer cette fonction
    if ( (curNode.get()->isDirectory() && asString(option("directorySelectable")) == "true") ||
         pUser->isAdministrator() || pUser->isEditor() ||
         (asString(option("showRoot")) == "true" && curNode.get()->getPath() == "/")
       ) {
      button->setLink(WLink(WLink::InternalPath, curNode.get()->getPath().string()));
    }
    if ( curNode.get()->isRegularFile() ) {
      button->setLink(makeLink(curNode.get()->getPath().string(), false));
      if ( button->link().type() == WLink::Url )
        button->setLinkTarget(TargetNewWindow);
    }
    bool popupAllowed = (curNode.get()->getProperties().get()->get("global", "allow_popup", "true") == "true" ? true : false);
    if ( curNode.get()->isDirectory() && popupAllowed && asString(option("usePopupMenu")) == "true" ) {
      if ( !(asString(option("noRootPopup")) == "true" && curNode.get()->getPath() == "/") ) {
        WPopupMenu* pPopup = new WPopupMenu();
        pPopup->addStyleClass("wt-no-reparent");
        loadPopupMenu(curNode, pPopup);
        button->setMenu(pPopup);
        pPopup->setAutoHide(true);
        button->mouseWentOver().connect(boost::bind(&WsMenu::onMouseWentOver, this, button));
        button->setMouseOverDelay(50);
      }
    }
  } else { // No buttons, standard menu
    if ( curNode.get()->getPath().string() != "/" )
      menuParent->addSeparator();
    WMenuItem* pItem = menuParent->addItem(curNode.get()->getDisplayName(true));
    pItem->setLink(WLink(WLink::InternalPath, curNode.get()->getPath().string()));
    if ( path2Icon.size() > 1 )
      pItem->setIcon(path2Icon);
    if ( curNode.get()->isDirectory() && asString(option("usePopupMenu")) == "true" )
      if ( curNode.get()->getDirectories().size() ) {
        WPopupMenu* pPopup = new WPopupMenu();
        pPopup->addStyleClass("wt-no-reparent");
        loadPopupMenu(curNode, pPopup);
        pItem->setMenu(pPopup);
      }
  }
}
Esempio n. 5
0
void HighScoresWidget::update()
{
  clear();
  
  new WText("<h2>Hall of fame</h2>", this);
  
  int ranking = session_->findRanking();
  
  std::string yourScore;
  if (ranking == 1)
    yourScore = "Congratulations! You are currently leading the pack.";
  else {
    yourScore = "You are currently ranked number "
      + boost::lexical_cast<std::string>(ranking)
      + ". Almost there !";
  }

  WText *score = new WText("<p>" + yourScore + "</p>", this);
  score->addStyleClass("score");
  
  std::vector<User> top = session_->topUsers(20);

  WTable *table = new WTable(this);

  new WText("Rank", table->elementAt(0, 0));
  new WText("User", table->elementAt(0, 1));
  new WText("Games", table->elementAt(0, 2));
  new WText("Score", table->elementAt(0, 3));
  new WText("Last game", table->elementAt(0, 4));
  table->setHeaderCount(1);

  int formerScore = -1;
  int rank = 0;
  for (unsigned i = 0; i < top.size(); i++) {
    User u = top[i];

    if (u.score != formerScore) {
      formerScore = u.score;
      ++rank;
    }
    
    int row = table->rowCount();
    new WText(boost::lexical_cast<std::string>(rank),
	      table->elementAt(row, 0));
    new WText(u.name, table->elementAt(row, 1));
    new WText(boost::lexical_cast<std::string>(u.gamesPlayed),
	      table->elementAt(row, 2));
    new WText(boost::lexical_cast<std::string>(u.score),
	      table->elementAt(row, 3));
    if (!u.lastGame.isNull())
      new WText(u.lastGame.timeTo(WDateTime::currentDateTime())
		+ " ago", table->elementAt(row, 4));
    else
      new WText("---", table->elementAt(row, 4));
    
    if (session_->login().loggedIn() && session_->userName() == u.name)
      table->rowAt(row)->setId("self");
  }

  WText *fineprint = new WText(tr("highscore.info"), this);
  fineprint->addStyleClass("fineprint");
}