// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef SESSION_H_
#define SESSION_H_

#include <Wt/Auth/Login>

#include <Wt/Dbo/Session>
#include <Wt/Dbo/ptr>
#include <Wt/Dbo/backend/Sqlite3>

#include "User.h"

namespace dbo = Wt::Dbo;

typedef Wt::Auth::Dbo::UserDatabase<AuthInfo> UserDatabase;

class QRAuthService;
class QRTokenDatabase;

class Session : public dbo::Session
{
public:
  static void configureAuth();

  Session(const std::string& sqliteDb);
  ~Session();

  dbo::ptr<User> user() const;

  Wt::Auth::AbstractUserDatabase& users();
  QRTokenDatabase& qrTokenDatabase();
  Wt::Auth::Login& login() { return login_; }

  static const Wt::Auth::AuthService& auth();
  static const Wt::Auth::PasswordService& passwordAuth();
  static const QRAuthService& qrAuth();
  static const std::vector<const Wt::Auth::OAuthService *>& oAuth();

private:
  dbo::backend::Sqlite3 connection_;
  UserDatabase *users_;
  QRTokenDatabase *qrTokens_;
  Wt::Auth::Login login_;
};

#endif // SESSION_H_
