Skip to content

Commit

Permalink
Add Manual Login Email
Browse files Browse the repository at this point in the history
  • Loading branch information
Man-Jain committed Jul 7, 2020
1 parent be9c7da commit cd06f4a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
17 changes: 12 additions & 5 deletions backend/downtownapi/main/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def create(self, validated_data):
last_name=validated_data.get('last_name', ''),
username=validated_data.get('email', ''),
email=validated_data.get('email', ''),
is_active=True,

is_email_verified=False,
is_active=False,
)
user.set_password(validated_data['password'])
user.save()
Expand Down Expand Up @@ -113,11 +113,18 @@ def validate(self, attrs):
if username and password:
user = authenticate(request=self.context.get('request'),
username=username, password=password)

# The authenticate call simply returns None for is_active=False
# users. (Assuming the default ModelBackend authentication
# backend.)
# users.
if not user:
try:
u = User.objects.get(username=username)
print(u)
except:
u = None
if not u.is_email_verified:
msg = 'Account not active. Please check your Inbox and Verify your Email'
logger.info('Account Not Active')
raise serializers.ValidationError(msg, code='authorization')
msg = 'Unable to log in with provided credentials.'
logger.info('Cant Authenticate User')
raise serializers.ValidationError(msg, code='authorization')
Expand Down
2 changes: 1 addition & 1 deletion backend/downtownapi/main/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def send_register_mail(sender, instance, **kwargs):
'token': token,
'user': instance,
}
subject = "Thanks for Creating an Account on Downtown Stimulus"
subject = "Welcome to the Downtown Stimulus! Your Account is Created. Please verify your Email"

try:
mail_body = get_mail_body('create_account', params)
Expand Down
13 changes: 11 additions & 2 deletions backend/downtownapi/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,18 @@ def activate(request, uidb64, token):
user = None
if user is not None and account_activation_token.check_token(user, token):
user.is_email_verified = True
user.is_active = True
user.save()
# return redirect('home')
return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
return HttpResponse('''
Thank you for your email confirmation. Now you can login to your account. Go to :- <a href="https://downtownstimulus.com">https://downtownstimulus.com</a>
<script>
function redirect(){
window.location.href = "https://downtownstimulus.com";
}
setTimeout(redirect, 3000);
</script>
''')
else:
return HttpResponse('Activation link is invalid!')

Expand Down

0 comments on commit cd06f4a

Please sign in to comment.