diff options
author | CruiseDevice | 2018-08-20 14:31:55 +0530 |
---|---|---|
committer | CruiseDevice | 2018-08-20 14:40:31 +0530 |
commit | 583c0f813306c43eb623198158ad82dd37e72a4b (patch) | |
tree | 5811b8d47724b5c3dec00a761a6e1dbffcdf532d /sbhs/decorators.py | |
parent | 1df056c7e273d07e920f04fe6b41b7a68ee267df (diff) | |
download | sbhs_server-583c0f813306c43eb623198158ad82dd37e72a4b.tar.gz sbhs_server-583c0f813306c43eb623198158ad82dd37e72a4b.tar.bz2 sbhs_server-583c0f813306c43eb623198158ad82dd37e72a4b.zip |
add send email and email verify decorator
Diffstat (limited to 'sbhs/decorators.py')
-rw-r--r-- | sbhs/decorators.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sbhs/decorators.py b/sbhs/decorators.py new file mode 100644 index 0000000..cd05e38 --- /dev/null +++ b/sbhs/decorators.py @@ -0,0 +1,27 @@ +from django.shortcuts import render +from django.conf import settings + +def user_has_profile(user): + return hasattr(user, 'profile') + +def email_verified(func): + """ + This decorator is used to check if email is verified. + If email is not verified then redirect user for email + verification. + """ + + def is_email_verified(request, *args, **kwargs): + user = request.user + context = {} + if not settings.IS_DEVELOPMENT: + if user.is_authenticated() and user_has_profile(user): + if not user.profile.is_email_verified: + context['success'] = False + context['msg'] = "Your account is not verified. \ + Please verify your account" + return render( + request, 'account/activation_status.html', context + ) + return func(request, *args, **kwargs) + return is_email_verified
\ No newline at end of file |