Example #1
0
def registration_view(request):
    form = RegistrationForm(request.POST)
    if form.is_valid():
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        user = User.objects.create_user(username=username, password=password)
        user = authenticate(username=username, password=password)
        login(request, user)
    return HttpResponseRedirect(reverse_lazy('home:homepage'))
Example #2
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Welcome To Stock Watch you can now log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
def register(request):
    #Validates user credential during registration like passward length,
    #Unique user name and valid message regardingly.
    if request.method == "POST":
        k, val = False, '3'
        form2 = RegistrationForm(request.POST)
        if form2.is_valid():
            k = True
            if len(request.POST.get('Password')) == 8:
                uname = request.POST.get('Username')
                for i in Registration.objects.all():
                    if i.Username == uname:
                        val = '2'
                        break
                else:
                    try:
                        form2.save()
                        messages.success(request, 'Registered Successfully')
                        return render(request, 'home.html')
                    except:
                        pass
            else:
                val = '1'
        form2 = RegistrationForm()
        return render(request, "registration.html", {
            'form2': form2,
            "flag": k,
            'val': val
        })
Example #4
0
def register(request):
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('login')
        else:
            return HttpResponse("Ooopss!! Something was wrong with your information. Please go back and try again.")
    else:
        form = RegistrationForm()

        arg = {'form': form}
        return render(request, 'homepage/register.html', arg)
Example #5
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid:  #all the fields are validated
            form.save()  #creates user and save data in database
            return redirect('/register/complete')

    else:  #requesting for the blank form to fill in
        form = RegistrationForm()

        args = {'form': form}
        return render(request, 'homepage/reg_form.html', args)
Example #6
0
 def test_password_case_sensitive(self):
     # If cases of password & confirmation do not match, FALSE
     data = {'firstName': "Foo", 'lastName': "Bar", 'email': "*****@*****.**", 'password1': "PaSS", 'password2': "pass"}
     form = RegistrationForm(data=data)
     self.assertFalse(form.is_valid())
Example #7
0
 def test_email_valid_format(self):
     # If email is of the correct format, e.g. [email protected]; TRUE
     data = {'firstName': "Foo", 'lastName': "Bar", 'email': "*****@*****.**", 'password1': "pass", 'password2': "pass"}
     form = RegistrationForm(data=data)
     self.assertTrue(form.is_valid())
Example #8
0
 def test_lastName_too_long(self):
     # If lastName is over 30 characters, FALSE
     data = {'firstName': "foo", 'lastName': "foobarfoobarfoobarfoobarfoobar1", 'email': "*****@*****.**", 'password1': "pass", 'password2': "pass"}
     form = RegistrationForm(data=data)
     self.assertFalse(form.is_valid())
Example #9
0
 def test_lastName_max_length(self):
     # If last name is max length, TRUE
     data = {'firstName': "foo", 'lastName': "foobarfoobarfoobarfoobarfoobar", 'email': "*****@*****.**", 'password1': "pass", 'password2': "pass"}
     form = RegistrationForm(data=data)
     self.assertTrue(form.is_valid())
Example #10
0
 def test_no_password_confirmation(self):
     # If password confirmation is missing, FALSE
     data = {'firstName': "Foo", 'lastName': "Bar", 'email': "*****@*****.**", 'password1': "pass", 'password2': ""}
     form = RegistrationForm(data=data)
     self.assertFalse(form.is_valid())
Example #11
0
 def test_no_email(self):
     # If email is missing, FALSE
     data = {'firstName': "Foo", 'lastName': "Bar", 'email': "", 'password1': "pass", 'password2': "pass"}
     form = RegistrationForm(data=data)
     self.assertFalse(form.is_valid())
Example #12
0
 def test_valid_input(self):
     # If form is complete, with valid input, TRUE
     data = {'firstName': "Foo", 'lastName': "Bar", 'email': "*****@*****.**", 'password1': "pass", 'password2': "pass"}
     form = RegistrationForm(data=data)
     self.assertTrue(form.is_valid())
