25 #include "core/auth/Token_odb.h"    28 #include "core/auth/User_odb.h"    36 #include <boost/algorithm/string.hpp>    37 #include <odb/object-result.hxx>    38 #include <odb/session.hxx>    51     ASSERT_LOG(token, 
"nullptr passed when excepting non-null token.");
    54     using namespace odb::core;
    55     odb::transaction t(
server_.
db()->begin());
    63     using namespace odb::core;
    64     using query = odb::query<Auth::Token>;
    67     transaction t(db->begin());
    71     if (token && token->is_valid())
    74         token->expire_in(std::chrono::minutes(20));
    83                                                  const std::string &password)
 const    86     using namespace odb::core;
    87     using query = odb::query<Auth::User>;
    90         transaction t(db->begin());
    92         auto username_lowercase = boost::algorithm::to_lower_copy(username);
    94             db->query_one<
Auth::User>(query::username == username_lowercase);
    95         if (user && user->verify_password(password))
    99             auto token = std::make_shared<Auth::Token>(
gen_uuid(), user);
   101             token->expire_in(std::chrono::minutes(20));
   105             if (user->username() == 
"admin")
   107                 if (
const auto &mailer =
   111                     mail.
title = 
"Admin Connected";
   112                     mail.
body  = 
"The user `admin` logged in !";
   113                     mailer->async_send_to_admin(mail);
   125     const auto &validity = u.
validity();
   126     if (!validity.is_enabled())
   128     if (!validity.is_in_range())
   130             BUILD_STR(
"This user account is not currently active."));
 
An authentication token used for authenticating a user against Leosac. 
 
std::shared_ptr< Token > TokenPtr
 
Acts like an odb::session, with the exception that it will save the current active session (if any) a...
 
This is the header file for a generated source file, GitSHA1.cpp. 
 
void invalidate_token(Auth::TokenPtr token) const
Invalidate the authentication token, removing it from the database. 
 
ServiceRegistry & get_service_registry()
A function to retrieve the ServiceRegistry from pretty much anywhere. 
 
Auth::TokenPtr authenticate_token(const std::string &token_str) const
Attempt to authenticate with an authentication token. 
 
void enforce_user_enabled(const Auth::User &u) const
Make sure the User u is authorized to log in. 
 
The implementation class that runs the websocket server. 
 
DBPtr db()
Retrieve database handle. 
 
std::shared_ptr< User > UserPtr
 
Auth::TokenPtr authenticate_credentials(const std::string &username, const std::string &password) const
Attempt to authenticate with username/password credential and generate an authentication token...
 
All modules that provides features to Leosac shall be in this namespace. 
 
#define ASSERT_LOG(cond, msg)
 
std::string gen_uuid()
Generate a new UUID. 
 
Provide ODB magic to be able to store an Leosac::Audit::EventType (FlagSet) object. 
 
std::shared_ptr< ServiceInterface > get_service() const
Retrieve the service instance implementing the ServiceInterface, or nullptr if no such service was re...
 
#define BUILD_STR(param)
Internal macro. 
 
A base class for Leosac specific exception. 
 
Reference interface for SMTP module. 
 
WSServer & server_
Reference to the Websocket server. 
 
const ValidityInfo & validity() const