Skip to content
Permalink
Browse files

Add flash messages, handle bad oauth-callback call

Change-Id: Iaa5eec3d46e19cd637fcf8b00e889064a019b93b
  • Loading branch information...
framawiki committed May 19, 2019
1 parent ec58f56 commit 29e39d686992ca48d973fc03ed2e073bac591e2e
Showing with 37 additions and 6 deletions.
  1. +11 −2 quarry/web/login.py
  2. +12 −1 quarry/web/static/css/base.css
  3. +13 −0 quarry/web/templates/base.html
  4. +1 −3 quarry/web/user.py
@@ -1,9 +1,11 @@
from flask import Blueprint, request, session, redirect, g
from flask import Blueprint, request, session, redirect, g, flash, url_for
from mwoauth import ConsumerToken, Handshaker
from mwoauth.errors import OAuthException
from .models.user import User
from requests import __version__ as requests_version
from socket import getfqdn
from sqlalchemy.exc import IntegrityError
from logging import exception

auth = Blueprint('auth', __name__)

@@ -42,7 +44,13 @@ def oauth_callback():
oauth_token,
user_agent=user_agent
)
access_token = handshaker.complete(session['request_token'], request.query_string)
try:
access_token = handshaker.complete(session['request_token'], request.query_string)
except (OAuthException, KeyError) as e:
exception(e)
flash('Fatal error occured while login (%s). Please try again after cleaning the cookies in your browser.'
% str(e), 'danger')
return redirect(url_for('index'))
session['access_token'] = access_token
identity = handshaker.identify(access_token)
wiki_uid = identity['sub']
@@ -51,6 +59,7 @@ def oauth_callback():
user = User(username=identity['username'], wiki_uid=wiki_uid)
g.conn.session.add(user)
g.conn.session.commit()
flash('Welcome to Quarry, %s!' % user.username, 'success')
elif user.username != identity['username']:
user.username = identity['username']
g.conn.session.add(user)
@@ -34,5 +34,16 @@
margin-bottom: 0px;
border-bottom-width: 0px;
text-align: center;
font-weight: bold;
}

.flashes {
padding: 0px 40px;
}

.alert {
font-weight: 400;
}

body {
font-size: 12px;
}
@@ -80,6 +80,19 @@
</div>
</div>

{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<ul class=flashes>
{% for category, message in messages %}
<div class="alert alert-dismissible alert-{{ category }}">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{{ message }}
</div>
{% endfor %}
</ul>
{% endif %}
{% endwith %}

{% block content %}
{% endblock %}

@@ -15,9 +15,7 @@ def get_user():
session.permanent = True
g._user = g.conn.session.query(User).filter(User.id == session['user_id']).one()
return g._user
else:
user = None
return user
return None


def get_preferences():

0 comments on commit 29e39d6

Please sign in to comment.
You can’t perform that action at this time.