mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 10:29:59 +00:00
Move /user/activate/<payload> route into users
Move supporting functions as well: - get_serializer - get_activation_link
This commit is contained in:
parent
0887dde6fc
commit
50529920bd
|
@ -11,7 +11,6 @@ from flask_paginate import Pagination
|
||||||
from werkzeug import url_encode
|
from werkzeug import url_encode
|
||||||
from werkzeug.datastructures import CombinedMultiDict
|
from werkzeug.datastructures import CombinedMultiDict
|
||||||
|
|
||||||
from itsdangerous import BadSignature, URLSafeSerializer
|
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
from nyaa import api_handler, app, backend, db, forms, models, torrents, views
|
from nyaa import api_handler, app, backend, db, forms, models, torrents, views
|
||||||
|
@ -286,27 +285,6 @@ def render_rss(label, query, use_elastic, magnet_links=False):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@app.route('/user/activate/<payload>')
|
|
||||||
def activate_user(payload):
|
|
||||||
s = get_serializer()
|
|
||||||
try:
|
|
||||||
user_id = s.loads(payload)
|
|
||||||
except BadSignature:
|
|
||||||
flask.abort(404)
|
|
||||||
|
|
||||||
user = models.User.by_id(user_id)
|
|
||||||
|
|
||||||
if not user:
|
|
||||||
flask.abort(404)
|
|
||||||
|
|
||||||
user.status = models.UserStatusType.ACTIVE
|
|
||||||
|
|
||||||
db.session.add(user)
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
return flask.redirect('/login')
|
|
||||||
|
|
||||||
|
|
||||||
@cached_function
|
@cached_function
|
||||||
def _create_upload_category_choices():
|
def _create_upload_category_choices():
|
||||||
''' Turns categories in the database into a list of (id, name)s '''
|
''' Turns categories in the database into a list of (id, name)s '''
|
||||||
|
@ -566,18 +544,6 @@ def _get_cached_torrent_file(torrent):
|
||||||
return open(cached_torrent, 'rb'), os.path.getsize(cached_torrent)
|
return open(cached_torrent, 'rb'), os.path.getsize(cached_torrent)
|
||||||
|
|
||||||
|
|
||||||
def get_serializer(secret_key=None):
|
|
||||||
if secret_key is None:
|
|
||||||
secret_key = app.secret_key
|
|
||||||
return URLSafeSerializer(secret_key)
|
|
||||||
|
|
||||||
|
|
||||||
def get_activation_link(user):
|
|
||||||
s = get_serializer()
|
|
||||||
payload = s.dumps(user.id)
|
|
||||||
return flask.url_for('activate_user', payload=payload, _external=True)
|
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def timesince(dt, default='just now'):
|
def timesince(dt, default='just now'):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -6,8 +6,8 @@ from ipaddress import ip_address
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
# Importing nyaa.routes for get_activation_link
|
from nyaa import app, db, forms, models
|
||||||
from nyaa import app, db, forms, models, routes
|
from nyaa.views.users import get_activation_link
|
||||||
|
|
||||||
bp = flask.Blueprint('account', __name__)
|
bp = flask.Blueprint('account', __name__)
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ def register():
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
if app.config['USE_EMAIL_VERIFICATION']: # force verification, enable email
|
if app.config['USE_EMAIL_VERIFICATION']: # force verification, enable email
|
||||||
activ_link = routes.get_activation_link(user)
|
activ_link = get_activation_link(user)
|
||||||
send_verification_email(user.email, activ_link)
|
send_verification_email(user.email, activ_link)
|
||||||
return flask.render_template('waiting.html')
|
return flask.render_template('waiting.html')
|
||||||
else: # disable verification, set user as active and auto log in
|
else: # disable verification, set user as active and auto log in
|
||||||
|
|
|
@ -3,6 +3,8 @@ import math
|
||||||
import flask
|
import flask
|
||||||
from flask_paginate import Pagination
|
from flask_paginate import Pagination
|
||||||
|
|
||||||
|
from itsdangerous import BadSignature, URLSafeSerializer
|
||||||
|
|
||||||
from nyaa import app, db, forms, models
|
from nyaa import app, db, forms, models
|
||||||
from nyaa.search import (DEFAULT_MAX_SEARCH_RESULT, DEFAULT_PER_PAGE, SERACH_PAGINATE_DISPLAY_MSG,
|
from nyaa.search import (DEFAULT_MAX_SEARCH_RESULT, DEFAULT_PER_PAGE, SERACH_PAGINATE_DISPLAY_MSG,
|
||||||
_generate_query_string, search_db, search_elastic)
|
_generate_query_string, search_db, search_elastic)
|
||||||
|
@ -135,6 +137,27 @@ def view_user(user_name):
|
||||||
admin_form=admin_form)
|
admin_form=admin_form)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/user/activate/<payload>')
|
||||||
|
def activate_user(payload):
|
||||||
|
s = get_serializer()
|
||||||
|
try:
|
||||||
|
user_id = s.loads(payload)
|
||||||
|
except BadSignature:
|
||||||
|
flask.abort(404)
|
||||||
|
|
||||||
|
user = models.User.by_id(user_id)
|
||||||
|
|
||||||
|
if not user:
|
||||||
|
flask.abort(404)
|
||||||
|
|
||||||
|
user.status = models.UserStatusType.ACTIVE
|
||||||
|
|
||||||
|
db.session.add(user)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return flask.redirect(flask.url_for('account.login'))
|
||||||
|
|
||||||
|
|
||||||
def _create_user_class_choices(user):
|
def _create_user_class_choices(user):
|
||||||
choices = [('regular', 'Regular')]
|
choices = [('regular', 'Regular')]
|
||||||
default = 'regular'
|
default = 'regular'
|
||||||
|
@ -154,3 +177,15 @@ def _create_user_class_choices(user):
|
||||||
default = 'banned'
|
default = 'banned'
|
||||||
|
|
||||||
return default, choices
|
return default, choices
|
||||||
|
|
||||||
|
|
||||||
|
def get_serializer(secret_key=None):
|
||||||
|
if secret_key is None:
|
||||||
|
secret_key = app.secret_key
|
||||||
|
return URLSafeSerializer(secret_key)
|
||||||
|
|
||||||
|
|
||||||
|
def get_activation_link(user):
|
||||||
|
s = get_serializer()
|
||||||
|
payload = s.dumps(user.id)
|
||||||
|
return flask.url_for('users.activate_user', payload=payload, _external=True)
|
||||||
|
|
Loading…
Reference in a new issue