Various fixes + refacto
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
auth_mode(C) 2013 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
namespace Database {
|
||||
|
||||
#define LMS_DATABASE_VERSION 24
|
||||
#define LMS_DATABASE_VERSION 25
|
||||
|
||||
using Version = std::size_t;
|
||||
|
||||
@@ -267,6 +267,11 @@ CREATE TABLE "user_backup" (
|
||||
// Just increment the scan version of the settings to make the next scheduled scan rescan everything
|
||||
ScanSettings::get(*this).modify()->incScanVersion();
|
||||
}
|
||||
else if (version == 24)
|
||||
{
|
||||
// User's AuthMode
|
||||
_session.execute("ALTER TABLE user ADD auth_mode INTEGER NOT NULL DEFAULT(" + std::to_string(static_cast<int>(User::defaultAuthMode)) + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
LMS_LOG(DB, ERROR) << "Database version " << version << " cannot be handled using migration";
|
||||
|
||||
@@ -70,10 +70,8 @@ AuthToken::getByValue(Session& session, const std::string& value)
|
||||
static const std::string playedListName {"__played_tracks__"};
|
||||
static const std::string queuedListName {"__queued_tracks__"};
|
||||
|
||||
User::User(const std::string& loginName, const PasswordHash& passwordHash)
|
||||
User::User(const std::string& loginName)
|
||||
: _loginName {loginName}
|
||||
, _passwordSalt {passwordHash.salt}
|
||||
, _passwordHash {passwordHash.hash}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -96,11 +94,11 @@ User::getDemo(Session& session)
|
||||
}
|
||||
|
||||
User::pointer
|
||||
User::create(Session& session, const std::string& loginName, const PasswordHash& passwordHash)
|
||||
User::create(Session& session, const std::string& loginName)
|
||||
{
|
||||
session.checkUniqueLocked();
|
||||
|
||||
User::pointer user {session.getDboSession().add(std::make_unique<User>(loginName, passwordHash))};
|
||||
User::pointer user {session.getDboSession().add(std::make_unique<User>(loginName))};
|
||||
|
||||
TrackList::create(session, playedListName, TrackList::Type::Internal, false, user);
|
||||
TrackList::create(session, queuedListName, TrackList::Type::Internal, false, user);
|
||||
|
||||
@@ -100,6 +100,12 @@ class User : public Wt::Dbo::Dbo<User>
|
||||
DEMO = 2,
|
||||
};
|
||||
|
||||
enum class AuthMode
|
||||
{
|
||||
Internal = 0,
|
||||
PAM = 1,
|
||||
};
|
||||
|
||||
struct PasswordHash
|
||||
{
|
||||
std::string salt;
|
||||
@@ -137,13 +143,14 @@ class User : public Wt::Dbo::Dbo<User>
|
||||
static inline const Bitrate defaultSubsonicTranscodeBitrate {128000};
|
||||
static inline const UITheme defaultUITheme {UITheme::Dark};
|
||||
static inline const SubsonicArtistListMode defaultSubsonicArtistListMode {SubsonicArtistListMode::AllArtists};
|
||||
static inline const AuthMode defaultAuthMode {AuthMode::Internal};
|
||||
|
||||
|
||||
User() = default;
|
||||
User(const std::string& loginName, const PasswordHash& passwordHash);
|
||||
User(const std::string& loginName);
|
||||
|
||||
// utility
|
||||
static pointer create(Session& session, const std::string& loginName, const PasswordHash& passwordHash);
|
||||
static pointer create(Session& session, const std::string& loginName);
|
||||
|
||||
static pointer getById(Session& session, IdType id);
|
||||
static pointer getByLoginName(Session& session, const std::string& loginName);
|
||||
@@ -165,7 +172,7 @@ class User : public Wt::Dbo::Dbo<User>
|
||||
void setSubsonicTranscodeBitrate(Bitrate bitrate);
|
||||
void setCurPlayingTrackPos(std::size_t pos) { _curPlayingTrackPos = pos; }
|
||||
void setRadio(bool val) { _radio = val; }
|
||||
void setExternalAuth(bool val) { _externalAuth = val; }
|
||||
void setAuthMode(AuthMode mode) { _authMode = mode;}
|
||||
void setRepeatAll(bool val) { _repeatAll = val; }
|
||||
void setUITheme(UITheme uiTheme) { _uiTheme = uiTheme; }
|
||||
void clearAuthTokens();
|
||||
@@ -180,7 +187,7 @@ class User : public Wt::Dbo::Dbo<User>
|
||||
std::size_t getCurPlayingTrackPos() const { return _curPlayingTrackPos; }
|
||||
bool isRepeatAllSet() const { return _repeatAll; }
|
||||
bool isRadioSet() const { return _radio; }
|
||||
bool hasExternalAuth() const { return _externalAuth; }
|
||||
AuthMode getAuthMode() const { return _authMode; }
|
||||
UITheme getUITheme() const { return _uiTheme; }
|
||||
SubsonicArtistListMode getSubsonicArtistListMode() const { return _subsonicArtistListMode; }
|
||||
|
||||
@@ -220,7 +227,7 @@ class User : public Wt::Dbo::Dbo<User>
|
||||
Wt::Dbo::field(a, _curPlayingTrackPos, "cur_playing_track_pos");
|
||||
Wt::Dbo::field(a, _repeatAll, "repeat_all");
|
||||
Wt::Dbo::field(a, _radio, "radio");
|
||||
Wt::Dbo::field(a, _externalAuth, "external_auth");
|
||||
Wt::Dbo::field(a, _authMode, "auth_mode");
|
||||
Wt::Dbo::hasMany(a, _tracklists, Wt::Dbo::ManyToOne, "user");
|
||||
Wt::Dbo::hasMany(a, _starredArtists, Wt::Dbo::ManyToMany, "user_artist_starred", "", Wt::Dbo::OnDeleteCascade);
|
||||
Wt::Dbo::hasMany(a, _starredReleases, Wt::Dbo::ManyToMany, "user_release_starred", "", Wt::Dbo::OnDeleteCascade);
|
||||
@@ -249,8 +256,7 @@ class User : public Wt::Dbo::Dbo<User>
|
||||
int _curPlayingTrackPos {}; // Current track position in queue
|
||||
bool _repeatAll {};
|
||||
bool _radio {};
|
||||
|
||||
bool _externalAuth {false};
|
||||
AuthMode _authMode {defaultAuthMode};
|
||||
|
||||
Wt::Dbo::collection<Wt::Dbo::ptr<TrackList>> _tracklists;
|
||||
Wt::Dbo::collection<Wt::Dbo::ptr<Artist>> _starredArtists;
|
||||
|
||||
Reference in New Issue
Block a user