File tree Expand file tree Collapse file tree 15 files changed +66
-17
lines changed Expand file tree Collapse file tree 15 files changed +66
-17
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ In templates
6363
6464Note: you can pass `next ` query parameter to the authorize view to direct the user to correct page after OAuth flow has completed successfully. Default will send user to '/'
6565
66+ In views as a decorator: this will kick off the Authorization flow or Refresh request (if token is expired) and will send the user back to the original requested url on completion
67+ ::
68+ from replyify_oauth2.decorators import replyify_auth_required
69+
70+ @replyify_auth_required
71+ def my_view_that_needs_replyify(request):
72+ ...
6673
6774Using the Replyify API
6875----------------------
File renamed without changes.
Original file line number Diff line number Diff line change 33
44#
55# This file is subject to the terms and conditions defined in
6- # file 'LICENSE.md ', which is part of this source code package.
6+ # file 'LICENSE', which is part of this source code package.
77#
8-
98from django import VERSION as DJANGO_VERSION
109if DJANGO_VERSION >= (1 , 7 ):
1110 default_app_config = 'replyify_oauth2.apps.ReplyifyOAuth2Config'
Original file line number Diff line number Diff line change 33
44#
55# This file is subject to the terms and conditions defined in
6- # file 'LICENSE.md ', which is part of this source code package.
6+ # file 'LICENSE', which is part of this source code package.
77#
8-
98from django .contrib import admin
109from django .contrib .auth import get_user_model
1110from . import settings
Original file line number Diff line number Diff line change 33
44#
55# This file is subject to the terms and conditions defined in
6- # file 'LICENSE.md ', which is part of this source code package.
6+ # file 'LICENSE', which is part of this source code package.
77#
8-
98from __future__ import unicode_literals
109from django import VERSION as DJANGO_VERSION
1110
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # -*- coding: utf-8 -*-
3+
4+ #
5+ # This file is subject to the terms and conditions defined in
6+ # file 'LICENSE', which is part of this source code package.
7+ #
8+ from functools import wraps
9+ from django .core .urlresolvers import reverse
10+ from django .shortcuts import redirect
11+ from .models import Credentials
12+
13+
14+ def replyify_auth_required (func ):
15+ def decorator (func ):
16+ def inner_decorator (request , * args , ** kwargs ):
17+ try :
18+ if Credentials .objects .get (user = request .user ).is_valid ():
19+ return func (request , * args , ** kwargs )
20+ except Credentials .DoesNotExsit :
21+ return redirect (reverse ('replyfy:authorize' ) + '?next=' + request .GET .get ('next' , request .path ))
22+ return redirect (reverse ('replyfy:refresh' ) + '?next=' + request .GET .get ('next' , request .path ))
23+ return wraps (func )(inner_decorator )
24+ return decorator (func )
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
12# -*- coding: utf-8 -*-
2- # Generated by Django 1.11 on 2017-04-11 21:18
3+
4+ #
5+ # This file is subject to the terms and conditions defined in
6+ # file 'LICENSE', which is part of this source code package.
7+ #
38from __future__ import unicode_literals
49
510from django .conf import settings
Original file line number Diff line number Diff line change 33
44#
55# This file is subject to the terms and conditions defined in
6- # file 'LICENSE.md ', which is part of this source code package.
6+ # file 'LICENSE', which is part of this source code package.
77#
Original file line number Diff line number Diff line change 33
44#
55# This file is subject to the terms and conditions defined in
6- # file 'LICENSE.md ', which is part of this source code package.
6+ # file 'LICENSE', which is part of this source code package.
77#
8-
98from __future__ import unicode_literals
109from django .conf import settings
1110from django .db import models
@@ -22,10 +21,13 @@ class Credentials(models.Model):
2221 updated = models .DateTimeField (auto_now = True )
2322 created = models .DateTimeField (auto_now_add = True )
2423
25- def expired (self ):
24+ def is_expired (self ):
2625 if timezone .now () > self .expires :
2726 return True
2827 return False
2928
29+ def is_valid (self ):
30+ return not self .is_expired ()
31+
3032 def __unicode__ (self ):
3133 return '<Replyify Creds: {}>' .format (self .access_token )
Original file line number Diff line number Diff line change 33
44#
55# This file is subject to the terms and conditions defined in
6- # file 'LICENSE.md ', which is part of this source code package.
6+ # file 'LICENSE', which is part of this source code package.
77#
88from django .conf import settings
99
You can’t perform that action at this time.
0 commit comments