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

    if request.method == 'POST':
        user_form = CreateUserForm(request.POST)
        person_form = CreatePersonForm(request.POST)

        if all((user_form.is_valid(), person_form.is_valid())):
            user = user_form.save(commit=False)
            # BETA
            try:
                Beta.objects.get(email=user.email, approved=True)
            except ObjectDoesNotExist:
                return HttpResponseRedirect(reverse('beta_reg'))


            user.first_name=user_form.cleaned_data['first_name']
            user.last_name=user_form.cleaned_data['last_name']
            user.username = user_form.cleaned_data['first_name'].lower() + user_form.cleaned_data['last_name'].lower()
            user.save()
            person = person_form.save(commit=False)
            person.user = user

            code = utils.generate_sms_code()
            person.sms_verify_code = code
            
            person.save()
            utils.send_sms_code(person.phone, code)
            return HttpResponseRedirect(reverse('user_verify_code', kwargs={'number': person.phone}))
    else:
        user_form = CreateUserForm()
        person_form = CreatePersonForm()

    context = {'user_form':user_form, 'person_form':person_form}
    return render(request, 'reminders/create_person_form.html', context)
예제 #2
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)