Exemplo n.º 1
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
        })
Exemplo n.º 2
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
    })
Exemplo 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")):

                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
        })
Exemplo n.º 4
0
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)