Example #1
0
File: BlogView.C Project: DTidd/wt
  void showArchive(WContainerWidget *parent) {
    static const char* dateFormat = "MMMM yyyy";
    
    new WText(tr("archive-title"), parent);

    Posts posts = session_.find<Post>("order by date desc");

    WDateTime formerDate;
    for (Posts::const_iterator i = posts.begin(); i != posts.end(); ++i) {
      if ((*i)->state != Post::Published)
	continue;

      if (formerDate.isNull() 
	  || yearMonthDiffer(formerDate, (*i)->date)) {
	WText *title
	  = new WText((*i)->date.date().toString(dateFormat), parent);
	title->setStyleClass("archive-month-title");
      }
      
      WAnchor *a = new WAnchor(WLink(WLink::InternalPath,
				     basePath_ + (*i)->permaLink()),
			       (*i)->title, parent);
      a->setInline(false);
      
      formerDate = (*i)->date;
    }
  }
CommentView::CommentView(CommentTuple data, WContainerWidget* parent): WContainerWidget(parent)
{
  setStyleClass("row comment-box");
  string username = data.get<3>();
  string email = data.get<2>();
  WDateTime commentTime = WDateTime::fromTime_t(data.get<1>());
  string commentText = data.get<0>();
  setContentAlignment(AlignLeft);
  addWidget(WW<WContainerWidget>().css("col-md-3 label label-success comment-header")
    .add(WW<WText>(username).setInline(false))
//     .add(WW(WText, email).setInline(false))
    .add(WW<WText>(commentTime.toString()).setInline(false)));
  addWidget(WW<WText>(WString::fromUTF8(commentText)).css("col-md-8 well comment-text") );
}
Example #3
0
const std::string OAuthTokenEndpoint::idTokenPayload(const std::string &clientId,
                                                     const std::string &scope,
                                                     const User &user)
{
  Json::Object root;
  root["iss"] = Json::Value(iss_);
  root["sub"] = Json::Value(user.id());
  root["aud"] = Json::Value(clientId);
  WDateTime curTime = WDateTime::currentDateTime();
  root["exp"] = Json::Value(static_cast<long long>(curTime.addSecs(idExpSecs_).toTime_t()));
  root["iat"] = Json::Value(static_cast<long long>(curTime.toTime_t()));
  root["auth_time"] =
    Json::Value(boost::lexical_cast<std::string>(
          user.lastLoginAttempt().toTime_t()));

  return Json::serialize(root);
}
Example #4
0
int PasswordService::delayForNextAttempt(const User& user) const
{
  if (attemptThrottling_) {
    int throttlingNeeded = getPasswordThrottle(user.failedLoginAttempts());

    if (throttlingNeeded) {
      WDateTime t = user.lastLoginAttempt();
      int diff = t.secsTo(WDateTime::currentDateTime());

      if (diff < throttlingNeeded)
	return throttlingNeeded - diff;
      else
	return 0;
    } else
	return 0;
  } else
    return 0;
}
Example #5
0
void AuthService::lostPassword(const std::string& emailAddress,
				   AbstractUserDatabase& users) const
{
  /*
   * This will check that a user exists in the database, and if so,
   * send an email.
   */
  User user = users.findWithEmail(emailAddress);

  if (user.isValid()) {
    std::string random = WRandom::generateId(randomTokenLength());
    std::string hash = tokenHashFunction()->compute(random, std::string());

    WDateTime expires = WDateTime::currentDateTime();
    expires = expires.addSecs(emailTokenValidity() * 60);

    Token t(hash, expires);
    user.setEmailToken(t, User::LostPassword);
    sendLostPasswordMail(emailAddress, user, random);
  }
}
Example #6
0
WDateTime operator +(const WDateTime& a, const TimeDuration& b) {
    return WDateTime::fromPosixTime(a.toPosixTime() +
                                    static_cast<const TimeDuration::Base&>(b));
}
Example #7
0
TimeDuration operator -(const WDateTime& a, const WDateTime& b) {
    return a.toPosixTime() - b.toPosixTime();
}
Example #8
0
File: BlogView.C Project: DTidd/wt
 bool yearMonthDiffer(const WDateTime& dt1, const WDateTime& dt2) {
   return dt1.date().year() != dt2.date().year()
     || dt1.date().month() != dt2.date().month();
 }