Merge pull request #157 from gazpachoking/oauth_redirect
Store next url redirect for in session to work with oauth login callback
This commit is contained in:
commit
3cecb160df
|
@ -1,4 +1,4 @@
|
||||||
from flask import current_app, request, redirect, Blueprint, flash, url_for
|
from flask import current_app, request, redirect, Blueprint, flash, url_for, session
|
||||||
from ..ldap.models import User
|
from ..ldap.models import User
|
||||||
from flask_ldap_login import LDAPLoginForm
|
from flask_ldap_login import LDAPLoginForm
|
||||||
|
|
||||||
|
@ -14,6 +14,6 @@ def login():
|
||||||
return redirect(url_for('auth.login'))
|
return redirect(url_for('auth.login'))
|
||||||
|
|
||||||
if User.auth(form.user, request.form['password']):
|
if User.auth(form.user, request.form['password']):
|
||||||
return redirect(request.args.get("next") or url_for(current_app.config['ROOT_ENDPOINT']))
|
return redirect(session.get("next_url") or url_for(current_app.config['ROOT_ENDPOINT']))
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('auth.login'))
|
return redirect(url_for('auth.login'))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import current_app, render_template, request, redirect, Blueprint, flash, url_for
|
from flask import current_app, render_template, request, redirect, Blueprint, flash, url_for, session
|
||||||
from realms.modules.auth.local.models import User
|
from realms.modules.auth.local.models import User
|
||||||
from realms.modules.auth.local.forms import LoginForm, RegistrationForm
|
from realms.modules.auth.local.forms import LoginForm, RegistrationForm
|
||||||
|
|
||||||
|
@ -46,6 +46,6 @@ def register():
|
||||||
User.create(request.form['username'], request.form['email'], request.form['password'])
|
User.create(request.form['username'], request.form['email'], request.form['password'])
|
||||||
User.auth(request.form['email'], request.form['password'])
|
User.auth(request.form['email'], request.form['password'])
|
||||||
|
|
||||||
return redirect(request.args.get("next") or url_for(current_app.config['ROOT_ENDPOINT']))
|
return redirect(session.get("next_url") or url_for(current_app.config['ROOT_ENDPOINT']))
|
||||||
|
|
||||||
return render_template("auth/register.html", form=form)
|
return render_template("auth/register.html", form=form)
|
||||||
|
|
|
@ -16,7 +16,7 @@ def login(provider):
|
||||||
|
|
||||||
@blueprint.route('/login/oauth/<provider>/callback')
|
@blueprint.route('/login/oauth/<provider>/callback')
|
||||||
def callback(provider):
|
def callback(provider):
|
||||||
next_url = request.args.get('next') or url_for(current_app.config['ROOT_ENDPOINT'])
|
next_url = session.get('next_url') or url_for(current_app.config['ROOT_ENDPOINT'])
|
||||||
try:
|
try:
|
||||||
remote_app = User.get_app(provider)
|
remote_app = User.get_app(provider)
|
||||||
resp = remote_app.authorized_response()
|
resp = remote_app.authorized_response()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import current_app, render_template, request, redirect, Blueprint, flash, url_for
|
from flask import current_app, render_template, request, redirect, Blueprint, flash, url_for, session
|
||||||
from flask_login import logout_user
|
from flask_login import logout_user
|
||||||
from realms.modules.auth.models import Auth
|
from realms.modules.auth.models import Auth
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ blueprint = Blueprint('auth', __name__, template_folder='templates')
|
||||||
|
|
||||||
@blueprint.route("/login", methods=['GET', 'POST'])
|
@blueprint.route("/login", methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
|
next_url = request.args.get('next') or url_for(current_app.config['ROOT_ENDPOINT'])
|
||||||
|
session['next_url'] = next_url
|
||||||
return render_template("auth/login.html", forms=Auth.login_forms())
|
return render_template("auth/login.html", forms=Auth.login_forms())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="{{ url_for('auth.login') }}"><i class="fa fa-user"></i> Login</a></li>
|
<li><a href="{{ url_for('auth.login', next=request.path) }}"><i class="fa fa-user"></i> Login</a></li>
|
||||||
{% if config.REGISTRATION_ENABLED and 'auth.local' in config.MODULES %}
|
{% if config.REGISTRATION_ENABLED and 'auth.local' in config.MODULES %}
|
||||||
<li><a href="{{ url_for('auth.local.register') }}"><i class="fa fa-users"></i> Register</a></li>
|
<li><a href="{{ url_for('auth.local.register') }}"><i class="fa fa-users"></i> Register</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue