mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-17 23:07:17 +01:00
Added user_id property to User, and also did some improvements to it's api.
This commit is contained in:
parent
fa768d2474
commit
8236c509c8
@ -39,7 +39,7 @@ Ref<User> UserManagerFile::_get_user_name(const String &user_name) {
|
|||||||
Ref<User> u = _users[i];
|
Ref<User> u = _users[i];
|
||||||
|
|
||||||
if (u.is_valid()) {
|
if (u.is_valid()) {
|
||||||
if (u->get_name_user_input() == user_name) {
|
if (u->get_user_name() == user_name) {
|
||||||
_rw_lock.read_unlock();
|
_rw_lock.read_unlock();
|
||||||
|
|
||||||
return u;
|
return u;
|
||||||
@ -75,7 +75,7 @@ bool UserManagerFile::_is_username_taken(const String &user_name) {
|
|||||||
Ref<User> u = _users[i];
|
Ref<User> u = _users[i];
|
||||||
|
|
||||||
if (u.is_valid()) {
|
if (u.is_valid()) {
|
||||||
if (u->get_name_user_input() == user_name) {
|
if (u->get_user_name() == user_name) {
|
||||||
_rw_lock.read_unlock();
|
_rw_lock.read_unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ bool UserManagerFile::_is_email_taken(const String &email) {
|
|||||||
Ref<User> u = _users[i];
|
Ref<User> u = _users[i];
|
||||||
|
|
||||||
if (u.is_valid()) {
|
if (u.is_valid()) {
|
||||||
if (u->get_email_user_input() == email) {
|
if (u->get_email() == email) {
|
||||||
_rw_lock.read_unlock();
|
_rw_lock.read_unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ Ref<User> UserManagerStatic::_get_user_name(const String &user_name) {
|
|||||||
Ref<User> u = _users[i];
|
Ref<User> u = _users[i];
|
||||||
|
|
||||||
if (u.is_valid()) {
|
if (u.is_valid()) {
|
||||||
if (u->get_name_user_input() == user_name) {
|
if (u->get_user_name() == user_name) {
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ bool UserManagerStatic::_is_username_taken(const String &user_name) {
|
|||||||
Ref<User> u = _users[i];
|
Ref<User> u = _users[i];
|
||||||
|
|
||||||
if (u.is_valid()) {
|
if (u.is_valid()) {
|
||||||
if (u->get_name_user_input() == user_name) {
|
if (u->get_user_name() == user_name) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ bool UserManagerStatic::_is_email_taken(const String &email) {
|
|||||||
Ref<User> u = _users[i];
|
Ref<User> u = _users[i];
|
||||||
|
|
||||||
if (u.is_valid()) {
|
if (u.is_valid()) {
|
||||||
if (u->get_email_user_input() == email) {
|
if (u->get_email() == email) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,8 +106,8 @@ void UserManagerStatic::set_create_user_bind(const bool val) {
|
|||||||
if (val) {
|
if (val) {
|
||||||
Ref<User> u = create_user();
|
Ref<User> u = create_user();
|
||||||
|
|
||||||
u->set_name_user_input(_create_user_name);
|
u->set_user_name(_create_user_name);
|
||||||
u->set_email_user_input(_create_user_email);
|
u->set_email(_create_user_email);
|
||||||
u->create_password(_create_user_password);
|
u->create_password(_create_user_password);
|
||||||
u->save();
|
u->save();
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ Ref<User> UserDB::get_user_name(const String &user_name) {
|
|||||||
Ref<User> u = _users[i];
|
Ref<User> u = _users[i];
|
||||||
|
|
||||||
if (u.is_valid()) {
|
if (u.is_valid()) {
|
||||||
if (u->get_name_user_input() == user_name) {
|
if (u->get_user_name() == user_name) {
|
||||||
_lock.read_unlock();
|
_lock.read_unlock();
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ bool UserDB::is_username_taken(const String &user_name) {
|
|||||||
Ref<User> u = _users[i];
|
Ref<User> u = _users[i];
|
||||||
|
|
||||||
if (u.is_valid()) {
|
if (u.is_valid()) {
|
||||||
if (u->get_name_user_input() == user_name) {
|
if (u->get_user_name() == user_name) {
|
||||||
_lock.read_unlock();
|
_lock.read_unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ bool UserDB::is_email_taken(const String &email) {
|
|||||||
Ref<User> u = _users[i];
|
Ref<User> u = _users[i];
|
||||||
|
|
||||||
if (u.is_valid()) {
|
if (u.is_valid()) {
|
||||||
if (u->get_email_user_input() == email) {
|
if (u->get_email() == email) {
|
||||||
_lock.read_unlock();
|
_lock.read_unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,31 @@
|
|||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "core/class_db.h"
|
#include "core/class_db.h"
|
||||||
|
|
||||||
String User::get_name_user_input() const {
|
int User::get_user_id() const {
|
||||||
return _name_user_input;
|
return _user_id;
|
||||||
}
|
}
|
||||||
void User::set_name_user_input(const String &val) {
|
void User::set_user_id(const int val) {
|
||||||
_name_user_input = val;
|
_user_id = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
String User::get_email_user_input() const {
|
String User::get_user_name() const {
|
||||||
return _email_user_input;
|
return _user_name;
|
||||||
}
|
}
|
||||||
void User::set_email_user_input(const String &val) {
|
void User::set_user_name(const String &val) {
|
||||||
_email_user_input = val;
|
_user_name = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
String User::get_email() const {
|
||||||
|
return _email;
|
||||||
|
}
|
||||||
|
void User::set_email(const String &val) {
|
||||||
|
_email = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
int User::get_rank() const {
|
int User::get_rank() const {
|
||||||
return _rank;
|
return _rank;
|
||||||
}
|
}
|
||||||
void User::set_rank(const int &val) {
|
void User::set_rank(const int val) {
|
||||||
_rank = val;
|
_rank = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +53,7 @@ void User::set_password_hash(const String &val) {
|
|||||||
bool User::get_banned() const {
|
bool User::get_banned() const {
|
||||||
return _banned;
|
return _banned;
|
||||||
}
|
}
|
||||||
void User::set_banned(const bool &val) {
|
void User::set_banned(const bool val) {
|
||||||
_banned = val;
|
_banned = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +67,7 @@ void User::set_password_reset_token(const String &val) {
|
|||||||
bool User::get_locked() const {
|
bool User::get_locked() const {
|
||||||
return _locked;
|
return _locked;
|
||||||
}
|
}
|
||||||
void User::set_locked(const bool &val) {
|
void User::set_locked(const bool val) {
|
||||||
_locked = val;
|
_locked = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,10 +84,11 @@ String User::hash_password(const String &p_password) {
|
|||||||
bool User::_check_password(const String &p_password) {
|
bool User::_check_password(const String &p_password) {
|
||||||
return hash_password(p_password) == get_password_hash();
|
return hash_password(p_password) == get_password_hash();
|
||||||
}
|
}
|
||||||
|
|
||||||
void User::_create_password(const String &p_password) {
|
void User::_create_password(const String &p_password) {
|
||||||
// todo improve a bit
|
// todo improve a bit
|
||||||
set_pre_salt(hash_password(get_name_user_input() + get_email_user_input()));
|
set_pre_salt(hash_password(get_user_name() + get_email()));
|
||||||
set_post_salt(hash_password(get_email_user_input() + get_name_user_input()));
|
set_post_salt(hash_password(get_email() + get_user_name()));
|
||||||
|
|
||||||
set_password_hash(hash_password(p_password));
|
set_password_hash(hash_password(p_password));
|
||||||
}
|
}
|
||||||
@ -107,6 +115,7 @@ void User::write_unlock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
User::User() {
|
User::User() {
|
||||||
|
_user_id = -1;
|
||||||
_rank = 0;
|
_rank = 0;
|
||||||
_banned = false;
|
_banned = false;
|
||||||
_locked = false;
|
_locked = false;
|
||||||
@ -116,13 +125,17 @@ User::~User() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void User::_bind_methods() {
|
void User::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_name_user_input"), &User::get_name_user_input);
|
ClassDB::bind_method(D_METHOD("get_user_id"), &User::get_user_id);
|
||||||
ClassDB::bind_method(D_METHOD("set_name_user_input", "val"), &User::set_name_user_input);
|
ClassDB::bind_method(D_METHOD("set_user_id", "val"), &User::set_user_id);
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "name_user_input"), "set_name_user_input", "get_name_user_input");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "user_id"), "set_user_id", "get_user_id");
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_email_user_input"), &User::get_email_user_input);
|
ClassDB::bind_method(D_METHOD("get_user_name"), &User::get_user_name);
|
||||||
ClassDB::bind_method(D_METHOD("set_email_user_input", "val"), &User::set_email_user_input);
|
ClassDB::bind_method(D_METHOD("set_user_name", "val"), &User::set_user_name);
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "email_user_input"), "set_email_user_input", "get_email_user_input");
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "user_name"), "set_user_name", "get_user_name");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_email"), &User::get_email);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_email", "val"), &User::set_email);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "email"), "set_email", "get_email");
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_rank"), &User::get_rank);
|
ClassDB::bind_method(D_METHOD("get_rank"), &User::get_rank);
|
||||||
ClassDB::bind_method(D_METHOD("set_rank", "val"), &User::set_rank);
|
ClassDB::bind_method(D_METHOD("set_rank", "val"), &User::set_rank);
|
||||||
|
@ -22,14 +22,17 @@ public:
|
|||||||
PERMISSION_NONE = 0
|
PERMISSION_NONE = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
String get_name_user_input() const;
|
int get_user_id() const;
|
||||||
void set_name_user_input(const String &val);
|
void set_user_id(const int val);
|
||||||
|
|
||||||
String get_email_user_input() const;
|
String get_user_name() const;
|
||||||
void set_email_user_input(const String &val);
|
void set_user_name(const String &val);
|
||||||
|
|
||||||
|
String get_email() const;
|
||||||
|
void set_email(const String &val);
|
||||||
|
|
||||||
int get_rank() const;
|
int get_rank() const;
|
||||||
void set_rank(const int &val);
|
void set_rank(const int val);
|
||||||
|
|
||||||
String get_pre_salt() const;
|
String get_pre_salt() const;
|
||||||
void set_pre_salt(const String &val);
|
void set_pre_salt(const String &val);
|
||||||
@ -41,13 +44,13 @@ public:
|
|||||||
void set_password_hash(const String &val);
|
void set_password_hash(const String &val);
|
||||||
|
|
||||||
bool get_banned() const;
|
bool get_banned() const;
|
||||||
void set_banned(const bool &val);
|
void set_banned(const bool val);
|
||||||
|
|
||||||
String get_password_reset_token() const;
|
String get_password_reset_token() const;
|
||||||
void set_password_reset_token(const String &val);
|
void set_password_reset_token(const String &val);
|
||||||
|
|
||||||
bool get_locked() const;
|
bool get_locked() const;
|
||||||
void set_locked(const bool &val);
|
void set_locked(const bool val);
|
||||||
|
|
||||||
bool check_password(const String &p_password);
|
bool check_password(const String &p_password);
|
||||||
void create_password(const String &p_password);
|
void create_password(const String &p_password);
|
||||||
@ -70,8 +73,9 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
String _name_user_input;
|
int _user_id;
|
||||||
String _email_user_input;
|
String _user_name;
|
||||||
|
String _email;
|
||||||
int _rank;
|
int _rank;
|
||||||
String _pre_salt;
|
String _pre_salt;
|
||||||
String _post_salt;
|
String _post_salt;
|
||||||
|
Loading…
Reference in New Issue
Block a user