This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git


The following commit(s) were added to refs/heads/master by this push:
     new a29b2b6  Handle next parameter to take user to page after login
a29b2b6 is described below

commit a29b2b6eb609db2fecd03a972a0c8f246c67be69
Author: Marcus Christie <machr...@iu.edu>
AuthorDate: Thu Apr 12 17:15:15 2018 -0400

    Handle next parameter to take user to page after login
---
 .../apps/auth/templates/django_airavata_auth/login.html       |  3 +++
 django_airavata/apps/auth/views.py                            | 11 +++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git 
a/django_airavata/apps/auth/templates/django_airavata_auth/login.html 
b/django_airavata/apps/auth/templates/django_airavata_auth/login.html
index f12f838..20d3e20 100644
--- a/django_airavata/apps/auth/templates/django_airavata_auth/login.html
+++ b/django_airavata/apps/auth/templates/django_airavata_auth/login.html
@@ -18,6 +18,9 @@
                             <label for="password">Password</label>
                             <input type="password" class="form-control" 
id="password" name="password" placeholder="Password">
                         </div>
+                        {% if next %}
+                        <input type="hidden" name="next" value="{{ next }}"/>
+                        {% endif %}
                         <button type="submit" class="btn 
btn-default">Submit</button>
                     </form>
                 </div>
diff --git a/django_airavata/apps/auth/views.py 
b/django_airavata/apps/auth/views.py
index 25609ab..8c1c468 100644
--- a/django_airavata/apps/auth/views.py
+++ b/django_airavata/apps/auth/views.py
@@ -23,7 +23,9 @@ def start_login(request):
     # # Store state in session for later validation
     # request.session['OAUTH2_STATE'] = state
     # return redirect(authorization_url)
-    return render(request, 'django_airavata_auth/login.html')
+    return render(request, 'django_airavata_auth/login.html', {
+        'next': request.GET.get('next', None)
+    })
 
 def handle_login(request):
     username = request.POST['username']
@@ -33,8 +35,8 @@ def handle_login(request):
     try:
         if user is not None:
             login(request, user)
-            # TODO: handle 'next' query param
-            return redirect(settings.LOGIN_REDIRECT_URL)
+            next_url = request.POST.get('next', settings.LOGIN_REDIRECT_URL)
+            return redirect(next_url)
         else:
             # TODO: add error message that login failed
             return render(request, 'django_airavata_auth/login.html', {
@@ -53,7 +55,8 @@ def callback(request):
     try:
         user = authenticate(request=request)
         login(request, user)
-        return redirect(settings.LOGIN_REDIRECT_URL)
+        next_url = request.GET.get('next', settings.LOGIN_REDIRECT_URL)
+        return redirect(next_url)
     except Exception as err:
         logger.exception("An error occurred while processing OAuth2 callback: 
{}".format(request.build_absolute_uri()))
         return redirect(reverse('django_airavata_auth:error'))

-- 
To stop receiving notification emails like this one, please contact
machris...@apache.org.

Reply via email to