Example #13
0
 def test_no_input(self):
     # If form has no input, FALSE
     data = {'firstName': "", 'lastName': "", 'email': "", 'password1': "", 'password2': ""}
     form = RegistrationForm(data=data)
     self.assertFalse(form.is_valid())
Example #14
0
 def test_password_no_match(self):
     # If password & confirmation do not match, FALSE
     data = {'firstName': "Foo", 'lastName': "Bar", 'email': "*****@*****.**", 'password1': "pass1", 'password2': "pass2"}
     form = RegistrationForm(data=data)
     self.assertFalse(form.is_valid())
Example #15
0
 def test_password_too_long(self):
     # If password exceeds max length (>12), FALSE
     data = {'firstName': "Foo", 'lastName': "Bar", 'email': "*****@*****.**", 'password1': "passpasspass1", 'password2': "passpasspass1"}
     form = RegistrationForm(data=data)
     self.assertFalse(form.is_valid())
Example #16
0
 def test_password_max_length(self):
     # If password is of max length (12), TRUE
     data = {'firstName': "Foo", 'lastName': "Bar", 'email': "*****@*****.**", 'password1': "passpasspass", 'password2': "passpasspass"}
     form = RegistrationForm(data=data)
     self.assertTrue(form.is_valid())
Example #17
0
 def test_email_unsw_format(self):
     # If email ends with "unsw.edu.au", TRUE
     data = {'firstName': "Foo", 'lastName': "Bar", 'email': "*****@*****.**", 'password1': "pass", 'password2': "pass"}
     form = RegistrationForm(data=data)
Example #18
0
def devview(request):
    if request.method == "POST":
        user_form = RegistrationForm(request.POST)
        event = request.POST['event_selected']
        email = request.POST['email']
        # add txn_id check here
        if RegistrationModel.objects.filter(txn_id=request.POST['txn_id']):
            return HttpResponse(json.dumps({
                "message":
                "Transaction ID is already Registered",
            }),
                                content_type="application/json")
        if user_form.is_valid():
            recaptcha_response = request.POST['g-recaptcha-response']
            values = {
                'secret':
                "6LcIvnIUAAAAAJumlie4zUhQy4y7I20ufzCvOrxF",  #ABHI's key
                'response': recaptcha_response,
            }
            data = urllib.parse.urlencode(values)
            data = data.encode('utf-8')
            apiurl = "https://www.google.com/recaptcha/api/siteverify"
            req = urlRequest.Request(apiurl, data)
            response = urlRequest.urlopen(req)
            result = json.load(response)
            if result['success']:
                new_data = RegistrationModel(
                    number=len(RegistrationModel.objects.all()) + 1,
                    coord_id=user_form.cleaned_data['coord_id'],
                    name=user_form.cleaned_data['name'],
                    phone=user_form.cleaned_data['phone'],
                    email=email,
                    college=user_form.cleaned_data['college'],
                    year=user_form.cleaned_data['year'],
                    event=event,
                    txn_id=user_form.cleaned_data['txn_id'],
                    amount=user_form.cleaned_data['amount'])
                new_data.save()
                sendEmail(email,
                          event,
                          name=user_form.cleaned_data['name'],
                          phone=user_form.cleaned_data['phone'],
                          college=user_form.cleaned_data['college'],
                          year=user_form.cleaned_data['year'],
                          txn_id=user_form.cleaned_data['txn_id'],
                          amount=user_form.cleaned_data['amount'])
                return HttpResponse(json.dumps({
                    "message": "success",
                }),
                                    content_type="application/json")
            else:
                return HttpResponse(json.dumps({
                    "message":
                    "reCaptcha Verification Failed!",
                }),
                                    content_type="application/json")
        else:
            return HttpResponse(json.dumps({
                "message":
                "Please re-check the details entered",
            }),
                                content_type="application/json")
    elif request.method == "GET":
        return HttpResponseRedirect("/admin")