changeset 2933:08007ac96dda

Issue #483 and #482
author Aabhas Majumdar <majumdaraabhas@gmail.com>
date Mon, 23 Feb 2015 00:03:32 +0530
parents ac10a2e3eaf6
children e2b5a79a1e06
files MoinMoin/apps/frontend/views.py MoinMoin/themes/__init__.py MoinMoin/themes/basic/templates/layout.html MoinMoin/themes/basic/templates/login.html
diffstat 4 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Fri Feb 13 21:14:01 2015 +0100
+++ b/MoinMoin/apps/frontend/views.py	Mon Feb 23 00:03:32 2015 +0530
@@ -1577,6 +1577,10 @@
         return Response(flaskg._login_multistage, mimetype='text/html')
 
     if request.method in ['GET', 'HEAD']:
+        # we already have a logged-in user
+        if flaskg.user.valid:
+            flash(_("You are already logged in."), "info")
+            return redirect(url_for('.show_root'))
         form = LoginForm.from_defaults()
         for authmethod in app.cfg.auth:
             hint = authmethod.login_hint()
@@ -1586,7 +1590,8 @@
         form = LoginForm.from_flat(request.form)
         if form.validate():
             # we have a logged-in, valid user
-            return redirect(url_for('.show_root'))
+            next_url = request.args.get('next', default=url_for('.show_root'))
+            return redirect(next_url)
         # flash the error messages (if any)
         for msg in flaskg._login_messages:
             flash(msg, "error")
@@ -1601,7 +1606,8 @@
 def logout():
     flash(_("You are now logged out."), "info")
     flaskg.user.logout_session()
-    return redirect(url_for('.show_root'))
+    next_url = request.args.get('next', default=url_for('.show_root'))
+    return redirect(next_url)
 
 
 class ValidChangePass(Validator):
--- a/MoinMoin/themes/__init__.py	Fri Feb 13 21:14:01 2015 +0100
+++ b/MoinMoin/themes/__init__.py	Mon Feb 23 00:03:32 2015 +0530
@@ -439,7 +439,7 @@
 
     # Properties ##############################################################
 
-    def login_url(self):
+    def login_url(self, next_url=None):
         """
         Return URL usable for user login
 
@@ -448,9 +448,9 @@
         """
         url = None
         if self.cfg.auth_login_inputs == ['special_no_input']:
-            url = url_for('frontend.login', login=1)
+            url = url_for('frontend.login', login=1, next=next_url)
         if self.cfg.auth_have_login:
-            url = url or url_for('frontend.login')
+            url = url or url_for('frontend.login', next=next_url)
         return url
 
     def get_fqnames(self, fqname):
--- a/MoinMoin/themes/basic/templates/layout.html	Fri Feb 13 21:14:01 2015 +0100
+++ b/MoinMoin/themes/basic/templates/layout.html	Mon Feb 23 00:03:32 2015 +0530
@@ -15,7 +15,7 @@
 {% set current_url = request.url %}
 {% set current_path = request.path %}
 {% set current_url_showview = url_for_item(endpoint='frontend.show_item', item_name=item_name) %}
-{% set login_url = theme_supp.login_url() %}
+{% set login_url = theme_supp.login_url(current_path) %}
 
 {# Helper macro to generate the local panel #}
 {% macro local_panel_main(panelname) -%}
@@ -41,7 +41,8 @@
         rel="nofollow"
         {% if title %} title="{{ title }}" {% endif %}>
         {% if iconcls %} <i class="{{ iconcls }}"> </i> {% endif %}
-        {% if href == login_url %}
+        {# needs a login url without next #}
+        {% if href == theme_supp.login_url() %}
             {{ label }}
         {% else %}
             <span class="hidden-sm hidden-xs">{{ label }}</span>
@@ -165,7 +166,7 @@
                                         {%- endif %}
                                         {% if user.auth_method in cfg.auth_can_logout %}
                                             <li title="{{ _('Logout') }}">
-                                                {{ hyperlink(url_for('frontend.logout', logout_submit=1), None, True,
+                                                {{ hyperlink(url_for('frontend.logout', logout_submit=1, next=current_path), None, True,
                                                         _('Logout'), "fa fa-sign-out fa-inverse", None) }}
                                             </li>
                                         {% endif %}
--- a/MoinMoin/themes/basic/templates/login.html	Fri Feb 13 21:14:01 2015 +0100
+++ b/MoinMoin/themes/basic/templates/login.html	Mon Feb 23 00:03:32 2015 +0530
@@ -8,7 +8,7 @@
             {{ forms.render_errors(form) }}
 
             {% if 'username' in login_inputs or 'password' in login_inputs %}
-                {{ gen.form.open(form, method="post", action=url_for('frontend.login')) }}
+                {{ gen.form.open(form, method="post", action=url_for('frontend.login', next=request.args.get('next'))) }}
 
                     {% if 'username' in login_inputs %}
                         <div class="form-group">