mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2025-12-07 20:08:53 -06:00
form progress
This commit is contained in:
@@ -15,5 +15,6 @@ login.login_view = 'login'
|
|||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
migrate = Migrate(app, db)
|
migrate = Migrate(app, db)
|
||||||
|
|
||||||
from app import routes, models
|
from app import models
|
||||||
|
from app import routes, dashboard, custom
|
||||||
app.jinja_env.globals.update(get_hidden=routes.get_hidden)
|
app.jinja_env.globals.update(get_hidden=routes.get_hidden)
|
||||||
14
app/custom.py
Normal file
14
app/custom.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from flask import abort
|
||||||
|
from flask_login import current_user
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
def require_role(roles=["User"]):
|
||||||
|
def wrap(func):
|
||||||
|
@wraps(func)
|
||||||
|
def decorated_view(*args, **kwargs):
|
||||||
|
if current_user.is_authenticated:
|
||||||
|
if current_user.has_roles(roles):
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
return abort(401)
|
||||||
|
return decorated_view
|
||||||
|
return wrap
|
||||||
26
app/dashboard.py
Normal file
26
app/dashboard.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from app import app, db, login
|
||||||
|
from app.models import User, Search
|
||||||
|
from app.custom import require_role
|
||||||
|
from flask import render_template, redirect, url_for, request, jsonify
|
||||||
|
from flask_login import current_user, login_required
|
||||||
|
|
||||||
|
@app.route('/dashboard')
|
||||||
|
@login_required
|
||||||
|
def dashboard():
|
||||||
|
return render_template('/dashboard/dashboard.html')
|
||||||
|
|
||||||
|
@app.route('/dashboard/profile_settings')
|
||||||
|
@login_required
|
||||||
|
def profile_settings():
|
||||||
|
return render_template('/dashboard/profile_settings.html')
|
||||||
|
|
||||||
|
@app.route('/dashboard/constants')
|
||||||
|
@login_required
|
||||||
|
@require_role(roles=['Admin'])
|
||||||
|
def constants():
|
||||||
|
return render_template('/dashboard/constants.html')
|
||||||
|
|
||||||
|
@app.route('/dashboard/rbac')
|
||||||
|
@login_required
|
||||||
|
def rbac():
|
||||||
|
return render_template('/dashboard/rbac.html')
|
||||||
@@ -25,3 +25,6 @@ class RegistrationForm(FlaskForm):
|
|||||||
user = User.query.filter_by(email=email.data).first()
|
user = User.query.filter_by(email=email.data).first()
|
||||||
if user is not None:
|
if user is not None:
|
||||||
raise ValidationError('That email address is not available.')
|
raise ValidationError('That email address is not available.')
|
||||||
|
|
||||||
|
class ProfileSettingsForm(FlaskForm):
|
||||||
|
show_email = BooleanField('Show ')
|
||||||
@@ -1,18 +1,9 @@
|
|||||||
|
from flask import abort
|
||||||
from flask_login import UserMixin
|
from flask_login import UserMixin
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from app import db, login
|
from app import db, login
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
def require_role(roles=["User"]):
|
|
||||||
def wrap(func):
|
|
||||||
@wraps(func)
|
|
||||||
def decorated_view(*args, **kwargs):
|
|
||||||
if current_user.is_authenticated:
|
|
||||||
if current_user.has_roles(roles):
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
return abort(401)
|
|
||||||
return decorated_view
|
|
||||||
return wrap
|
|
||||||
@login.user_loader
|
@login.user_loader
|
||||||
class User(UserMixin, db.Model):
|
class User(UserMixin, db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from app import app, db, login
|
from app import app, db, login
|
||||||
from app.models import User, Search, require_role
|
from app.models import User, Search
|
||||||
from app.forms import LoginForm, RegistrationForm
|
from app.forms import LoginForm, RegistrationForm
|
||||||
|
from app.custom import require_role
|
||||||
from werkzeug.urls import url_parse
|
from werkzeug.urls import url_parse
|
||||||
from flask import render_template, redirect, url_for, flash, request, jsonify, abort
|
from flask import render_template, redirect, url_for, flash, request, jsonify, abort
|
||||||
from flask_login import current_user, login_user, logout_user, login_required
|
from flask_login import current_user, login_user, logout_user, login_required
|
||||||
from functools import wraps
|
|
||||||
import requests
|
import requests
|
||||||
import xmltodict
|
import xmltodict
|
||||||
import base64
|
import base64
|
||||||
@@ -21,11 +21,6 @@ def strgen(length): return ''.join(random.choices(list(string.ascii_letters), k=
|
|||||||
def unauthorized(e):
|
def unauthorized(e):
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
@app.route('/dashboard')
|
|
||||||
@login_required
|
|
||||||
def dashboard():
|
|
||||||
return render_template('/dashboard/dashboard.html')
|
|
||||||
|
|
||||||
@app.route('/profile/')
|
@app.route('/profile/')
|
||||||
@login_required
|
@login_required
|
||||||
def profile():
|
def profile():
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% extends 'dashboard_base' %}
|
{% extends '/dashboard/dashboard_base.html' %}
|
||||||
{% set constants_active = True %}
|
{% set constants_active = True %}
|
||||||
{% block dashboard_body %}
|
{% block dashboard_body %}
|
||||||
constants
|
constants
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% extends 'dashboard/dashboard_base.html' %}
|
{% extends '/dashboard/dashboard_base.html' %}
|
||||||
{% set dashboard_home_active = True %}
|
{% set dashboard_home_active = True %}
|
||||||
{% block dashboard_body %}
|
{% block dashboard_body %}
|
||||||
<section></section>
|
<section></section>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<ul class="menu-list">
|
<ul class="menu-list">
|
||||||
<li><a href="{{ url_for('dashboard') }}" {% if dashboard_home_active %}class="is-active"{% endif %}>Home</a></li>
|
<li><a href="{{ url_for('dashboard') }}" {% if dashboard_home_active %}class="is-active"{% endif %}>Home</a></li>
|
||||||
<li><a href="{{ url_for('profile_settings') }}" {% if dashboard_profile_settings_active %}class="is-active"{% endif %}>Profile Settings</a></li>
|
<li><a href="{{ url_for('profile_settings') }}" {% if profile_settings_active %}class="is-active"{% endif %}>Profile Settings</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="menu-list">
|
<ul class="menu-list">
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<ul class="menu-list">
|
<ul class="menu-list">
|
||||||
<li><a href="{{ url_for('constants') }}" {% if constants_active %}class="is-active"{% endif %}>Constants</a></li>
|
<li><a href="{{ url_for('constants') }}" {% if constants_active %}class="is-active"{% endif %}>Constants</a></li>
|
||||||
<li>
|
<li>
|
||||||
<a {% if role_settings_active %}class="is-active"{% endif %}><abbr title="Role Based Access Control">RBAC</abbr> Settings</a>
|
<a href="{{ url_for('rbac') }}" {% if role_settings_active %}class="is-active"{% endif %}>RBAC Settings</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ url_for('rbac') + '#apply-user-roles' }}">Apply Roles to User(s)</a></li>
|
<li><a href="{{ url_for('rbac') + '#apply-user-roles' }}">Apply Roles to User(s)</a></li>
|
||||||
<li><a href="{{ url_for('rbac') + '#view-user-roles' }}">View all Roles</a></li>
|
<li><a href="{{ url_for('rbac') + '#view-user-roles' }}">View all Roles</a></li>
|
||||||
|
|||||||
37
app/templates/dashboard/profile_settings.html
Normal file
37
app/templates/dashboard/profile_settings.html
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{% extends '/dashboard/dashboard_base.html' %}
|
||||||
|
{% set profile_settings_active = True %}
|
||||||
|
{% block head %}
|
||||||
|
{{ super() }}
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('form').submit(function (e) {
|
||||||
|
var url = "{# { url_for('something') } #}"; // send the form data here.
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: url,
|
||||||
|
data: $('form').serialize(), // serializes the form's elements.
|
||||||
|
success: function (data) {
|
||||||
|
console.log(data) // display the returned data in the console.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
e.preventDefault(); // block the traditional submission of the form.
|
||||||
|
});
|
||||||
|
// Inject our CSRF token into our AJAX request.
|
||||||
|
$.ajaxSetup({
|
||||||
|
beforeSend: function (xhr, settings) {
|
||||||
|
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
|
||||||
|
xhr.setRequestHeader("X-CSRFToken", "{#{ form.csrf_token._value() }#}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock head %}
|
||||||
|
{% block dashboard_body %}
|
||||||
|
<section>
|
||||||
|
<h1 class="title">Profile Settings</h1>
|
||||||
|
<span>
|
||||||
|
form goes here nibba
|
||||||
|
</span>
|
||||||
|
</section>
|
||||||
|
{% endblock dashboard_body %}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{% extends 'dashboard_base.html' %}
|
{% extends '/dashboard/dashboard_base.html' %}
|
||||||
{% set role_settings_active = True %}
|
{% set role_settings_active = True %}
|
||||||
{% block dashboard_body %}
|
{% block dashboard_body %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user