-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorator.py
More file actions
32 lines (27 loc) · 1.08 KB
/
decorator.py
File metadata and controls
32 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'''
* * Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
* * See LICENSE in the project root for license information.
'''
from django.http import HttpResponseRedirect
from services.auth_service import AuthService
def login_required(func):
def decorator(request, *args, **kwargs):
user = AuthService.get_current_user(request)
if not user.is_authenticated:
return HttpResponseRedirect('/Account/Login')
return func(request, *args, **kwargs)
return decorator
def admin_only(func):
def decorator(request, *args, **kwargs):
user = AuthService.get_current_user(request)
if not user.is_admin:
return HttpResponseRedirect('/Account/LogOff')
return func(request, *args, **kwargs)
return decorator
def linked_users_only(func):
def decorator(request, *args, **kwargs):
user = AuthService.get_current_user(request)
if not user.are_linked:
return HttpResponseRedirect('/Link')
return func(request, *args, **kwargs)
return decorator