aboutsummaryrefslogtreecommitdiff
path: root/app/views/githublogin.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-03-24 02:35:58 +0000
committerrubenwardy <rw@rubenwardy.com>2018-03-24 02:35:58 +0000
commit6be5b3eb42b97c29305bbe47defcb9a1b5e6d367 (patch)
tree939fdde9e3094592d787eee41804703ad89631ff /app/views/githublogin.py
parentbb9d589fb55718db6783a236d047614b284d352e (diff)
downloadcheatdb-6be5b3eb42b97c29305bbe47defcb9a1b5e6d367.tar.xz
Add registering using Github
Diffstat (limited to 'app/views/githublogin.py')
-rw-r--r--app/views/githublogin.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/app/views/githublogin.py b/app/views/githublogin.py
index f04e8de..30cb61f 100644
--- a/app/views/githublogin.py
+++ b/app/views/githublogin.py
@@ -24,6 +24,9 @@ def _do_login_user(user, remember_me=False):
return False
user.active = True
+ if not user.rank.atLeast(UserRank.NEW_MEMBER):
+ user.rank = UserRank.NEW_MEMBER
+
db.session.commit()
# Check if user account has been disabled
@@ -91,8 +94,16 @@ def github_authorized(oauth_token):
# If not logged in, log in
else:
if userByGithub is None:
- flash("Authorization failed [err=gh-no-such-account]", "danger")
- return redirect(url_for("user.login"))
+ newUser = User(username)
+ newUser.github_username = username
+ db.session.add(newUser)
+ db.session.commit()
+
+ if not _login_user(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))
elif _login_user(userByGithub):
return redirect(next_url or url_for("home_page"))
else: