예제 #1
0
def signup(request):
    message = "" # help messages for user
    if request.method == 'POST':
        form = SignUpForm(request.POST) # get form filled by user
        if form.is_valid(): # django validations
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            email = form.cleaned_data.get('email')
            if isEmailValid(email): #verify this email is not already in use
                form.save() # save new user
                newUser = User.objects.filter(username = username, email = email)[0]

                sp = Savings_Percentage(user = newUser)
                sp.save() #create new register for this new user regarding her/his desired saving amount

                #saving = Savings(user = newUser, month=datetime.now().month, year=datetime.now().year)
                #saving.save() # create new register for new user in which we will know how much is she/he saving

                return redirect('../login/')
            else:
                message = "not valid email"
        else:
            print("form not valid")
            message = form.errors # gather error messages to show to user
    form = SignUpForm()
    return render(request, 'registration/signup.html',{'form': form, 'message': message})
예제 #2
0
def signup(request):
    #use case: Sign Up
    message = ""  # help messages for user
    if request.method == 'POST':
        form = SignUpForm(request.POST)  # get form filled by user
        if form.is_valid():  # django validations
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            email = form.cleaned_data.get('email')
            form.save()
            user = authenticate(username=username, password=raw_password)
            score = Scores(user=user,
                           problem1_status="not solved",
                           problem2_status="not solved",
                           problem3_status="not solved",
                           score=0.00)
            score.save()
            login(request, user)
            return redirect('/')
        else:
            print("form not valid")
            message = form.errors  # gather error messages to show to user
    form = SignUpForm()
    return render(request, 'registration/signup.html', {
        'form': form,
        'message': message
    })
예제 #3
0
def signup(request):
    form = SignUpForm()
    registered = False
    if request.method == 'POST':
        form = SignUpForm(data=request.POST)
        if form.is_valid():
            form.save()
            registered = True
    dict = {'form': form, 'registered': registered}
    return render(request, 'login/signup.html', context=dict)
예제 #4
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('login')
    else:
        form = SignUpForm()
    return render(request, "signup.html", {'form': form})
예제 #5
0
    def test_user_signup_form_is_valid(self):

        signup_form = {
            'username': '******',
            'first_name': 'Test',
            'last_name': 'User',
            'email': '*****@*****.**',
            'password1': 'testpassword12',
            'password2': 'testpassword12',
        }

        form = SignUpForm(data=signup_form)
        self.assertTrue(form.is_valid())
예제 #6
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        form2 = PhoneDetailsForm(request.POST)
        if form.is_valid():
            ''' Begin reCAPTCHA validation '''
            recaptcha_response = request.POST.get('g-recaptcha-response')
            url = 'https://www.google.com/recaptcha/api/siteverify'
            values = {
                'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
                'response': recaptcha_response
            }
            data = urllib.parse.urlencode(values).encode()
            req = urllib.request.Request(url, data=data)
            response = urllib.request.urlopen(req)
            result = json.loads(response.read().decode())
            ''' End reCAPTCHA validation '''

            if result['success']:
                print("Success")
                form.save()

                phone = form2.save(commit=False)
                phone.username = form.cleaned_data['username']
                phone.save()

                user = form.save(commit=False)
                user.is_active = False
                user.save()

                current_site = get_current_site(request)
                subject = 'Activate Your MySite Account'
                message = render_to_string(
                    'account_activation_email.html', {
                        'user': user,
                        'domain': current_site.domain,
                        'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                        'token': account_activation_token.make_token(user),
                    })
                user.email_user(subject, message)

                return redirect('account_activation_sent')
            else:
                messages.error(request,
                               'Invalid reCAPTCHA. Please try again.',
                               extra_tags='safe')
    else:
        form = SignUpForm()
        form2 = PhoneDetailsForm()
    return render(request, 'signup.html', {'form': form, 'form2': form2})
예제 #7
0
def registrar_participante(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()  # load the profile instance created by the signal
            user.profile.birth_date = form.cleaned_data.get('birth_date')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            return redirect('participantes')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
예제 #8
0
    def test_signup_form_adds_user(self):

        signup_form = {
            'username': '******',
            'first_name': 'Test',
            'last_name': 'User',
            'email': '*****@*****.**',
            'password1': 'testpassword12',
            'password2': 'testpassword12',
        }

        form = SignUpForm(data=signup_form)
        self.assertTrue(form.is_valid())
        self.client.post(reverse('login:signup'), signup_form, follow=True)

        self.assertEqual(len(User.objects.all()), 1)
예제 #9
0
def signUpRequest(request):
    message = ""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            email = form.cleaned_data.get('email')
            if isEmailValid(email):
                form.save()
                return redirect('../login/')
            else:
                message = "not valid email"
        else:
            print("form not valid")
            message = form.errors
    form = SignUpForm()
    return render(request, 'registration/registro.html',{'form': form, 'message': message})
예제 #10
0
def signup(request):
    if 'UserName' in request.session:
        return redirect("/")
    else:
        form = SignUpForm()
        if request.method == "POST":
            form = SignUpForm(request.POST)
            password = request.POST.get("Password")
            confirmPassword = request.POST.get("ConfirmPassword")
            if password == confirmPassword:
                if form.is_valid():
                    form.save(commit=True)
                    return redirect("login")
            else:
                return render(request, 'login/signup.html', {
                    'form': form,
                    'msg': "Passwords does not match"
                })
        return render(request, 'login/signup.html', {'form': form})
예제 #11
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            subject = 'Activate Your MySite Account'
            message = render_to_string(
                'activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)
            return redirect('account_activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
예제 #12
0
def signup(request):
    if request.user.is_anonymous():
        if request.method == "POST":
            signupForm = SignUpForm(request.POST)
            if signupForm.is_valid():
                signupForm = signupForm.clean()

                userName = signupForm['username']
                userMail = signupForm['email']
                password = signupForm['password']
                user = User.objects.create_user(userName, userMail, password)
                user.save()

                login(request)
                messages.success(request, "User account created succesfully")
                return HttpResponseRedirect('/home')
            else:
                messages.error(request, "Please check the entered form")
        else:
            signupForm = SignUpForm()
        return render(request, "login/signup.html", {"signupForm": signupForm})
    else:
        return HttpResponseRedirect("/home/")
예제 #13
0
    def test_signup_form_invalid(self):

        form = SignUpForm(data={})
        self.assertFalse(form.is_valid())
        self.assertEqual(len(form.errors), 4)