Bayo
Bayo

Reputation: 31

Authenticating Registrationn form in django

I have this html form that I want to use for signup of customers.

<form id='registration-form'>
                    {% csrf_token %}
                    <div class="form-group">
                      <input type="text" class="form-control input-upper" id="fullname" placeholder="John Doe" name="fullname" ><br>
                      <input type="text" class="form-control input-upper" id="username" placeholder="Username" name="username"><br>
                      <input type="email" class="form-control input-upper" id="email" placeholder="Email" name="email"><br>
                      <input type="text" class="form-control input-upper" id="organization" placeholder="Organization" name="organization"><br>
                      <input type="password" class="form-control input-upper" id="password" placeholder="Password" name="password"><br>
                      <input type="password" class="form-control input-upper" id="password" placeholder="Confirm Password" name="password"><br>
                      <small>By registering you agree to our <a href="{% url 'tos' %}">terms and conditions</a></small>
                      <button type="button" class="btn btn-primary btn-block btn-signup-form">SIGN UP</button>
                      <button type="button" class="btn btn-primary btn-block btn-sign-linkedin" href="{% url 'social:begin' 'linkedin-oauth2' %}?next={{ next }}">Sign up with LinkedIn</button>
                      <p class="text-already">Already have an account? <a href="">LOGIN</a></p>
                    </div>
                </form>

How do I make an validation of the data filled i.e the email and password and I want customers to be able to log in after signing up

Upvotes: 0

Views: 29

Answers (1)

Priyank Singh
Priyank Singh

Reputation: 41

I'm not sure what you mean by validating data but If i got you correctly you should go for Django built in functionality for user creation. Django comes with Auth module which can reduce your lot's of effort and takes care of most of the painful parts. Just have a look on this post https://simpleisbetterthancomplex.com/tutorial/2017/02/18/how-to-create-user-sign-up-view.html

If you want simple validations you can use clean methods of Django Form. write one form class with the same fields as you mentioned. EX.

Class  SignupForm2(forms.ModelForm ):
  class Meta:
       model = User 

  def clean(self):
      self.cleaned_data = super(SignupForm2, self).clean()

        if 'captcha' in self._errors and self._errors['captcha'] != ["This field is required."]:
        self._errors['captcha'] = ["Please enter a correct value"]
    return self.cleaned_data

Upvotes: 1

Related Questions