/*
* Copyright (C) 2013 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see .
*/
#include "DatabaseHandler.hpp"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "utils/Logger.hpp"
#include "Artist.hpp"
#include "Cluster.hpp"
#include "Release.hpp"
#include "ScanSettings.hpp"
#include "SimilaritySettings.hpp"
#include "Track.hpp"
#include "TrackList.hpp"
#include "TrackFeatures.hpp"
namespace Database {
namespace {
Wt::Auth::AuthService authService;
Wt::Auth::PasswordService passwordService(authService);
}
void
Handler::configureAuth(void)
{
authService.setEmailVerificationEnabled(false);
authService.setAuthTokensEnabled(true, "lmsauth");
authService.setAuthTokenValidity(24 * 60 * 365); // A year
authService.setIdentityPolicy(Wt::Auth::IdentityPolicy::LoginName);
authService.setRandomTokenLength(32);
#if WT_VERSION < 0X04000300
authService.setTokenHashFunction(new Wt::Auth::BCryptHashFunction(8));
#else
authService.setTokenHashFunction(std::make_unique(8));
#endif
auto verifier = std::make_unique();
verifier->addHashFunction(std::make_unique(8));
passwordService.setVerifier(std::move(verifier));
passwordService.setAttemptThrottlingEnabled(true);
auto strengthValidator = std::make_unique();
// Reduce some constraints...
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::PassPhrase, 4);
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::OneCharClass, 4);
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::TwoCharClass, 4);
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::ThreeCharClass, 4 );
strengthValidator->setMinimumLength( Wt::Auth::PasswordStrengthType::FourCharClass, 4 );
passwordService.setStrengthValidator(std::move(strengthValidator));
}
const Wt::Auth::AuthService&
Handler::getAuthService()
{
return authService;
}
const Wt::Auth::PasswordService&
Handler::getPasswordService()
{
return passwordService;
}
Handler::Handler(Wt::Dbo::SqlConnectionPool& connectionPool)
{
_session.setConnectionPool(connectionPool);
_session.mapClass("artist");
_session.mapClass("cluster");
_session.mapClass("cluster_type");
_session.mapClass("tracklist");
_session.mapClass("tracklist_entry");
_session.mapClass("release");
_session.mapClass