def account(request, email): user = None if email: user = get_object_or_404(User, username=email) if request.method == 'POST': email = request.POST['email'] mobile_num = to_e164(request.POST['mobile_num']) password = request.POST['password'] if not user: if password == request.POST['confirm']: user = User.objects.create(username=email, email=email) user.set_password(password) user.save() UserProfile.objects.create(user=user).save() send_confirmation_text(user, mobile_num) user = auth.authenticate(username=user.username, password=password) auth.login(request, user) try: route_json = request.session['route_json'] except IndexError: pass else: r = Route(user=request.user, json=route_json, start_time=request.POST['start_time']) r.save() profile_data = {'mobile_num': mobile_num} UserProfile.objects.filter(user=user).update(**profile_data) return redirect('myroutes') profile = user.get_profile() if user else None return render(request, 'account.html', {'user': user, 'profile': profile})
def account_sms_confirm(request): mobile_num = to_e164(request.POST['From']) profile = UserProfile.objects.get(mobile_num=mobile_num) profile.mobile_confirmed = True profile.save() return render(request, 'account_sms_confirm.xml', {'Sms': THANK_YOU_TEXT}, content_type='application/xml')