diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-05-13 23:31:42 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-05-13 23:33:05 +0100 |
commit | ff8bf992a9048e55b58ece46cf25cc3a43edcef7 (patch) | |
tree | 02a1a7198a9fd20539465a0ccd378f0dd02f8913 /app/tasks/forumtasks.py | |
parent | 31615da169766087a35c104d6aa8797a6eaa7594 (diff) | |
download | cheatdb-ff8bf992a9048e55b58ece46cf25cc3a43edcef7.tar.xz |
Add user account claiming
Diffstat (limited to 'app/tasks/forumtasks.py')
-rw-r--r-- | app/tasks/forumtasks.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/tasks/forumtasks.py b/app/tasks/forumtasks.py new file mode 100644 index 0000000..e4ddc59 --- /dev/null +++ b/app/tasks/forumtasks.py @@ -0,0 +1,33 @@ +import flask +from flask.ext.sqlalchemy import SQLAlchemy +from app import app +from app.models import * +from app.tasks import celery +from .phpbbparser import getProfile + +@celery.task() +def checkForumAccount(username, token=None): + try: + profile = getProfile("https://forum.minetest.net", username) + except OSError: + return + + user = User.query.filter_by(forums_username=username).first() + + # Create user + needsSaving = False + if user is None: + user = User(username) + user.forums_username = username + db.session.add(user) + + # Get github username + github_username = profile.get("github") + if github_username is not None and github_username.strip() != "": + print("Updated github username") + user.github_username = github_username + needsSaving = True + + # Save + if needsSaving: + db.session.commit() |