Пример #1
0
WebAuth::WebAuth() : m_sqlite3(WApplication::instance()->appRoot() + "RTAutomationWeb.db")
{
    m_authSession.setConnection(m_sqlite3);
    m_sqlite3.setProperty("show-queries", "true");

    m_authSession.mapClass<WebUser>("user");
    m_authSession.mapClass<AuthInfo>("auth_info");
    m_authSession.mapClass<AuthInfo::AuthIdentityType>("auth_identity");
    m_authSession.mapClass<AuthInfo::AuthTokenType>("auth_token");

    m_users = new UserDatabase(m_authSession);

    dbo::Transaction transaction(m_authSession);
    try
    {
        m_authSession.createTables();

        Auth::User guestUser = m_users->registerNew();
        guestUser.addIdentity(Auth::Identity::LoginName, "richards-tech");
        WebPasswordService.updatePassword(guestUser, "richards-tech");

        qDebug() << "Database created";
    } catch (...) {
        qDebug() << "Using existing database";
    }

    transaction.commit();
}
Пример #2
0
Файл: Session.C Проект: DTidd/wt
Session::Session()
  : sqlite3_(WApplication::instance()->appRoot() + "hangman.db")
{
  session_.setConnection(sqlite3_);
  sqlite3_.setProperty("show-queries", "true");

  session_.mapClass<User>("user");
  session_.mapClass<AuthInfo>("auth_info");
  session_.mapClass<AuthInfo::AuthIdentityType>("auth_identity");
  session_.mapClass<AuthInfo::AuthTokenType>("auth_token");

  users_ = new UserDatabase(session_);

  dbo::Transaction transaction(session_);
  try {
    session_.createTables();

    /*
     * Add a default guest/guest account
     */
    Auth::User guestUser = users_->registerNew();
    guestUser.addIdentity(Auth::Identity::LoginName, "guest");
    myPasswordService.updatePassword(guestUser, "guest");

    Wt::log("info") << "Database created";
  } catch (...) {
    Wt::log("info") << "Using existing database";
  }

  transaction.commit();
}
Пример #3
0
  AuthApplication(const WEnvironment& env)
    : WApplication(env),
      session_(appRoot() + "auth.db")
  {
    session_.login().changed().connect(this, &AuthApplication::authEvent);

    useStyleSheet("css/style.css");

    std::unique_ptr<Auth::AuthWidget> authWidget(new Auth::AuthWidget(
                          Session::auth(), session_.users(), session_.login()));

    authWidget->setRegistrationEnabled(true);

    WSslInfo *sslInfo = env.sslInfo();
    if (sslInfo) {
      Auth::Identity id = createIdentity(sslInfo);
      Auth::User u = session_.users().findWithIdentity(id.provider(),
							   id.id());
      if (!u.isValid()) 
	authWidget->registerNewUser(id);
      else
        session_.login().login(u, Auth::LoginState::Weak);

      root()->addWidget(std::move(authWidget));
    } else {
      root()->addWidget(cpp14::make_unique<WText>("Not an SSL session, or no "
          "client certificate available. Please read the readme file in "
          "examples/feature/client-ssl-auth for more info."));
      quit();
    }

  }