mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-04-20 01:43:12 +02:00
Replaced std::string and std::vectors in the user module aswell.
This commit is contained in:
parent
e977de894a
commit
c86ed59dd6
@ -19,7 +19,7 @@ void UserController::handle_request_default(Request *request) {
|
||||
}
|
||||
}
|
||||
|
||||
const std::string &segment = request->get_current_path_segment();
|
||||
const String &segment = request->get_current_path_segment();
|
||||
|
||||
if (segment == "") {
|
||||
handle_login_request_default(request);
|
||||
@ -270,7 +270,7 @@ void UserController::render_login_success(Request *request) {
|
||||
}
|
||||
|
||||
void UserController::handle_request(Ref<User> &user, Request *request) {
|
||||
const std::string &segment = request->get_current_path_segment();
|
||||
const String &segment = request->get_current_path_segment();
|
||||
|
||||
if (segment == "") {
|
||||
handle_main_page_request(user, request);
|
||||
|
@ -18,20 +18,20 @@ public:
|
||||
virtual void handle_request_default(Request *request);
|
||||
|
||||
struct LoginRequestData {
|
||||
std::string error_str;
|
||||
std::string uname_val;
|
||||
std::string pass_val;
|
||||
String error_str;
|
||||
String uname_val;
|
||||
String pass_val;
|
||||
};
|
||||
|
||||
virtual void handle_login_request_default(Request *request);
|
||||
virtual void render_login_request_default(Request *request, LoginRequestData *data);
|
||||
|
||||
struct RegisterRequestData {
|
||||
std::string error_str;
|
||||
std::string uname_val;
|
||||
std::string email_val;
|
||||
std::string pass_val;
|
||||
std::string pass_check_val;
|
||||
String error_str;
|
||||
String uname_val;
|
||||
String email_val;
|
||||
String pass_val;
|
||||
String pass_check_val;
|
||||
};
|
||||
|
||||
virtual void handle_register_request_default(Request *request);
|
||||
@ -45,12 +45,12 @@ public:
|
||||
virtual void handle_main_page_request(Ref<User> &user, Request *request);
|
||||
|
||||
struct SettingsRequestData {
|
||||
std::string error_str;
|
||||
String error_str;
|
||||
|
||||
std::string uname_val;
|
||||
std::string email_val;
|
||||
std::string pass_val;
|
||||
std::string pass_check_val;
|
||||
String uname_val;
|
||||
String email_val;
|
||||
String pass_val;
|
||||
String pass_check_val;
|
||||
};
|
||||
|
||||
virtual void handle_settings_request(Ref<User> &user, Request *request);
|
||||
|
@ -45,7 +45,7 @@ Ref<User> UserModel::get_user(const int id) {
|
||||
return user;
|
||||
}
|
||||
|
||||
Ref<User> UserModel::get_user(const std::string &user_name_input) {
|
||||
Ref<User> UserModel::get_user(const String &user_name_input) {
|
||||
if (user_name_input == "") {
|
||||
return Ref<User>();
|
||||
}
|
||||
@ -125,7 +125,7 @@ void UserModel::save_user(Ref<User> &user) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Ref<User> > UserModel::get_all() {
|
||||
Vector<Ref<User> > UserModel::get_all() {
|
||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
||||
|
||||
b->select("id, username, email, rank, pre_salt, post_salt, password_hash, banned, password_reset_token, locked");
|
||||
@ -133,7 +133,7 @@ std::vector<Ref<User> > UserModel::get_all() {
|
||||
b->end_command();
|
||||
//b->print();
|
||||
|
||||
std::vector<Ref<User> > users;
|
||||
Vector<Ref<User> > users;
|
||||
|
||||
Ref<QueryResult> r = b->run();
|
||||
|
||||
@ -158,7 +158,7 @@ std::vector<Ref<User> > UserModel::get_all() {
|
||||
return users;
|
||||
}
|
||||
|
||||
bool UserModel::is_username_taken(const std::string &user_name_input) {
|
||||
bool UserModel::is_username_taken(const String &user_name_input) {
|
||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
||||
|
||||
b->select("id")->from(_table_name)->where("username")->like(user_name_input)->end_command();
|
||||
@ -167,7 +167,7 @@ bool UserModel::is_username_taken(const std::string &user_name_input) {
|
||||
|
||||
return r->next_row();
|
||||
}
|
||||
bool UserModel::is_email_taken(const std::string &email_input) {
|
||||
bool UserModel::is_email_taken(const String &email_input) {
|
||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
||||
|
||||
b->select("id")->from(_table_name)->where("username")->like(email_input)->end_command();
|
||||
@ -177,11 +177,11 @@ bool UserModel::is_email_taken(const std::string &email_input) {
|
||||
return r->next_row();
|
||||
}
|
||||
|
||||
bool UserModel::check_password(const Ref<User> &user, const std::string &p_password) {
|
||||
bool UserModel::check_password(const Ref<User> &user, const String &p_password) {
|
||||
return hash_password(user, p_password) == user->password_hash;
|
||||
}
|
||||
|
||||
void UserModel::create_password(Ref<User> &user, const std::string &p_password) {
|
||||
void UserModel::create_password(Ref<User> &user, const String &p_password) {
|
||||
if (!user.is_valid()) {
|
||||
printf("Error UserModel::create_password !user.is_valid()!\n");
|
||||
return;
|
||||
@ -194,7 +194,7 @@ void UserModel::create_password(Ref<User> &user, const std::string &p_password)
|
||||
user->password_hash = hash_password(user, p_password);
|
||||
}
|
||||
|
||||
std::string UserModel::hash_password(const Ref<User> &user, const std::string &p_password) {
|
||||
String UserModel::hash_password(const Ref<User> &user, const String &p_password) {
|
||||
if (!user.is_valid()) {
|
||||
printf("Error UserModel::hash_password !user.is_valid()!\n");
|
||||
return "";
|
||||
@ -202,9 +202,9 @@ std::string UserModel::hash_password(const Ref<User> &user, const std::string &p
|
||||
|
||||
Ref<SHA256> s = SHA256::get();
|
||||
|
||||
std::string p = user->pre_salt + p_password + user->post_salt;
|
||||
String p = user->pre_salt + p_password + user->post_salt;
|
||||
|
||||
std::string c = s->compute(p);
|
||||
String c = s->compute(p);
|
||||
|
||||
return c;
|
||||
}
|
||||
@ -260,5 +260,5 @@ UserModel::~UserModel() {
|
||||
|
||||
UserModel *UserModel::_self = nullptr;
|
||||
|
||||
std::string UserModel::_path = "./";
|
||||
std::string UserModel::_table_name = "users";
|
||||
String UserModel::_path = "./";
|
||||
String UserModel::_table_name = "users";
|
@ -1,28 +1,29 @@
|
||||
#ifndef USER_MODEL_H
|
||||
#define USER_MODEL_H
|
||||
|
||||
#include "core/string.h"
|
||||
#include "core/containers/vector.h"
|
||||
|
||||
#include "core/object.h"
|
||||
|
||||
#include "user.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class UserModel : public Object {
|
||||
RCPP_OBJECT(UserModel, Object);
|
||||
|
||||
public:
|
||||
Ref<User> get_user(const int id);
|
||||
Ref<User> get_user(const std::string &user_name_input);
|
||||
Ref<User> get_user(const String &user_name_input);
|
||||
void save_user(Ref<User> &user);
|
||||
|
||||
std::vector<Ref<User> > get_all();
|
||||
Vector<Ref<User> > get_all();
|
||||
|
||||
bool is_username_taken(const std::string &user_name_input);
|
||||
bool is_email_taken(const std::string &email_input);
|
||||
bool is_username_taken(const String &user_name_input);
|
||||
bool is_email_taken(const String &email_input);
|
||||
|
||||
virtual bool check_password(const Ref<User> &user, const std::string &p_password);
|
||||
virtual void create_password(Ref<User> &user, const std::string &p_password);
|
||||
virtual std::string hash_password(const Ref<User> &user, const std::string &p_password);
|
||||
virtual bool check_password(const Ref<User> &user, const String &p_password);
|
||||
virtual void create_password(Ref<User> &user, const String &p_password);
|
||||
virtual String hash_password(const Ref<User> &user, const String &p_password);
|
||||
|
||||
virtual void create_table();
|
||||
virtual void drop_table();
|
||||
@ -36,10 +37,10 @@ public:
|
||||
protected:
|
||||
static UserModel *_self;
|
||||
|
||||
std::string _file_path;
|
||||
String _file_path;
|
||||
|
||||
static std::string _path;
|
||||
static std::string _table_name;
|
||||
static String _path;
|
||||
static String _table_name;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user