From 583c0f813306c43eb623198158ad82dd37e72a4b Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 20 Aug 2018 14:31:55 +0530 Subject: add send email and email verify decorator --- sbhs/decorators.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 sbhs/decorators.py (limited to 'sbhs/decorators.py') 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 -- cgit