Skip to content

Commit

Permalink
remove extra lines of code and make minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
valaparthvi committed Jul 25, 2017
1 parent 757e724 commit 014952e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cadasta/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def verify_token(self, token, tolerance=0):
if ((totp.t() > self.last_verified_counter) and
(totp.verify(token, tolerance=tolerance))):
self.last_verified_counter = totp.t()
verified = True
self.verified = True
self.save()
else:
verified = False
return verified
self.verified = False
return self.verified
2 changes: 2 additions & 0 deletions cadasta/accounts/tests/test_views_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def test_successful_phone_verification(self):

assert response.status_code == 302
assert self.user.phone_verified is True
assert self.user.is_active is True

def test_unsuccessful_phone_verification_with_invalid_token(self):
self.device = self.user.verificationdevice_set.create(
Expand Down Expand Up @@ -387,3 +388,4 @@ def test_successful_phone_verification_new_phone(self):
assert response.status_code == 302
assert self.user.phone == '+919327768250'
assert self.user.phone_verified is True
assert self.user.is_active is True
22 changes: 11 additions & 11 deletions cadasta/accounts/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from allauth.account.utils import send_email_confirmation
from allauth.account.models import EmailAddress

from ..models import User
from ..models import User, VerificationDevice
from .. import forms


Expand Down Expand Up @@ -126,28 +126,28 @@ class ConfirmPhone(FormView):
form_class = forms.PhoneVerificationForm
success_url = reverse_lazy('account:login')

def get_user(self):
def get_device(self):
user_id = self.request.session['user_id']
user = User.objects.get(id=user_id)
return user
device = VerificationDevice.objects.get(user_id=user_id)
return device

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
user = self.get_user()
device = self.get_device()
user = device.user
context['email'] = user.email
context['phone'] = user.phone
return context

def form_valid(self, form):
user = self.get_user()
device = user.verificationdevice_set.get()
token = form.cleaned_data.get('token')
device = self.get_device()
user = device.user
if device.verify_token(token):
if user.phone == device.unverified_phone:
user.phone_verified = True
else:
if user.phone != device.unverified_phone:
user.phone = device.unverified_phone
user.phone_verified = True
user.phone_verified = True
user.is_active = True
user.save()
message = _("Successfully verified {phone}")
message = message.format(phone=user.phone)
Expand Down

0 comments on commit 014952e

Please sign in to comment.