mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-31 12:56:11 +01:00
Initial back end support for user based languages
This commit is contained in:
parent
e976593d83
commit
56deaa0bcb
@ -65,6 +65,7 @@ class Users_Controller:
|
|||||||
elif base_data[key] != user_data[key]:
|
elif base_data[key] != user_data[key]:
|
||||||
up_data[key] = user_data[key]
|
up_data[key] = user_data[key]
|
||||||
up_data['last_update'] = helper.get_time_as_string()
|
up_data['last_update'] = helper.get_time_as_string()
|
||||||
|
up_data['lang'] = user_data['lang']
|
||||||
logger.debug("user: {} +role:{} -role:{}".format(user_data, added_roles, removed_roles))
|
logger.debug("user: {} +role:{} -role:{}".format(user_data, added_roles, removed_roles))
|
||||||
for role in added_roles:
|
for role in added_roles:
|
||||||
users_helper.get_or_create(user_id=user_id, role_id=role)
|
users_helper.get_or_create(user_id=user_id, role_id=role)
|
||||||
|
@ -40,7 +40,8 @@ class Users(Model):
|
|||||||
password = CharField(default="")
|
password = CharField(default="")
|
||||||
enabled = BooleanField(default=True)
|
enabled = BooleanField(default=True)
|
||||||
superuser = BooleanField(default=False)
|
superuser = BooleanField(default=False)
|
||||||
api_token = CharField(default="", unique=True, index=True) # we may need to revisit this
|
api_token = CharField(default="", unique=True, index=True), # we may need to revisit this
|
||||||
|
lang = CharField(default='en_EN')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
table_name = "users"
|
table_name = "users"
|
||||||
@ -81,6 +82,10 @@ class helper_users:
|
|||||||
except DoesNotExist:
|
except DoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_user_lang_by_id(user_id):
|
||||||
|
return Users.get(Users.user_id == user_id).lang
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_user_by_api_token(token: str):
|
def get_user_by_api_token(token: str):
|
||||||
query = Users.select().where(Users.api_token == token)
|
query = Users.select().where(Users.api_token == token)
|
||||||
@ -114,6 +119,7 @@ class helper_users:
|
|||||||
'api_token': None,
|
'api_token': None,
|
||||||
'roles': [],
|
'roles': [],
|
||||||
'servers': [],
|
'servers': [],
|
||||||
|
'lang': 'en_EN'
|
||||||
}
|
}
|
||||||
user = model_to_dict(Users.get(Users.user_id == user_id))
|
user = model_to_dict(Users.get(Users.user_id == user_id))
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from app.classes.shared.translation import Translation
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import tornado.web
|
import tornado.web
|
||||||
@ -363,6 +364,11 @@ class PanelHandler(BaseHandler):
|
|||||||
page_data['permissions_all'] = self.controller.crafty_perms.list_defined_crafty_permissions()
|
page_data['permissions_all'] = self.controller.crafty_perms.list_defined_crafty_permissions()
|
||||||
page_data['permissions_list'] = set()
|
page_data['permissions_list'] = set()
|
||||||
page_data['quantity_server'] = self.controller.crafty_perms.list_all_crafty_permissions_quantity_limits()
|
page_data['quantity_server'] = self.controller.crafty_perms.list_all_crafty_permissions_quantity_limits()
|
||||||
|
page_data['languages'] = []
|
||||||
|
for file in os.listdir(os.path.join(helper.root_dir, 'app', 'translations')):
|
||||||
|
if file.endswith('.json'):
|
||||||
|
page_data['languages'].append(file.split('.')[0])
|
||||||
|
print(page_data['languages'])
|
||||||
|
|
||||||
template = "panel/panel_edit_user.html"
|
template = "panel/panel_edit_user.html"
|
||||||
|
|
||||||
@ -382,6 +388,10 @@ class PanelHandler(BaseHandler):
|
|||||||
page_data['permissions_all'] = self.controller.crafty_perms.list_defined_crafty_permissions()
|
page_data['permissions_all'] = self.controller.crafty_perms.list_defined_crafty_permissions()
|
||||||
page_data['permissions_list'] = self.controller.crafty_perms.get_crafty_permissions_list(user_id)
|
page_data['permissions_list'] = self.controller.crafty_perms.get_crafty_permissions_list(user_id)
|
||||||
page_data['quantity_server'] = self.controller.crafty_perms.list_crafty_permissions_quantity_limits(user_id)
|
page_data['quantity_server'] = self.controller.crafty_perms.list_crafty_permissions_quantity_limits(user_id)
|
||||||
|
page_data['languages'] = []
|
||||||
|
for file in os.listdir(os.path.join(helper.root_dir, 'app', 'translations')):
|
||||||
|
if file.endswith('.json'):
|
||||||
|
page_data['languages'].append(file.split('.')[0])
|
||||||
|
|
||||||
if user_id is None:
|
if user_id is None:
|
||||||
self.redirect("/panel/error?error=Invalid User ID")
|
self.redirect("/panel/error?error=Invalid User ID")
|
||||||
@ -690,6 +700,7 @@ class PanelHandler(BaseHandler):
|
|||||||
password1 = bleach.clean(self.get_argument('password1', None))
|
password1 = bleach.clean(self.get_argument('password1', None))
|
||||||
enabled = int(float(self.get_argument('enabled', '0')))
|
enabled = int(float(self.get_argument('enabled', '0')))
|
||||||
regen_api = int(float(self.get_argument('regen_api', '0')))
|
regen_api = int(float(self.get_argument('regen_api', '0')))
|
||||||
|
lang = bleach.clean(self.get_argument('lang'), 'en_EN')
|
||||||
|
|
||||||
if Enum_Permissions_Crafty.User_Config not in exec_user_crafty_permissions:
|
if Enum_Permissions_Crafty.User_Config not in exec_user_crafty_permissions:
|
||||||
if user_id != exec_user_id:
|
if user_id != exec_user_id:
|
||||||
@ -762,6 +773,7 @@ class PanelHandler(BaseHandler):
|
|||||||
"enabled": enabled,
|
"enabled": enabled,
|
||||||
"regen_api": regen_api,
|
"regen_api": regen_api,
|
||||||
"roles": roles,
|
"roles": roles,
|
||||||
|
"lang": lang
|
||||||
}
|
}
|
||||||
user_crafty_data = {
|
user_crafty_data = {
|
||||||
"permissions_mask": permissions_mask,
|
"permissions_mask": permissions_mask,
|
||||||
@ -780,7 +792,8 @@ class PanelHandler(BaseHandler):
|
|||||||
username = bleach.clean(self.get_argument('username', None))
|
username = bleach.clean(self.get_argument('username', None))
|
||||||
password0 = bleach.clean(self.get_argument('password0', None))
|
password0 = bleach.clean(self.get_argument('password0', None))
|
||||||
password1 = bleach.clean(self.get_argument('password1', None))
|
password1 = bleach.clean(self.get_argument('password1', None))
|
||||||
enabled = int(float(self.get_argument('enabled', '0')))
|
enabled = int(float(self.get_argument('enabled', '0'))),
|
||||||
|
lang = bleach.clean(self.get_argument('lang', 'en_EN'))
|
||||||
|
|
||||||
if Enum_Permissions_Crafty.User_Config not in exec_user_crafty_permissions:
|
if Enum_Permissions_Crafty.User_Config not in exec_user_crafty_permissions:
|
||||||
self.redirect("/panel/error?error=Unauthorized access: not a user editor")
|
self.redirect("/panel/error?error=Unauthorized access: not a user editor")
|
||||||
@ -832,6 +845,7 @@ class PanelHandler(BaseHandler):
|
|||||||
user_id = self.controller.users.add_user(username, password=password0, enabled=enabled)
|
user_id = self.controller.users.add_user(username, password=password0, enabled=enabled)
|
||||||
user_data = {
|
user_data = {
|
||||||
"roles": roles,
|
"roles": roles,
|
||||||
|
'lang': lang
|
||||||
}
|
}
|
||||||
user_crafty_data = {
|
user_crafty_data = {
|
||||||
"permissions_mask": permissions_mask,
|
"permissions_mask": permissions_mask,
|
||||||
|
@ -54,9 +54,9 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 col-sm-12">
|
<div class="col-md-6 col-sm-12">
|
||||||
{% if data['new_user'] %}
|
{% if data['new_user'] %}
|
||||||
<form class="forms-sample" method="post" action="/panel/add_user">
|
<form id="user_form" class="forms-sample" method="post" action="/panel/add_user">
|
||||||
{% else %}
|
{% else %}
|
||||||
<form class="forms-sample" method="post" action="/panel/edit_user">
|
<form id="user_form" class="forms-sample" method="post" action="/panel/edit_user">
|
||||||
{% end %}
|
{% end %}
|
||||||
{% raw xsrf_form_html() %}
|
{% raw xsrf_form_html() %}
|
||||||
<input type="hidden" name="id" value="{{ data['user']['user_id'] }}">
|
<input type="hidden" name="id" value="{{ data['user']['user_id'] }}">
|
||||||
@ -80,6 +80,14 @@
|
|||||||
<label for="password1">Repeat Password <small class="text-muted ml-1"> - leave blank to don't change</small> </label>
|
<label for="password1">Repeat Password <small class="text-muted ml-1"> - leave blank to don't change</small> </label>
|
||||||
<input type="password" class="form-control" name="password1" id="password1" value="" placeholder="Repeat Password" >
|
<input type="password" class="form-control" name="password1" id="password1" value="" placeholder="Repeat Password" >
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="language">User Language:</label>
|
||||||
|
<select id="language" name="language" form="user_form">
|
||||||
|
{% for lang in data['languages'] %}
|
||||||
|
<option value="{{lang}}">{{lang}}</option>
|
||||||
|
{% end %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user