mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2025-12-06 19:16:53 -06:00
api
This commit is contained in:
@@ -21,8 +21,13 @@ def profile_settings():
|
||||
def profile_settings_submit():
|
||||
form = ProfileSettingsForm()
|
||||
if form.validate_on_submit():
|
||||
return jsonify(data={'message' : 'hello {}'.format(form.show_email.data)})
|
||||
return '$'
|
||||
data = {
|
||||
'show_email' : form.show_email.data or None,
|
||||
'profile_picture_file' : request.files
|
||||
}
|
||||
return jsonify(data=data)
|
||||
return '{}'
|
||||
|
||||
@app.route('/dashboard/constants')
|
||||
@login_required
|
||||
@require_role(roles=['Admin'])
|
||||
|
||||
10
app/forms.py
10
app/forms.py
@@ -1,6 +1,6 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField, RadioField
|
||||
from wtforms.validators import ValidationError, DataRequired, EqualTo, Email
|
||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField, RadioField, FileField
|
||||
from wtforms.validators import ValidationError, DataRequired, EqualTo, Email, URL
|
||||
from app.models import User
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
@@ -28,6 +28,10 @@ class RegistrationForm(FlaskForm):
|
||||
|
||||
class ProfileSettingsForm(FlaskForm):
|
||||
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')
|
||||
|
||||
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)
|
||||
username = db.Column(db.String(64), 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))
|
||||
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
||||
search_history = db.relationship('Search', backref='user', lazy='dynamic')
|
||||
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):
|
||||
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__())
|
||||
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):
|
||||
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(' ')
|
||||
if type(roles) == str:
|
||||
user_roles.append(roles)
|
||||
@@ -33,6 +63,11 @@ class User(UserMixin, db.Model):
|
||||
user_roles.extend(roles)
|
||||
user_roles = ' '.join(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']]
|
||||
# Meaning: Must have 'Insane' role, as well as 'Fortunate' or 'Blessed' roles.
|
||||
|
||||
@@ -15,7 +15,8 @@ import json
|
||||
|
||||
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)
|
||||
def unauthorized(e):
|
||||
@@ -26,6 +27,10 @@ def unauthorized(e):
|
||||
def profile():
|
||||
return render_template('profile.html')
|
||||
|
||||
@app.route('/api/')
|
||||
def api():
|
||||
return 'fuckoff bots'
|
||||
|
||||
@app.route('/userinfo/')
|
||||
def user_info():
|
||||
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>
|
||||
</a>
|
||||
<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>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
</p>
|
||||
<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('profile_settings') }}" {% if profile_settings_active %}class="is-active"{% endif %}>Profile Settings</a></li>
|
||||
</ul>
|
||||
<p class="menu-label">
|
||||
Settings
|
||||
</p>
|
||||
<ul class="menu-list">
|
||||
|
||||
<li><a href="{{ url_for('profile_settings') }}" {% if profile_settings_active %}class="is-active"{% endif %}>Profile Settings</a></li>
|
||||
</ul>
|
||||
<p class="menu-label">
|
||||
Administration
|
||||
@@ -28,7 +30,8 @@
|
||||
</ul>
|
||||
</aside>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="column"></div>
|
||||
<div class="column is-two-thirds">
|
||||
{% block dashboard_body %}
|
||||
|
||||
{% endblock dashboard_body %}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{{ super() }}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('form').submit(function (e) {
|
||||
$('#form-ajax').submit(function (e) {
|
||||
var url = "{{ url_for('profile_settings_submit') }}"; // send the form data here.
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
@@ -26,17 +26,43 @@
|
||||
})
|
||||
});
|
||||
</script>
|
||||
<style type="text/css">
|
||||
.tab-left {
|
||||
padding-left: 3rem;
|
||||
}
|
||||
</style>
|
||||
{% endblock head %}
|
||||
{% block dashboard_body %}
|
||||
<section>
|
||||
<h1 class="title">Profile Settings</h1>
|
||||
<form action="" method="POST" novalidate>
|
||||
<form class="form-ajax" action="" method="POST" novalidate>
|
||||
{{ form.hidden_tag() }}
|
||||
<div class="field">
|
||||
{{ form.show_email.label }}
|
||||
{{ form.show_email(class="_input") }}
|
||||
<div class="field tab-left">
|
||||
<h4 class="title is-4">{{ form.show_email.label }}</h4>
|
||||
{{ form.show_email() }}
|
||||
</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>
|
||||
</section>
|
||||
{% endblock dashboard_body %}
|
||||
Reference in New Issue
Block a user