starting working on ui for multiple users

This commit is contained in:
Ross Mountjoy 2020-02-06 21:31:51 -05:00
parent 71b5f17f83
commit 63f9f4b536
7 changed files with 166 additions and 53 deletions

View File

@ -64,8 +64,12 @@ def home():
return render_template("main/home.html")
@public_route
@main.route("/app_view?<app_id>", methods=["GET"])
def app_view(app_id):
settings = Settings.query.first()
if not check_groups(settings.home_access_groups, current_user):
return redirect(url_for("user_system.login"))
app_db = Apps.query.filter_by(id=app_id).first()
return render_template("main/app-view.html", url=f"{app_db.prefix}{app_db.url}")

View File

@ -4,6 +4,7 @@ from flask_login import current_user
from flask import render_template, request, Blueprint, jsonify, redirect, url_for
from dashmachine.user_system.forms import UserForm
from dashmachine.user_system.utils import add_edit_user
from dashmachine.user_system.models import User
from dashmachine.main.utils import row2dict, public_route, check_groups
from dashmachine.main.read_config import read_config
from dashmachine.main.models import Files, TemplateApps
@ -29,6 +30,7 @@ def settings():
config_form = ConfigForm()
user_form = UserForm()
# user_form.role.choices = [(role, role) for role in settings_db.roles.split(",")]
with open(os.path.join(user_data_folder, "config.ini"), "r") as config_file:
config_form.config.data = config_file.read()
files_html = load_files_html()
@ -36,6 +38,8 @@ def settings():
t_apps = TemplateApps.query.all()
for t_app in t_apps:
template_apps.append(f"{t_app.name}&&{t_app.icon}")
users = User.query.all()
return render_template(
"settings_system/settings.html",
config_form=config_form,
@ -43,6 +47,7 @@ def settings():
user_form=user_form,
template_apps=",".join(template_apps),
version=version,
users=users,
)
@ -93,7 +98,13 @@ def edit_user():
if form.validate_on_submit():
if form.password.data != form.confirm_password.data:
return jsonify(data={"err": "Passwords don't match"})
add_edit_user(form.username.data, form.password.data)
if not form.id.data:
new = True
else:
new = False
add_edit_user(
form.username.data, form.password.data, user_id=form.id.data, new=new
)
else:
err_str = ""
for fieldName, errorMessages in form.errors.items():

View File

