예제 #1
0
파일: views.py 프로젝트: Circle-Labs/upkeep
def login_view(request, number):

    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('contacts'))

    if request.method == 'POST':
        parsed = ""
        try:
            parsed = utils.parse_phone_number(request.POST['phone'])
            person = Person.objects.get(phone=parsed)
        except ObjectDoesNotExist:
            return HttpResponseRedirect(reverse('user_verify_code'))
            
        user = authenticate(phone=parsed, code=request.POST['verify_code'])
        if user is not None:
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect(reverse('contacts'))
            else:
                print('not active')
        else:
            print('invalid login')

    context = {'number':number}

    return render(request, 'reminders/login_form.html', context)
예제 #2
0
파일: forms.py 프로젝트: Circle-Labs/upkeep
	def clean_phone(self):
		phone = self.cleaned_data['phone']

		parsed = utils.parse_phone_number(phone)
		if parsed == "1":
			self.add_error("phone", "Phone number is invalid")
		else:
			return parsed
예제 #3
0
파일: forms.py 프로젝트: Circle-Labs/upkeep
	def clean_phone(self):
		phone = self.cleaned_data.get('phone')
		parsed = utils.parse_phone_number(phone)
		if parsed == "1":
			self.add_error("phone", "Phone number is invalid")
		elif Person.objects.filter(phone=parsed).count():
			self.add_error("phone", "Someone has already registered this number!")
		else:
			return parsed
예제 #4
0
파일: views.py 프로젝트: Circle-Labs/upkeep
def verification_view(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('contacts'))

    if request.method == 'POST':
        try:
            person = Person.objects.get(phone=utils.parse_phone_number(request.POST['phone']))
        except ObjectDoesNotExist:
            return HttpResponseRedirect(reverse('user_login'))

        code = utils.generate_sms_code()
        person.sms_verify_code = code
        print(code)
        person.save()
        utils.send_sms_code(person.phone, code)

        url = reverse('user_verify_code', kwargs={'number':request.POST['phone']})
        return HttpResponseRedirect(url)
    context = {'number':''} 
    return render(request, 'reminders/send_code_form.html', context)