Add user account claiming

This commit is contained in:
rubenwardy
2018-05-13 23:31:42 +01:00
parent 31615da169
commit ff8bf992a9
9 changed files with 253 additions and 27 deletions

View File

@@ -43,16 +43,8 @@ def github_authorized(oauth_token):
# If not logged in, log in
else:
if userByGithub is None:
newUser = User(username)
newUser.github_username = username
db.session.add(newUser)
db.session.commit()
if not loginUser(newUser):
raise Exception("Unable to login as user we just created")
flash("Created an account", "success")
return redirect(url_for("user_profile_page", username=username))
flash("Unable to find an account for that Github user", "error")
return redirect(url_for("user_claim_page"))
elif loginUser(userByGithub):
return redirect(next_url or url_for("home_page"))
else:

View File

@@ -22,7 +22,6 @@ def new_getmeta_page():
})
@app.route("/tasks/<id>/")
@login_required
def check_task(id):
result = celery.AsyncResult(id)
status = result.status
@@ -51,7 +50,6 @@ def check_task(id):
abort(422)
if status == "SUCCESS":
flash("Task complete!", "success")
return redirect(r)
else:
return render_template("tasks/view.html", info=info)

View File

@@ -8,7 +8,8 @@ from flask_wtf import FlaskForm
from flask_user.forms import RegisterForm
from wtforms import *
from wtforms.validators import *
from .utils import rank_required
from .utils import rank_required, randomString
from app.tasks.forumtasks import checkForumAccount
class MyRegisterForm(RegisterForm):
display_name = StringField("Display name")
@@ -59,3 +60,42 @@ def user_profile_page(username):
# Process GET or invalid POST
return render_template("users/user_profile_page.html",
user=user, form=form)
@app.route("/users/claim/", methods=["GET", "POST"])
def user_claim_page():
username = request.args.get("username")
if username is None:
username = ""
else:
method = request.args.get("method")
user = User.query.filter_by(forums_username=username).first()
if user and user.rank.atLeast(UserRank.NEW_MEMBER):
flash("User has already been claimed", "error")
return redirect(url_for("user_claim_page"))
elif user is None and method == "github":
flash("Unable to get Github username for user", "error")
return redirect(url_for("user_claim_page"))
elif user is None:
flash("Unable to find that user", "error")
return redirect(url_for("user_claim_page"))
if user is not None and method == "github":
return redirect(url_for("github_signin_page"))
if request.method == "POST":
ctype = request.form.get("claim_type")
username = request.form.get("username")
if username is None or len(username.strip()) < 2:
flash("Invalid username", "error")
elif ctype == "github":
task = checkForumAccount.delay(username)
return redirect(url_for("check_task", id=task.id, r=url_for("user_claim_page", username=username, method="github")))
elif ctype == "forum":
token = request.form.get("token")
flash("Unimplemented", "error")
else:
flash("Unknown claim type", "error")
return render_template("users/claim.html", username=username, key=randomString(32))