User creation
FossilOrigin-Name: ef5ff920c1aed33ef696f8335515d7dd94d6fc4e0405bb5b7e884808e3bf7234
This commit is contained in:
parent
a9fdab5469
commit
0b2db03e72
5 changed files with 32 additions and 7 deletions
|
@ -41,3 +41,8 @@ User Database::get_user(const std::string& acct)
|
|||
std::cerr << "Database::get_user()" << std::endl;
|
||||
return {};
|
||||
}
|
||||
|
||||
void Database::create_user(const User& props)
|
||||
{
|
||||
std::cerr << "Database::create_user()" << std::endl;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@ namespace DB
|
|||
virtual User get_user(unsigned long id);
|
||||
virtual User get_user(const std::string& acct);
|
||||
|
||||
virtual void create_user(const User& props);
|
||||
|
||||
/// These are just enums for Configuration and stuff, but Polymorphism
|
||||
/// handles the typing stuff already
|
||||
enum class Type
|
||||
{
|
||||
SQLite,
|
||||
|
|
|
@ -94,7 +94,7 @@ int SQLite::sqlite_exec(SQLiteCacheIndex idx,
|
|||
|
||||
while ((code = sqlite3_step(stmt)) == SQLITE_ROW)
|
||||
{
|
||||
func(stmt);
|
||||
if (func) func(stmt);
|
||||
++query_count;
|
||||
}
|
||||
|
||||
|
@ -104,6 +104,7 @@ int SQLite::sqlite_exec(SQLiteCacheIndex idx,
|
|||
Logger::instance().log("SQLite database is busy!", Logger::Level::DEBUG);
|
||||
break;
|
||||
case SQLITE_ERROR:
|
||||
default:
|
||||
case SQLITE_MISUSE:
|
||||
{
|
||||
const std::string err_msg = "Couldn't exec query: "s + std::string(sqlite3_errmsg(db));
|
||||
|
@ -111,7 +112,6 @@ int SQLite::sqlite_exec(SQLiteCacheIndex idx,
|
|||
throw std::runtime_error(err_msg);
|
||||
}
|
||||
case SQLITE_DONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -161,6 +161,19 @@ User SQLite::get_user(unsigned long id)
|
|||
return luser;
|
||||
}
|
||||
|
||||
void SQLite::create_user(const User& p)
|
||||
{
|
||||
// INSERT INTO users (local, display_name, acct, bio, created_at) VALUES (TRUE, 'Test user', 'test1', 'sneed!!!', unixepoch());
|
||||
|
||||
sqlite_compile_to_cache(CREATE_USER, "INSERT INTO users ( local, email, display_name, acct, bio, created_at, updated_at, birthday, key )"
|
||||
"VALUES ( ?1, ?2, ?3, ?4, ?5, unixepoch(), unixepoch(), ?6, ?7 )");
|
||||
|
||||
sqlite_exec(CREATE_USER,
|
||||
{p.local, p.email, p.display_name, p.acct,
|
||||
p.bio, p.birthday, "the key lole"},
|
||||
nullptr);
|
||||
}
|
||||
|
||||
User SQLite::get_user(const std::string& acct)
|
||||
{
|
||||
User luser{0, {}, false, {}, acct, {}, {}, {}};
|
||||
|
@ -228,6 +241,7 @@ CREATE TABLE IF NOT EXISTS users (
|
|||
janny_level INTEGER DEFAULT 0,
|
||||
follow_move BOOLEAN DEFAULT FALSE,
|
||||
instance_id INTEGER,
|
||||
unique (acct),
|
||||
FOREIGN KEY(instance_id) REFERENCES instances(id)
|
||||
)
|
||||
)sql",
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace DB
|
|||
enum SQLiteCacheIndex {
|
||||
GET_USER_BY_ID = 0,
|
||||
GET_USER_BY_ACCT,
|
||||
CREATE_USER,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
|
@ -46,9 +47,10 @@ namespace DB
|
|||
explicit SQLite(std::filesystem::path path);
|
||||
virtual ~SQLite();
|
||||
|
||||
virtual bool try_migration() override;
|
||||
virtual User get_user(unsigned long id) override;
|
||||
virtual User get_user(const std::string& acct) override;
|
||||
virtual bool try_migration() override final;
|
||||
virtual User get_user(unsigned long id) override final;
|
||||
virtual User get_user(const std::string& acct) override final;
|
||||
virtual void create_user(const User& props) override final;
|
||||
private:
|
||||
/**
|
||||
* @brief Executes an SQL statement
|
||||
|
|
|
@ -25,10 +25,10 @@ class User
|
|||
public:
|
||||
unsigned long id;
|
||||
std::string email;
|
||||
bool is_local;
|
||||
bool local;
|
||||
std::string bio;
|
||||
std::string acct;
|
||||
std::string birthday;
|
||||
int birthday;
|
||||
std::string display_name;
|
||||
std::string key;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue