コード例 #1
0
ファイル: views.py プロジェクト: vetleen/vetletemplate
def sign_up(request):
    """View function for signing up."""
    #logged in users are redirected
    if request.user.is_authenticated:
        messages.error(request, 'You are already signed in, and can\'t make a new account until you sign out.', extra_tags='alert alert-warning')
        return render(request, 'you_did_something.html')

    form = SignUpForm
    context = {
        'form': form,
        'submit_button_text': 'Sign up',
    }
    # If this is a POST request then process the Form data
    if request.method == 'POST':

        # Create a form instance and populate it with data from the request (binding):
        form = SignUpForm(request.POST)
        context.update({'form': form})
        # Check if the form is valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required (here we just write it to the model due_back field)
            user = User.objects.create_user(form.cleaned_data['username'], form.cleaned_data['username'], form.cleaned_data['password'])
            user.save()
            messages.success(request, 'Welcome aboard. This is your dashboard, where you can....', extra_tags='alert alert-success')
            if user is not None:
                auth.login(request, user)
            # redirect to a new URL:

            return HttpResponseRedirect(reverse('dashboard'))

    return render(request, 'sign_up_form.html', context)
コード例 #2
0
 def setUp(self):
     self.form = SignUpForm()
     self.form.fields['username'] = '******'
     self.form.fields['first_name'] = 'testfirstname'
     self.form.fields['last_name'] = 'testlastname'
     self.form.fields['email'] = 'testemail'
     self.form.fields['password1'] = 'testpassword'
     self.form.fields['password2'] = 'testpassword'
     self.form.__init__()
コード例 #3
0
 def test_signup_form_valid(self):
     """Signup valid test"""
     form = SignUpForm(
         data={
             'first_name': 'first_name',
             'last_name': 'last_name',
             'email': '*****@*****.**',
             'password1': 'ldoehs154',
             'password2': 'ldoehs154',
         })
     self.assertTrue(form.is_valid())
コード例 #4
0
ファイル: routes.py プロジェクト: MHDFahz/WEBSITE
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = SignUpForm()
    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(f'Acoount is created succesfully for {form.username.data}! Now you Can Login', 'success')
        return redirect(url_for('login'))
    return render_template('signup.html',title='Sign Up',form=form)
コード例 #5
0
class SignUpFormTest(TestCase):
    def setUp(self):
        self.form = SignUpForm()
        self.form.fields['username'] = '******'
        self.form.fields['first_name'] = 'testfirstname'
        self.form.fields['last_name'] = 'testlastname'
        self.form.fields['email'] = 'testemail'
        self.form.fields['password1'] = 'testpassword'
        self.form.fields['password2'] = 'testpassword'
        self.form.__init__()

    def test_signup_form_first_name_field_label(self):
        self.assertTrue(
            self.form.fields['first_name'].label is None
            or self.form.fields['first_name'].label == 'first name')

    def test_signup_form_last_name_field_label(self):
        self.assertTrue(self.form.fields['last_name'].label is None
                        or self.form.fields['last_name'].label == 'last name')

    def test_signup_form_email_field_label(self):
        self.assertTrue(self.form.fields['email'].label is None
                        or self.form.fields['email'].label == 'email')

    def test_signup_form_first_name_field_help_text(self):
        self.assertEqual(self.form.fields['first_name'].help_text,
                         'Entrez votre prénom.')

    def test_signup_form_last_name_field_help_text(self):
        self.assertEqual(self.form.fields['last_name'].help_text,
                         'Entrez votre nom.')

    def test_signup_form_email_field_help_text(self):
        self.assertEqual(self.form.fields['email'].help_text,
                         'Entrez une adresse email valide.')

    def test_signup_form_first_name_field_max_length(self):
        self.assertEqual(self.form.fields['first_name'].max_length, 30)

    def test_signup_form_last_name_field_max_length(self):
        self.assertEqual(self.form.fields['last_name'].max_length, 30)

    def test_signup_form_email_field_max_length(self):
        self.assertEqual(self.form.fields['email'].max_length, 254)

    def test_signup_form_field_class_is_form_control(self):
        for visible in self.form.visible_fields():
            self.assertEqual(visible.field.widget.attrs['class'],
                             'form-control')
コード例 #6
0
    def setUp(self):
        self.user = User.objects.create(username='******',
                                        first_name='firstname',
                                        last_name='lastname',
                                        email='*****@*****.**',
                                        password='******')

        self.form = SignUpForm(
            data={
                'username': '******',
                'first_name': 'firstname',
                'last_name': 'lastname',
                'email': '*****@*****.**',
                'password1': 'okabc321',
                'password2': 'okabc321'
            })
コード例 #7
0
ファイル: test_forms.py プロジェクト: liorco15/HealthTourism
 def test_sign_up_form(self):
     form = SignUpForm(
         data={
             'model': ['SignUp'],
             'fields': [
                 'lior', 'inbar', 16, 'man', 'dinab@gmail', +972855555555,
                 'Canada', 'write'
             ]
         })
コード例 #8
0
def sign_up():
    form = SignUpForm(request.form)
    next_url = request.args.get('next')
    if next_url:
        form.next.data = next_url
    if request.method == 'POST' and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            form.email.errors.append('This email already exists.')
        else:
            role = Role.query.filter_by(name=app.config['DEFAULT_ROLE']).first()
            user = form.to_user()
            user.role_id = role.id
            db.session.add(user)
            db.session.commit()
            next_url = form.next.data
            sign_in_url = url_for('account.sign_in', next=next_url) if next_url \
                else url_for('account.sign_in')
            return redirect(sign_in_url)
    return render_template('account/sign_up.html', form=form)
コード例 #9
0
class SignUpFormTest(TestCase):
    """ Test case for SignUpForm """
    def setUp(self):
        self.user = User.objects.create(username='******',
                                        first_name='firstname',
                                        last_name='lastname',
                                        email='*****@*****.**',
                                        password='******')

        self.form = SignUpForm(
            data={
                'username': '******',
                'first_name': 'firstname',
                'last_name': 'lastname',
                'email': '*****@*****.**',
                'password1': 'okabc321',
                'password2': 'okabc321'
            })

    def test_valid_form(self):
        """ Test valid SignUp form """

        self.assertTrue(self.form.is_valid())

    def test_remove_username(self):
        """ Test invalid SignUp form (removing username) """

        invalid_form = self.form
        del invalid_form.data['email']
        self.assertFalse(invalid_form.is_valid())

    def test_invalid_email(self):
        """ Test invalid SignUpForm email """

        invalid_form = self.form
        invalid_form.data['email'] = 'ok'
        self.assertFalse(invalid_form.is_valid())

    def test_invalid_password1(self):
        """ Test invalid SignUpForm password1 """

        invalid_form = self.form
        invalid_form.data['password1'] = 'ok'
        self.assertFalse(invalid_form.is_valid())

    def test_invalid_password2(self):
        """ Test invalid SignUpForm password2 """

        invalid_form = self.form
        invalid_form.data['password2'] = 'ok'
        self.assertFalse(invalid_form.is_valid())
コード例 #10
0
ファイル: views.py プロジェクト: adaltopicotti/logic4
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('home')
    else:
        form = SignUpForm()
    return render(request, 'website/accounts/signup.html', {'form': form})
コード例 #11
0
def signup(request):
    """A view that displays the new account registration form."""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
コード例 #12
0
def signup(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('index')
    else:
        form = SignUpForm()
    return render(request, 'website/signup.html', {'form': form})
コード例 #13
0
ファイル: form_tests.py プロジェクト: CS130-W20/team-A9
 def test_company_success(self):
     d = self.company_data.copy()
     form = SignUpForm(d, user_type="C")
     self.assertTrue(form.is_valid())
コード例 #14
0
ファイル: form_tests.py プロジェクト: CS130-W20/team-A9
 def test_homeless_failure(self):
     d = self.homeless_data.copy()
     d["last_name"] = ""
     form = SignUpForm(d, user_type="H")
     self.assertFalse(form.is_valid())
コード例 #15
0
ファイル: form_tests.py プロジェクト: CS130-W20/team-A9
 def test_homeless_success(self):
     d = self.homeless_data.copy()
     form = SignUpForm(d, user_type="H")
     self.assertTrue(form.is_valid())
コード例 #16
0
ファイル: form_tests.py プロジェクト: CS130-W20/team-A9
 def test_volunteer_failure(self):
     d = self.volunteer_data.copy()
     d["car_make"] = ""
     form = SignUpForm(d, user_type="V")
     self.assertFalse(form.is_valid())
コード例 #17
0
ファイル: form_tests.py プロジェクト: CS130-W20/team-A9
 def test_volunteer_success(self):
     form = SignUpForm(self.volunteer_data.copy(), user_type="V")
     self.assertTrue(form.is_valid())
コード例 #18
0
def sign_up(request):
    """View function for signing up."""
    #logged in users are redirected
    if request.user.is_authenticated:
        messages.error(
            request,
            _('You are already signed in, and can\'t make a new account until you sign out.'
              ),
            extra_tags='alert alert-warning')
        return render(request, 'you_did_something.html')

    #mark an event - someone visited this site
    event = Event(category='visited_sign_up_view')
    event.save()

    #create the form
    form = SignUpForm
    context = {'form': form, 'submit_button_text': _('Sign up', )}
    # If this is a POST request then process the Form data
    if request.method == 'POST':

        # Create a form instance and populate it with data from the request (binding):
        form = SignUpForm(request.POST)
        context.update({'form': form})
        # Check if the form is valid:
        if form.is_valid():

            # process the data in form.cleaned_data as required (here we just write it to the model due_back field)
            user = User.objects.create_user(form.cleaned_data['username'],
                                            form.cleaned_data['username'],
                                            form.cleaned_data['password'])
            user.save()
            organization = Organization(
                owner=user,
                phone=form.cleaned_data['phone'],
                name=form.cleaned_data['name'],
                address_line_1=form.cleaned_data['address_line_1'],
                address_line_2=form.cleaned_data['address_line_2'],
                zip_code=form.cleaned_data['zip_code'],
                city=form.cleaned_data['city'],
                country=form.cleaned_data['country'],
                accepted_terms_and_conditions=form.
                cleaned_data['accepted_terms_and_conditions'],
            )
            organization.save()
            messages.success(
                request,
                _("Welcome aboard. Let's start by adding some employees to survey!"
                  ),
                extra_tags='alert alert-success')
            send_mail(
                '[www] New user: %s!' % (user.username),
                'User: %s has signed up!' % (user.username),
                '*****@*****.**',
                ['*****@*****.**'],
                fail_silently=True,
            )
            if user is not None:
                auth.login(request, user)

            #mark an event - someone signed up successfully
            event = Event(category='completed_sign_up', user=user)
            event.save()

            # redirect to a new URL:
            return HttpResponseRedirect(reverse('surveys-dashboard'))
        else:
            #mark an event - someone failed to sign up
            comment = ""
            for field in form.visible_fields():
                if field.field.label != _(
                        "Choose a password") and field.field.label != _(
                            "Confirm password"):
                    field_data = "%s: %s \n" % (field.field.label, field.data)
                    comment += (field_data)
            event = Event(category='failed_sign_up', comment=comment)
            event.save()
    return render(request, 'sign_up_form.html', context)
コード例 #19
0
 def test_signup_form_invalid(self):
     """Signup invalid test"""
     form = SignUpForm(data={})
     self.assertFalse(form.is_valid())