mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2025-12-07 03:16:58 -06:00
api
This commit is contained in:
@@ -21,8 +21,13 @@ def profile_settings():
|
|||||||
def profile_settings_submit():
|
def profile_settings_submit():
|
||||||
form = ProfileSettingsForm()
|
form = ProfileSettingsForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
return jsonify(data={'message' : 'hello {}'.format(form.show_email.data)})
|
data = {
|
||||||
return '$'
|
'show_email' : form.show_email.data or None,
|
||||||
|
'profile_picture_file' : request.files
|
||||||
|
}
|
||||||
|
return jsonify(data=data)
|
||||||
|
return '{}'
|
||||||
|
|
||||||
@app.route('/dashboard/constants')
|
@app.route('/dashboard/constants')
|
||||||
@login_required
|
@login_required
|
||||||
@require_role(roles=['Admin'])
|
@require_role(roles=['Admin'])
|
||||||
|
|||||||
10
app/forms.py
10
app/forms.py
@@ -1,6 +1,6 @@
|
|||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField, RadioField
|
from wtforms import StringField, PasswordField, BooleanField, SubmitField, RadioField, FileField
|
||||||
from wtforms.validators import ValidationError, DataRequired, EqualTo, Email
|
from wtforms.validators import ValidationError, DataRequired, EqualTo, Email, URL
|
||||||
from app.models import User
|
from app.models import User
|
||||||
|
|
||||||
class LoginForm(FlaskForm):
|
class LoginForm(FlaskForm):
|
||||||
@@ -28,6 +28,10 @@ class RegistrationForm(FlaskForm):
|
|||||||
|
|
||||||
class ProfileSettingsForm(FlaskForm):
|
class ProfileSettingsForm(FlaskForm):
|
||||||
show_email = RadioField('Show Email', default='registered', choices=[('public', 'Public'), ('registered', 'Registered Users Only'), ('hidden', 'Hidden')])
|
show_email = RadioField('Show Email', default='registered', choices=[('public', 'Public'), ('registered', 'Registered Users Only'), ('hidden', 'Hidden')])
|
||||||
profile_picture_file = FileField('Upload Profile Picture')
|
|
||||||
submit = SubmitField('Save Profile Settings')
|
submit = SubmitField('Save Profile Settings')
|
||||||
|
|
||||||
|
class ProfilePictureForm(FlaskForm):
|
||||||
|
profile_picture_file = FileField('Upload Profile Picture')
|
||||||
|
profile_picture_url = StringField('Use URL for Profile Picture', validators=[URL()])
|
||||||
|
submit = SubmitField('Submit Profile Picture')
|
||||||
@@ -9,10 +9,14 @@ class User(UserMixin, db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
username = db.Column(db.String(64), index=True, unique=True)
|
username = db.Column(db.String(64), index=True, unique=True)
|
||||||
email = db.Column(db.String(120), index=True, unique=True)
|
email = db.Column(db.String(120), index=True, unique=True)
|
||||||
|
register_timestamp = db.Column(db.DateTime, default=datetime.utcnow)
|
||||||
password_hash = db.Column(db.String(64))
|
password_hash = db.Column(db.String(64))
|
||||||
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
||||||
search_history = db.relationship('Search', backref='user', lazy='dynamic')
|
search_history = db.relationship('Search', backref='user', lazy='dynamic')
|
||||||
uroles = db.Column(db.String(80), default='')
|
uroles = db.Column(db.String(80), default='')
|
||||||
|
about_me = db.Column(db.String(320))
|
||||||
|
last_seen = db.Column(db.DateTime, default=datetime.utcnow)
|
||||||
|
show_email = db.Column
|
||||||
|
|
||||||
def set_password(self, password):
|
def set_password(self, password):
|
||||||
self.password_hash = generate_password_hash(password)
|
self.password_hash = generate_password_hash(password)
|
||||||
@@ -22,10 +26,36 @@ class User(UserMixin, db.Model):
|
|||||||
raise "{} has no password_hash set!".format(self.__repr__())
|
raise "{} has no password_hash set!".format(self.__repr__())
|
||||||
return check_password_hash(self.password_hash, password)
|
return check_password_hash(self.password_hash, password)
|
||||||
|
|
||||||
|
# Retains order while making sure that there are no duplicate role values and they are capitalized
|
||||||
|
def post_role_processing(self):
|
||||||
|
user_roles = self.uroles.split(' ')
|
||||||
|
user_roles = list(dict.fromkeys(user_roles))
|
||||||
|
self.uroles = ' '.join([role.title() for role in user_roles])
|
||||||
|
|
||||||
|
def delete_role(self, role):
|
||||||
|
return self.delete_roles([role])
|
||||||
|
|
||||||
|
# Will return True if successful, else False if a role didn't exist
|
||||||
|
def delete_roles(self, roles, ignore=True):
|
||||||
|
user_roles = self.uroles.split(' ')
|
||||||
|
success = True
|
||||||
|
for role in roles:
|
||||||
|
try:
|
||||||
|
user_roles.remove(role)
|
||||||
|
except ValueError as e:
|
||||||
|
if not ignore:
|
||||||
|
raise e
|
||||||
|
success = False
|
||||||
|
return success
|
||||||
|
|
||||||
|
|
||||||
def get_roles(self):
|
def get_roles(self):
|
||||||
return self.uroles.split(' ')
|
return self.uroles.split(' ')
|
||||||
|
|
||||||
def add_roles(self, roles):
|
def add_role(self, role):
|
||||||
|
self.add_roles([role])
|
||||||
|
|
||||||
|
def add_roles(self, roles, postprocess=True):
|
||||||
user_roles = self.uroles.split(' ')
|
user_roles = self.uroles.split(' ')
|
||||||
if type(roles) == str:
|
if type(roles) == str:
|
||||||
user_roles.append(roles)
|
user_roles.append(roles)
|
||||||
@@ -33,6 +63,11 @@ class User(UserMixin, db.Model):
|
|||||||
user_roles.extend(roles)
|
user_roles.extend(roles)
|
||||||
user_roles = ' '.join(user_roles)
|
user_roles = ' '.join(user_roles)
|
||||||
self.uroles = user_roles
|
self.uroles = user_roles
|
||||||
|
if postprocess:
|
||||||
|
self.post_role_processing()
|
||||||
|
|
||||||
|
def has_role(self, role):
|
||||||
|
return self.has_roles([role])
|
||||||
|
|
||||||
# Input: ['Insane', ['Fortunate', 'Blessed']]
|
# Input: ['Insane', ['Fortunate', 'Blessed']]
|
||||||
# Meaning: Must have 'Insane' role, as well as 'Fortunate' or 'Blessed' roles.
|
# Meaning: Must have 'Insane' role, as well as 'Fortunate' or 'Blessed' roles.
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ import json
|
|||||||
|
|
||||||
fake = faker.Faker()
|
fake = faker.Faker()
|
||||||
|
|
||||||
def strgen(length): return ''.join(random.choices(list(string.ascii_letters), k=length))
|
def strgen(length):
|
||||||
|
return ''.join(random.choices(list(string.ascii_letters), k=length))
|
||||||
|
|
||||||
@app.errorhandler(401)
|
@app.errorhandler(401)
|
||||||
def unauthorized(e):
|
def unauthorized(e):
|
||||||
@@ -26,6 +27,10 @@ def unauthorized(e):
|
|||||||
def profile():
|
def profile():
|
||||||
return render_template('profile.html')
|
return render_template('profile.html')
|
||||||
|
|
||||||
|
@app.route('/api/')
|
||||||
|
def api():
|
||||||
|
return 'fuckoff bots'
|
||||||
|
|
||||||
@app.route('/userinfo/')
|
@app.route('/userinfo/')
|
||||||
def user_info():
|
def user_info():
|
||||||
prepare = {
|
prepare = {
|
||||||
|
|||||||
2
app/static/robots.txt
Normal file
2
app/static/robots.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
User-agent: *
|
||||||
|
Disallow: /
|
||||||
@@ -127,7 +127,7 @@ Color = Bulma Color Type of the Message Box
|
|||||||
<div class="navbar-text">Login</div>
|
<div class="navbar-text">Login</div>
|
||||||
</a>
|
</a>
|
||||||
<a class="navbar-item" href="{{ url_for('register') }}">
|
<a class="navbar-item" href="{{ url_for('register') }}">
|
||||||
<span class="navbar-fa-icon fas fa-clipboard-list"></span>
|
<span class="navbar-fa-icon fas fa-pen"></span>
|
||||||
<div class="navbar-text">Register</div>
|
<div class="navbar-text">Register</div>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -8,10 +8,12 @@
|
|||||||
</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 profile_settings_active %}class="is-active"{% endif %}>Profile Settings</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
<p class="menu-label">
|
||||||
|
Settings
|
||||||
|
</p>
|
||||||
<ul class="menu-list">
|
<ul class="menu-list">
|
||||||
|
<li><a href="{{ url_for('profile_settings') }}" {% if profile_settings_active %}class="is-active"{% endif %}>Profile Settings</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="menu-label">
|
<p class="menu-label">
|
||||||
Administration
|
Administration
|
||||||
@@ -28,7 +30,8 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column"></div>
|
||||||
|
<div class="column is-two-thirds">
|
||||||
{% block dashboard_body %}
|
{% block dashboard_body %}
|
||||||
|
|
||||||
{% endblock dashboard_body %}
|
{% endblock dashboard_body %}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
{{ super() }}
|
{{ super() }}
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('form').submit(function (e) {
|
$('#form-ajax').submit(function (e) {
|
||||||
var url = "{{ url_for('profile_settings_submit') }}"; // send the form data here.
|
var url = "{{ url_for('profile_settings_submit') }}"; // send the form data here.
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@@ -26,17 +26,43 @@
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
<style type="text/css">
|
||||||
|
.tab-left {
|
||||||
|
padding-left: 3rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
{% endblock head %}
|
{% endblock head %}
|
||||||
{% block dashboard_body %}
|
{% block dashboard_body %}
|
||||||
<section>
|
<section>
|
||||||
<h1 class="title">Profile Settings</h1>
|
<h1 class="title">Profile Settings</h1>
|
||||||
<form action="" method="POST" novalidate>
|
<form class="form-ajax" action="" method="POST" novalidate>
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
<div class="field">
|
<div class="field tab-left">
|
||||||
{{ form.show_email.label }}
|
<h4 class="title is-4">{{ form.show_email.label }}</h4>
|
||||||
{{ form.show_email(class="_input") }}
|
{{ form.show_email() }}
|
||||||
</div>
|
</div>
|
||||||
{{ form.submit }}
|
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
<h4 class="title is-4">{{ form.profile_picture_file.label }}</h4>
|
||||||
|
{{ form.profile_picture_file(class="") }}
|
||||||
|
<div class="field tab-left">
|
||||||
|
<div class="file">
|
||||||
|
<label class="file-label">
|
||||||
|
<!-- -->
|
||||||
|
<span class="file-cta">
|
||||||
|
<span class="file-icon">
|
||||||
|
<i class="fas fa-upload"></i>
|
||||||
|
</span>
|
||||||
|
<span class="file-label">
|
||||||
|
Choose a file…
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ form.submit(class="button is-danger") }}
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
{% endblock dashboard_body %}
|
{% endblock dashboard_body %}
|
||||||
Reference in New Issue
Block a user