Esempio n. 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})
Esempio n. 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
    })
Esempio n. 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)
Esempio n. 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})
Esempio n. 5
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})
Esempio n. 6
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})
Esempio n. 7
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})
Esempio n. 8
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})
Esempio n. 9
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})