예제 #1
0
def registermodal(request, pk):
    route = TravelRoute.objects.get(pk=pk)
    if request.method == "POST":
        full_name = request.POST["full_name"]
        email = request.POST["email"]
        mobile_number = request.POST["mobile_number"]
        password = request.POST["password"]
        password2 = request.POST["password2"]

        if password == password2:
            if CustomUser.objects.filter(mobile_number=mobile_number).exists():
                messages.error(request, "That mobile number is already in use")
                route = TravelRoute.objects.get(pk=pk)
                return redirect("accounts:registermodal", route.pk)
            else:
                if CustomUser.objects.filter(email=email).exists():
                    messages.error(request, "That email is already taken")
                    route = TravelRoute.objects.get(pk=pk)
                    return redirect("accounts:registermodal", route.pk)
                else:
                    # Looks good
                    user = CustomUser()
                    user.full_name = full_name
                    user.email = email
                    user.mobile_number = mobile_number
                    user.password = password

                    user = CustomUser.objects.create_user(
                        full_name=full_name,
                        email=email,
                        mobile_number=mobile_number,
                        password=password,
                    )
                    user.save()

                    # Login after register
                    auth.login(request, user)
                    messages.success(request, "You are now logged in")

                    route = TravelRoute.objects.get(pk=pk)
                    return redirect("bookings:make_a_booking", route.pk)
        else:
            messages.error(request, "Passwords do not match")
            route = TravelRoute.objects.get(pk=pk)
            return redirect("accounts:registermodal", route.pk)
    else:
        route = TravelRoute.objects.get(pk=pk)
        context = {
            "route": route,
        }
        return render(request, "bookings/booking.html", context)
예제 #2
0
파일: views.py 프로젝트: nickmwangemi/Hafla
def register(request):
    if request.method == 'POST':
        # Get form values
        full_name = request.POST['full_name']
        email = request.POST['email']
        mobile_number = request.POST['mobile_number']
        password = request.POST['password']
        password2 = request.POST['password2']

        if password == password2:
            if CustomUser.objects.filter(mobile_number=mobile_number).exists():
                messages.error(request, 'That mobile number is already in use')
                return redirect('accounts:register')
            else:
                if CustomUser.objects.filter(email=email).exists():
                    messages.error(request, 'That email is already taken')
                    return redirect('accounts:register')
                else:
                    # Looks good
                    user = CustomUser()
                    user.full_name = full_name
                    user.email = email
                    user.mobile_number = mobile_number
                    user.password = password

                    user = CustomUser.objects.create_user(
                        full_name=full_name,
                        email=email,
                        mobile_number=mobile_number,
                        password=password)
                    user.save()

                    # Login after register
                    auth.login(request, user)
                    messages.success(request, 'You are now logged in')
                    return redirect('accounts:dashboard')
        else:
            messages.error(request, 'Passwords do not match')
            return redirect('accounts:register')
    else:
        return render(request, 'accounts/register.html')
예제 #3
0
def register(request):
    if request.method != "POST":
        return render(request, "accounts/register.html")
    # Get form values
    full_name = request.POST["full_name"]
    email = request.POST["email"]
    mobile_number = request.POST["mobile_number"]
    password = request.POST["password"]
    password2 = request.POST["password2"]

    if password == password2:
        if CustomUser.objects.filter(mobile_number=mobile_number).exists():
            messages.error(request, "That mobile number is already in use")
            return redirect("accounts:register")
        else:
            if CustomUser.objects.filter(email=email).exists():
                messages.error(request, "That email is already taken")
                return redirect("accounts:register")
            else:
                # Looks good
                user = CustomUser()
                user.full_name = full_name
                user.email = email
                user.mobile_number = mobile_number
                user.password = password

                user = CustomUser.objects.create_user(
                    full_name=full_name,
                    email=email,
                    mobile_number=mobile_number,
                    password=password,
                )
                user.save()

                # Login after register
                auth.login(request, user)
                messages.success(request, "You are now logged in")
                return redirect("accounts:dashboard")
    else:
        messages.error(request, "Passwords do not match")
        return redirect("accounts:register")