diff --git a/OVERVIEW.md b/OVERVIEW.md index b9baf5ab..97991b57 100644 --- a/OVERVIEW.md +++ b/OVERVIEW.md @@ -59,7 +59,7 @@ Redis and ARDB overview | | | | | user:tokens | **token** | **user id** | | | | | -| user_metadata:**user id** | **user token** | **token** | +| user_metadata:**user id** | token | **token** | | | change_passwd | **boolean** | | Set Key | Value | diff --git a/var/www/create_default_user.py b/var/www/create_default_user.py index 07dca0d6..1dcc9aed 100755 --- a/var/www/create_default_user.py +++ b/var/www/create_default_user.py @@ -28,6 +28,7 @@ def create_user_db(username_id , password, default=False, role=None, update=Fals else: if default: r_serv_db.hset('user_metadata:{}'.format(username_id), 'change_passwd', True) + r_serv_db.hset('user_metadata:{}'.format(username_id), 'role', role) if role: if role in get_all_role(): r_serv_db.sadd('user_role:{}'.format(role), username_id) @@ -55,6 +56,7 @@ if __name__ == "__main__": # create user token token = secrets.token_urlsafe(41) r_serv_db.hset('user:tokens', token, username) + r_serv_db.hset('user_metadata:{}'.format(username), 'token', token) default_passwd_file = os.path.join(os.environ['AIL_HOME'], 'DEFAULT_PASSWORD') to_write_str = '# Password Generated by default\n# This file is deleted after the first login\n#\nemail=admin@admin.test\npassword=' diff --git a/var/www/modules/settings/Flask_settings.py b/var/www/modules/settings/Flask_settings.py index 0563056a..b6254d98 100644 --- a/var/www/modules/settings/Flask_settings.py +++ b/var/www/modules/settings/Flask_settings.py @@ -5,9 +5,10 @@ Flask functions and routes for the settings modules page ''' from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for -from flask_login import login_required +from flask_login import login_required, current_user import json +import secrets import datetime import git_status @@ -35,6 +36,14 @@ def one(): #def get_v1.5_update_tags_backgroud_status(): # return '38%' +def generate_new_token(user_id): + # create user token + current_token = r_serv_db.hget('user_metadata:{}'.format(user_id), 'token') + r_serv_db.hdel('user:tokens', current_token) + token = secrets.token_urlsafe(41) + r_serv_db.hset('user:tokens', token, user_id) + r_serv_db.hset('user_metadata:{}'.format(user_id), 'token', token) + def get_git_metadata(): dict_git = {} dict_git['current_branch'] = git_status.get_current_branch() @@ -72,6 +81,14 @@ def get_update_metadata(): dict_update['current_background_script_stat'] = r_serv_db.get('ail:current_background_script_stat') return dict_update + +def get_user_metadata(user_id): + user_metadata = {} + user_metadata['email'] = user_id + user_metadata['role'] = r_serv_db.hget('user_metadata:{}'.format(user_id), 'role') + user_metadata['api_key'] = r_serv_db.hget('user_metadata:{}'.format(user_id), 'token') + return user_metadata + # ============= ROUTES ============== @settings.route("/settings/", methods=['GET']) @@ -81,10 +98,21 @@ def settings_page(): current_version = r_serv_db.get('ail:version') update_metadata = get_update_metadata() - return render_template("settings_index.html", git_metadata=git_metadata, current_version=current_version) +@settings.route("/settings/edit_profile", methods=['GET']) +@login_required +def edit_profile(): + user_metadata = get_user_metadata(current_user.get_id()) + return render_template("edit_profile.html", user_metadata=user_metadata) + +@settings.route("/settings/new_token", methods=['GET']) +@login_required +def new_token(): + generate_new_token(current_user.get_id()) + return redirect(url_for('settings.edit_profile')) + @settings.route("/settings/get_background_update_stats_json", methods=['GET']) @login_required diff --git a/var/www/modules/settings/templates/edit_profile.html b/var/www/modules/settings/templates/edit_profile.html new file mode 100644 index 00000000..f0b8d476 --- /dev/null +++ b/var/www/modules/settings/templates/edit_profile.html @@ -0,0 +1,82 @@ + + + + + Server Management - AIL + + + + + + + + + + + + + + + + + + {% include 'nav_bar.html' %} + +
+
+ + {% include 'settings/menu_sidebar.html' %} + +
+ +
+
+
AIL-framework Status :
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + +
Email{{user_metadata['email']}}
Role{{user_metadata['role']}}
API Key + {{user_metadata['api_key']}} + +
+
+
+
+
+ +
+
+ +
+
+
+ + + + + + diff --git a/var/www/modules/settings/templates/settings_index.html b/var/www/modules/settings/templates/settings_index.html index 5b1e055a..5fc21dc5 100644 --- a/var/www/modules/settings/templates/settings_index.html +++ b/var/www/modules/settings/templates/settings_index.html @@ -142,7 +142,8 @@