Esempio n. 1
0
def Contractor(request):
    registered = False
    if request.method == 'POST':
        user_from = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_from.is_valid() and profile_form.is_valid():
            user = user_from.save()
            user.set_password(user.password)
            user.save()
            # driv = profile_form.save()
            # driv.user = user
            # driv.save()

            registered = True
            return HttpResponseRedirect(reverse('index'))
        else:
            return HttpResponse("dfghjklkjhgvghj")

    else:
        user_from = UserForm()
        profile_form = UserProfileInfoForm()
        return render(
            request, 'login/registration.html', {
                'user_form': user_from,
                'profile_form': profile_form,
                'registered': registered
            })
Esempio n. 2
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'profile_pic' in request.FILES:
                print('found it')
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'registration/register.html', {
            'user_form': user_form,
            'nav': 'login',
            'title': 'Vaping.com | Register',
            'profile_form': profile_form,
            'registered': registered
        })
Esempio n. 3
0
def register(request):
    error = ""
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            if  validate(user_form.cleaned_data.get("email")):
                user = user_form.save()
                user.set_password(user.password)
                user.save()

                profile = profile_form.save(commit=False)
                profile.user = user

                if 'profile_pic' in request.FILES:
                    profile.profile_pic = request.FILES['profile_pic']

                profile.save()

                registered = True
            else:
                error = "IIITB email required"
        else:
            print(user_form.errors,profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(request,'Login/register.html',{
            'user_form':user_form,
            'profile_form':profile_form,
            'registered':registered,
            'error' : error
    })
def register(request):
    error = ""
    registered = False
    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            if validate(user_form.cleaned_data.get("email")):

                otp_no = random.randint(1000000, 9999999)
                mail = EmailMessage('Sports Room Authentication',
                                    'Authentication key: ' + str(otp_no),
                                    to=[user_form.cleaned_data.get("email")])
                mail.send()

                user = user_form.save()
                user.username = user.username.upper()
                user.set_password(user.password)
                user.save()

                profile = profile_form.save(commit=False)
                profile.user = user
                profile.otp_no = otp_no
                if 'profile_pic' in request.FILES:
                    profile.profile_pic = request.FILES['profile_pic']

                profile.save()

                registered = True
                return render(request, 'Login/otp.html', {
                    'otp_no': otp_no,
                    'email': user_form.cleaned_data.get("email")
                })
            else:
                error = "IIITB email required"
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'Login/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
            'error': error
        })
def signup(request):
    dicti = dict()
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            try:
                validate_password(user.password)
            except:
                dicti['error'] = "Password Entered Is Too Week To Be Accepted."
                dicti['user_form'] = UserForm()
                dicti['profile_form'] = UserProfileInfoForm()
                return render(request, 'login/signup.html', context=dicti)
            if User.objects.filter(email__iexact=user.email):
                dicti[
                    'error'] = "Please Select A New E-Mail. This E-Mail is already In Use."
                dicti['user_form'] = UserForm()
                dicti['profile_form'] = UserProfileInfoForm()
                return render(request, 'login/signup.html', context=dicti)
            else:
                user.set_password(user.password)
                user.save()
                profile = profile_form.save(commit=False)
                profile.user = user
                profile.save()
                return HttpResponseRedirect(reverse('login:signin'))
        else:
            dicti[
                'error'] = "Please Select A New User Name. This User Name is already In Use."
            dicti['user_form'] = UserForm()
            dicti['profile_form'] = UserProfileInfoForm()
    else:
        dicti['user_form'] = UserForm()
        dicti['profile_form'] = UserProfileInfoForm()

    return render(request, 'login/signup.html', context=dicti)