mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-29 12:29:18 +01:00
Added a few bindings to UserManagerStatic to help with creating users form the editor.
This commit is contained in:
parent
7989cfabc4
commit
0ef9dc8fcf
@ -24,8 +24,12 @@ void UserManagerStatic::_save_user(Ref<User> user) {
|
||||
//With this class Users are serialized via editor properties, ignore
|
||||
}
|
||||
Ref<User> UserManagerStatic::_create_user() {
|
||||
//With this class Users are managed via the editor editor
|
||||
return Ref<User>();
|
||||
Ref<User> u;
|
||||
u.instance();
|
||||
|
||||
_users.push_back(u);
|
||||
|
||||
return u;
|
||||
}
|
||||
bool UserManagerStatic::_is_username_taken(const String &user_name) {
|
||||
for (int i = 0; i < _users.size(); ++i) {
|
||||
@ -74,6 +78,45 @@ void UserManagerStatic::set_users(const Vector<Variant> &users) {
|
||||
}
|
||||
}
|
||||
|
||||
String UserManagerStatic::get_create_user_name_bind() {
|
||||
return _create_user_name;
|
||||
}
|
||||
void UserManagerStatic::set_create_user_name_bind(const String &val) {
|
||||
_create_user_name = val;
|
||||
}
|
||||
|
||||
String UserManagerStatic::get_create_user_email_bind() {
|
||||
return _create_user_email;
|
||||
}
|
||||
void UserManagerStatic::set_create_user_email_bind(const String &val) {
|
||||
_create_user_email = val;
|
||||
}
|
||||
|
||||
String UserManagerStatic::get_create_user_password_bind() {
|
||||
return _create_user_password;
|
||||
}
|
||||
void UserManagerStatic::set_create_user_password_bind(const String &val) {
|
||||
_create_user_password = val;
|
||||
}
|
||||
|
||||
bool UserManagerStatic::get_create_user_bind() {
|
||||
return false;
|
||||
}
|
||||
void UserManagerStatic::set_create_user_bind(const bool val) {
|
||||
if (val) {
|
||||
Ref<User> u = create_user();
|
||||
|
||||
u->set_name_user_input(_create_user_name);
|
||||
u->set_email_user_input(_create_user_email);
|
||||
u->create_password(_create_user_password);
|
||||
u->save();
|
||||
|
||||
_create_user_password = "";
|
||||
_create_user_email = "";
|
||||
_create_user_name = "";
|
||||
}
|
||||
}
|
||||
|
||||
UserManagerStatic::UserManagerStatic() {
|
||||
}
|
||||
|
||||
@ -84,4 +127,20 @@ void UserManagerStatic::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_users"), &UserManagerStatic::get_users);
|
||||
ClassDB::bind_method(D_METHOD("set_users", "users"), &UserManagerStatic::set_users);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "users", PROPERTY_HINT_NONE, "17/17:User", PROPERTY_USAGE_DEFAULT, "User"), "set_users", "get_users");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_create_user_name"), &UserManagerStatic::get_create_user_name_bind);
|
||||
ClassDB::bind_method(D_METHOD("set_create_user_name", "val"), &UserManagerStatic::set_create_user_name_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "create_user_name"), "set_create_user_name", "get_create_user_name");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_create_user_email"), &UserManagerStatic::get_create_user_email_bind);
|
||||
ClassDB::bind_method(D_METHOD("set_create_user_email", "val"), &UserManagerStatic::set_create_user_email_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "create_user_email"), "set_create_user_email", "get_create_user_email");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_create_user_password"), &UserManagerStatic::get_create_user_password_bind);
|
||||
ClassDB::bind_method(D_METHOD("set_create_user_password", "val"), &UserManagerStatic::set_create_user_password_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "create_user_password"), "set_create_user_password", "get_create_user_password");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_create_user"), &UserManagerStatic::get_create_user_bind);
|
||||
ClassDB::bind_method(D_METHOD("set_create_user", "val"), &UserManagerStatic::set_create_user_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "create_user"), "set_create_user", "get_create_user");
|
||||
}
|
||||
|
@ -28,6 +28,18 @@ public:
|
||||
Vector<Variant> get_users();
|
||||
void set_users(const Vector<Variant> &users);
|
||||
|
||||
String get_create_user_name_bind();
|
||||
void set_create_user_name_bind(const String &val);
|
||||
|
||||
String get_create_user_email_bind();
|
||||
void set_create_user_email_bind(const String &val);
|
||||
|
||||
String get_create_user_password_bind();
|
||||
void set_create_user_password_bind(const String &val);
|
||||
|
||||
bool get_create_user_bind();
|
||||
void set_create_user_bind(const bool val);
|
||||
|
||||
UserManagerStatic();
|
||||
~UserManagerStatic();
|
||||
|
||||
@ -35,6 +47,10 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
Vector<Ref<User>> _users;
|
||||
|
||||
String _create_user_name;
|
||||
String _create_user_email;
|
||||
String _create_user_password;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -89,6 +89,10 @@ String User::_hash_password(const String &p_password) {
|
||||
return p.sha256_text();
|
||||
}
|
||||
|
||||
void User::save() {
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
User::User() {
|
||||
_rank = 0;
|
||||
_banned = false;
|
||||
@ -147,6 +151,8 @@ void User::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_create_password", "password"), &User::_create_password);
|
||||
ClassDB::bind_method(D_METHOD("_hash_password", "password"), &User::_hash_password);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("save"), &User::save);
|
||||
|
||||
BIND_ENUM_CONSTANT(PERMISSION_CREATE);
|
||||
BIND_ENUM_CONSTANT(PERMISSION_READ);
|
||||
BIND_ENUM_CONSTANT(PERMISSION_UPDATE);
|
||||
|
@ -56,6 +56,8 @@ public:
|
||||
virtual void _create_password(const String &p_password);
|
||||
virtual String _hash_password(const String &p_password);
|
||||
|
||||
void save();
|
||||
|
||||
User();
|
||||
~User();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user