@ -4,6 +4,11 @@ d.className += " active theme-primary";
$( document ).ready(function() {
initTCdrop('#images-tcdrop');
$("#config-wiki-modal").modal();
$("#user-modal").modal({
onCloseEnd: function () {
$("#edit-user-form").trigger('reset');
}
});
$("#save-config-btn").on('click', function(e) {
$.ajax({
@ -58,7 +63,7 @@ $( document ).ready(function() {
}
});
$("#edit-user-btn").on('click', function(e) {
$("#save-user-btn").on('click', function(e) {
$.ajax({
url: $(this).attr('data-url'),
type: 'POST',
@ -75,4 +80,12 @@ $( document ).ready(function() {
});
});
$(".edit-user-btn").on('click', function(e) {
$("#user-modal").modal('open');
$("#user-form-username").val($(this).attr("data-username"));
$("#user-form-role").val($(this).attr("data-role"));
$("#user-form-id").val($(this).attr("data-id"));
M.updateTextFields();
});
});

View File

@ -1,7 +1,8 @@
{% extends "main/layout.html" %}
{% from 'global_macros.html' import input, button %}
{% from 'global_macros.html' import input, button, select %}
{% from 'main/tcdrop.html' import tcdrop %}
{% from 'settings_system/config-readme.html' import ConfigReadme %}
{% from 'settings_system/user.html' import UserTab with context %}
{% block page_vendor_css %}
{% endblock page_vendor_css %}
@ -133,51 +134,7 @@
</div>
<div id="user" class="col s12">
<div class="row">
<h5>User</h5>
<form id="edit-user-form">
{{ user_form.hidden_tag() }}
{{ input(
label="Username",
id="user-form-username",
size="s12",
form_obj=user_form.username,
val=current_user.username
) }}
{{ input(
label="Password",
id="user-form-password",
form_obj=user_form.password,
size="s12"
) }}
{{ input(
label="Confirm Password",
id="user-form-confirm_password",
form_obj=user_form.confirm_password,
required='required',
size="s12"
) }}
</form>
{{ button(
icon="save",
float="left",
id="edit-user-btn",
data={'url': url_for('settings_system.edit_user')},
text="save"
) }}
</div>
<div class="row mt-4">
<h5>DashMachine</h5>
<p class="mb-2">version: {{ version }}</p>
</div>
{{ UserTab() }}
</div>
</div>

View File

@ -0,0 +1,88 @@
{% macro UserTab() %}
<div id="user-modal" class="modal">
<div class="modal-content">
<div class="row mt-2">
<div class="col s12">
<form id="edit-user-form">
{{ user_form.hidden_tag() }}
{# {{ select(#}
{# id='user-form-role',#}
{# form_obj=user_form.role,#}
{# size="s12",#}
{# label='Role'#}
{# ) }}#}
{{ input(
label="Username",
id="user-form-username",
size="s12",
form_obj=user_form.username
) }}
{{ input(
label="Password",
id="user-form-password",
form_obj=user_form.password,
size="s12"
) }}
{{ input(
label="Confirm Password",
id="user-form-confirm_password",
form_obj=user_form.confirm_password,
required='required',
size="s12"
) }}
{{ user_form.id(class="hide", id="user-form-id") }}
</form>
{{ button(
icon="save",
float="left",
id="save-user-btn",
class="mb-2",
data={'url': url_for('settings_system.edit_user')},
text="save"
) }}
</div>
</div>
</div>
</div>
<div class="row mt-2">
<div class="col s12">
<h5>Users
<a href="#user-modal" class="modal-trigger">
<i class="material-icons-outlined theme-secondary-text icon-btn ml-2 toggle-config-help" style="position: relative; top: 4px;">add</i>
</a>
</h5>
{% for user in users %}
<div class="card theme-surface-1">
<div class="card-content">
<span style="font-size: 1.3rem">
{{ user.username }}
<span class="theme-secondary-text">{{ user.role }}</span>
</span>
<span class="right pb-2">
<i class="material-icons-outlined icon-btn edit-user-btn"
data-role="{{ user.role }}"
data-id="{{ user.id }}"
data-username="{{ user.username }}">edit</i>
<i class="material-icons-outlined icon-btn">close</i>
</span>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="row mt-4">
<h5>DashMachine</h5>
<p class="mb-2">version: {{ version }}</p>
</div>
{% endmacro %}

View File

@ -1,9 +1,5 @@
from flask_wtf import FlaskForm
from wtforms import (
StringField,
PasswordField,
BooleanField,
)
from wtforms import StringField, PasswordField, BooleanField, SelectField
from wtforms.validators import DataRequired, Length
@ -12,6 +8,10 @@ class UserForm(FlaskForm):
password = PasswordField(validators=[DataRequired(), Length(min=8, max=120)])
# role = SelectField()
id = StringField()
confirm_password = PasswordField()
remember = BooleanField()

View File

@ -0,0 +1,40 @@
"""empty message
Revision ID: 8f5a046465e8
Revises: 45ebff47af9f
Create Date: 2020-02-06 19:51:14.594434
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "8f5a046465e8"
down_revision = "45ebff47af9f"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("api_calls")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"api_calls",
sa.Column("id", sa.INTEGER(), nullable=False),
sa.Column("name", sa.VARCHAR(), nullable=True),
sa.Column("resource", sa.VARCHAR(), nullable=True),
sa.Column("method", sa.VARCHAR(), nullable=True),
sa.Column("payload", sa.VARCHAR(), nullable=True),
sa.Column("authentication", sa.VARCHAR(), nullable=True),
sa.Column("username", sa.VARCHAR(), nullable=True),
sa.Column("password", sa.VARCHAR(), nullable=True),
sa.Column("value_template", sa.VARCHAR(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###