mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 15:50:00 +00:00
Merge pull request #101 from nyaadevs/show_edit_user_info
Show edit user info
This commit is contained in:
commit
4bb9828291
|
@ -259,6 +259,14 @@ class UploadForm(FlaskForm):
|
||||||
bencoded_info_dict=bencoded_info_dict)
|
bencoded_info_dict=bencoded_info_dict)
|
||||||
|
|
||||||
|
|
||||||
|
class UserForm(FlaskForm):
|
||||||
|
user_class = DisabledSelectField('Change User Class')
|
||||||
|
|
||||||
|
def validate_user_class(form, field):
|
||||||
|
if not field.data:
|
||||||
|
raise ValidationError('Please select a proper user class')
|
||||||
|
|
||||||
|
|
||||||
class TorrentFileData(object):
|
class TorrentFileData(object):
|
||||||
"""Quick and dirty class to pass data from the validator"""
|
"""Quick and dirty class to pass data from the validator"""
|
||||||
|
|
||||||
|
|
|
@ -361,6 +361,15 @@ class User(db.Model):
|
||||||
def is_admin(self):
|
def is_admin(self):
|
||||||
return self.level is UserLevelType.ADMIN or self.level is UserLevelType.SUPERADMIN
|
return self.level is UserLevelType.ADMIN or self.level is UserLevelType.SUPERADMIN
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_superadmin(self):
|
||||||
|
return self.level is UserLevelType.SUPERADMIN
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_trusted(self):
|
||||||
|
return self.level is UserLevelType.TRUSTED
|
||||||
|
|
||||||
|
|
||||||
# class Session(db.Model):
|
# class Session(db.Model):
|
||||||
# __tablename__ = 'sessions'
|
# __tablename__ = 'sessions'
|
||||||
#
|
#
|
||||||
|
|
|
@ -206,13 +206,42 @@ def home(rss):
|
||||||
rss_filter=rss_query_string)
|
rss_filter=rss_query_string)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/user/<user_name>')
|
@app.route('/user/<user_name>', methods=['GET', 'POST'])
|
||||||
def view_user(user_name):
|
def view_user(user_name):
|
||||||
user = models.User.by_username(user_name)
|
user = models.User.by_username(user_name)
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
flask.abort(404)
|
flask.abort(404)
|
||||||
|
|
||||||
|
if flask.g.user and flask.g.user.id != user.id:
|
||||||
|
admin = flask.g.user.is_admin
|
||||||
|
superadmin = flask.g.user.is_superadmin
|
||||||
|
else:
|
||||||
|
admin = False
|
||||||
|
superadmin = False
|
||||||
|
|
||||||
|
form = forms.UserForm()
|
||||||
|
form.user_class.choices = _create_user_class_choices()
|
||||||
|
if flask.request.method == 'POST' and form.validate():
|
||||||
|
selection = form.user_class.data
|
||||||
|
|
||||||
|
if selection == 'regular':
|
||||||
|
user.level = models.UserLevelType.REGULAR
|
||||||
|
elif selection == 'trusted':
|
||||||
|
user.level = models.UserLevelType.TRUSTED
|
||||||
|
db.session.add(user)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return flask.redirect('/user/' + user.username)
|
||||||
|
|
||||||
|
level = 'Regular'
|
||||||
|
if user.is_admin:
|
||||||
|
level = 'Moderator'
|
||||||
|
if user.is_superadmin: # check this second because user can be admin AND superadmin
|
||||||
|
level = 'Administrator'
|
||||||
|
elif user.is_trusted:
|
||||||
|
level = 'Trusted'
|
||||||
|
|
||||||
term = flask.request.args.get('q')
|
term = flask.request.args.get('q')
|
||||||
sort = flask.request.args.get('s')
|
sort = flask.request.args.get('s')
|
||||||
order = flask.request.args.get('o')
|
order = flask.request.args.get('o')
|
||||||
|
@ -273,7 +302,11 @@ def view_user(user_name):
|
||||||
search=query_args,
|
search=query_args,
|
||||||
user=user,
|
user=user,
|
||||||
user_page=True,
|
user_page=True,
|
||||||
rss_filter=rss_query_string)
|
rss_filter=rss_query_string,
|
||||||
|
level=level,
|
||||||
|
admin=admin,
|
||||||
|
superadmin=superadmin,
|
||||||
|
form=form)
|
||||||
# Similar logic as home page
|
# Similar logic as home page
|
||||||
else:
|
else:
|
||||||
if use_elastic:
|
if use_elastic:
|
||||||
|
@ -287,7 +320,11 @@ def view_user(user_name):
|
||||||
search=query_args,
|
search=query_args,
|
||||||
user=user,
|
user=user,
|
||||||
user_page=True,
|
user_page=True,
|
||||||
rss_filter=rss_query_string)
|
rss_filter=rss_query_string,
|
||||||
|
level=level,
|
||||||
|
admin=admin,
|
||||||
|
superadmin=superadmin,
|
||||||
|
form=form)
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter('rfc822')
|
@app.template_filter('rfc822')
|
||||||
|
@ -400,6 +437,15 @@ def profile():
|
||||||
return flask.redirect('/') # so we dont get stuck in infinite loop when signing out
|
return flask.redirect('/') # so we dont get stuck in infinite loop when signing out
|
||||||
|
|
||||||
form = forms.ProfileForm(flask.request.form)
|
form = forms.ProfileForm(flask.request.form)
|
||||||
|
|
||||||
|
level = 'Regular'
|
||||||
|
if flask.g.user.is_admin:
|
||||||
|
level = 'Moderator'
|
||||||
|
if flask.g.user.is_superadmin: # check this second because we can be admin AND superadmin
|
||||||
|
level = 'Administrator'
|
||||||
|
elif flask.g.user.is_trusted:
|
||||||
|
level = 'Trusted'
|
||||||
|
|
||||||
if flask.request.method == 'POST' and form.validate():
|
if flask.request.method == 'POST' and form.validate():
|
||||||
user = flask.g.user
|
user = flask.g.user
|
||||||
new_email = form.email.data.strip()
|
new_email = form.email.data.strip()
|
||||||
|
@ -431,7 +477,7 @@ def profile():
|
||||||
|
|
||||||
current_email = models.User.by_id(flask.g.user.id).email
|
current_email = models.User.by_id(flask.g.user.id).email
|
||||||
|
|
||||||
return flask.render_template('profile.html', form=form, email=current_email)
|
return flask.render_template('profile.html', form=form, email=current_email, level=level)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/user/activate/<payload>')
|
@app.route('/user/activate/<payload>')
|
||||||
|
@ -631,6 +677,13 @@ def send_verification_email(to_address, activ_link):
|
||||||
server.quit()
|
server.quit()
|
||||||
|
|
||||||
|
|
||||||
|
def _create_user_class_choices():
|
||||||
|
choices = [('regular', 'Regular')]
|
||||||
|
if flask.g.user and flask.g.user.is_superadmin:
|
||||||
|
choices.append(('trusted', 'Trusted'))
|
||||||
|
return choices
|
||||||
|
|
||||||
|
|
||||||
# #################################### STATIC PAGES ####################################
|
# #################################### STATIC PAGES ####################################
|
||||||
@app.route('/rules', methods=['GET'])
|
@app.route('/rules', methods=['GET'])
|
||||||
def site_rules():
|
def site_rules():
|
||||||
|
|
|
@ -91,3 +91,30 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro render_menu_with_button(field) %}
|
||||||
|
{% if field.errors %}
|
||||||
|
<div class="form-group has-error">
|
||||||
|
{% else %}
|
||||||
|
<div class="form-group">
|
||||||
|
{% endif %}
|
||||||
|
{{ field.label(class='control-label') }}
|
||||||
|
{{ field(title=field.description,**kwargs) | safe }}
|
||||||
|
<button type="submit" class="btn btn-primary">Apply</button>
|
||||||
|
{% if field.errors %}
|
||||||
|
<div class="help-block">
|
||||||
|
{% if field.errors|length < 2 %}
|
||||||
|
{% for error in field.errors %}
|
||||||
|
{{ error }}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<ul>
|
||||||
|
{% for error in field.errors %}
|
||||||
|
<li>{{ error }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
|
@ -12,6 +12,9 @@
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a href="#email-change" id="email-change-tab" role="tab" data-toggle="tab" aria-controls="profile" aria-expanded="false">Email</a>
|
<a href="#email-change" id="email-change-tab" role="tab" data-toggle="tab" aria-controls="profile" aria-expanded="false">Email</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#general-info" id="general-info-tab" role="tab" data-toggle="tab" aria-controls="profile" aria-expanded="false">My Info</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane fade active in" role="tabpanel" id="password-change" aria-labelledby="password-change-tab">
|
<div class="tab-pane fade active in" role="tabpanel" id="password-change" aria-labelledby="password-change-tab">
|
||||||
|
@ -67,6 +70,16 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tab-pane fade" role="tabpanel" id="general-info" aria-labelledby="general-info-tab">
|
||||||
|
<dl class="dl-horizontal">
|
||||||
|
<dt>User ID:</dt>
|
||||||
|
<dd>{{g.user.id}}</dd>
|
||||||
|
<dt>Account created on:</dt>
|
||||||
|
<dd>{{g.user.created_time}}</dd>
|
||||||
|
<dt>User class:</dt>
|
||||||
|
<dd>{{level}}</dd><br>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,8 +1,34 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% block title %}{{ user.username }} :: {{ config.SITE_NAME }}{% endblock %}
|
{% block title %}{{ user.username }} :: {{ config.SITE_NAME }}{% endblock %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
{% from "_formhelpers.html" import render_menu_with_button %}
|
||||||
|
|
||||||
|
{% if superadmin %}
|
||||||
|
<h2>User Information</h2><br>
|
||||||
|
<dl class="dl-horizontal">
|
||||||
|
<dt>User ID:</dt>
|
||||||
|
<dd>{{user.id}}</dd>
|
||||||
|
<dt>Account created on:</dt>
|
||||||
|
<dd>{{user.created_time}}</dd>
|
||||||
|
<dt>Email address:</dt>
|
||||||
|
<dd>{{user.email}}</dd>
|
||||||
|
<dt>User class:</dt>
|
||||||
|
<dd>{{level}}</dd><br>
|
||||||
|
</dl>
|
||||||
|
<form method="POST">
|
||||||
|
{{ form.csrf_token }}
|
||||||
|
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
{{ render_menu_with_button(form.user_class)}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<h3>
|
<h3>
|
||||||
Browsing {{user.username}}'s torrents
|
Browsing {{user.username}}'s torrents
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
{% include "search_results.html" %}
|
{% include "search_results.html" %}
|
||||||
|
|
Loading…
Reference in a new issue