Are you using a custom User model? Your code is very similar to the
UserCreationForm django.contrib.auth.forms, and you might want to consider
at least subclassing it so you can make use of some of its features (like
clean_username).


On Sun, Sep 8, 2013 at 11:41 AM, Anil Jangity <an...@me.com> wrote:

> class SignupForm(forms.ModelForm):
>     class Meta:
>         model = User
>         fields = ["username", "mail", "password"]
>
>     def clean_password(self):
>         password = self.cleaned_data.get("password")
>         return password
>
>     def save(self, commit=True):
>         user = super(SignupForm, self).save(commit=False)
>         print user, type(user)
>         user.set_password(self.cleaned_data["password"])
>         if commit:
>             user.save()
>         return user
>
> I copied this from some other site.
>
> On Sep 8, 2013, at 10:39 AM, Jonathan Baker <jonathandavidba...@gmail.com>
> wrote:
>
> Can you post your entire SignupForm class? I think a bit more context will
> help me diagnose.
>
>
> On Sun, Sep 8, 2013 at 11:27 AM, Anil Jangity <an...@me.com> wrote:
>
>> I tried that too earlier.
>>
>> I added these to the SignupForm class:
>>
>>     def clean_password(self):
>>         password = self.cleaned_data.get("password")
>>         return password
>>
>>     def save(self, commit=True):
>>         user = super(SignupForm, self).save(commit=False)
>>         user.set_password(self.cleaned_data["password"])
>>         if commit:
>>             user.save()
>>         return user
>>
>> That throws this exception:
>> AttributeError: 'User' object has no attribute 'set_password'
>>
>>
>> On Sep 8, 2013, at 10:06 AM, Jonathan Baker <jonathandavidba...@gmail.com>
>> wrote:
>>
>> You need to run the password through the 'set_password' method of the
>> User class to hash it. See:
>> https://docs.djangoproject.com/en/1.0/topics/auth/#django.contrib.auth.models.User.set_password
>>
>> Hope this helps,
>> JDB
>>
>>
>> On Sun, Sep 8, 2013 at 11:02 AM, Anil Jangity <an...@me.com> wrote:
>>
>>> New to Django.
>>> When I submit a signup form with this, the password is human readable in
>>> the database. It seems like it should be hashed?
>>> Looking at some Google pages, it seems I need to
>>> subclass UserCreationForm.
>>>
>>> I tried that instead of forms.ModelForm and now it complains my form
>>> doesn't have "password1" and "password2"; which is not what I want. I just
>>> want a single password field.
>>>
>>> Can someone give me pointers on how I should go about this?
>>>
>>> Thanks!
>>>
>>>
>>> Models:
>>> class User(models.Model):
>>>     name = models.CharField(max_length=32)
>>>     username = models.CharField(max_length=16, primary_key=True)
>>>     mail = models.EmailField(max_length=254)
>>>     password = models.CharField(max_length=64)
>>>     status = models.CharField(max_length=32)
>>>     create_tstamp = models.DateTimeField(auto_now_add=True)
>>>
>>>     def __unicode__(self):
>>>         user = "%s: %s, %s" % (self.username, self.mail, self.name)
>>>         return user
>>>
>>> class SignupForm(forms.ModelForm):
>>>     class Meta:
>>>         model = User
>>>         fields = ["username", "mail", "password"]
>>>
>>>
>>> View:
>>> def signup(request):
>>>     if request.POST:
>>>         form = SignupForm(request.POST)
>>>         if form.is_valid():
>>>             newUser = form.save()
>>>             return HttpResponseRedirect(reverse('dashboard'))
>>>     else:
>>>         form = SignupForm()
>>>     return render(request, "registration/signup.html", {'form': form,})
>>>
>>>
>>> I am using Bootstrap and here is my signup.html for reference:
>>>
>>>     <form class="form-signin" method="post" action="">
>>>         {% csrf_token %}
>>>         <h4 class="form-signin-heading">Signup for Globexch account</h4>
>>>         <p>It's free. You can also <a href="/login">Login</a>.</p>
>>>
>>>         {% if form.username.errors %}
>>>             <p class="alert alert-warn">{{ form.username.errors|join:",
>>> " }}</p>
>>>         {% endif %}
>>>         <input id="id_username" type="text" name="username" {% if
>>> form.username.value %}value="{{ form.username.value }}" {% endif %}
>>> class="input-block-level" placeholder="Login name">
>>>
>>>
>>>         {% if form.mail.errors %}
>>>             <p class="alert alert-warn">{{ form.mail.errors|join:", "
>>> }}</p>
>>>         {% endif %}
>>>         <input id="id_mail" type="text" name="mail" {% if
>>> form.mail.value %}value="{{ form.mail.value }}" {% endif %}
>>> class="input-block-level" placeholder="u...@example.com">
>>>
>>>
>>>         {% if form.password.errors %}
>>>             <p class="alert alert-warn">{{ form.password.errors|join:",
>>> " }}</p>
>>>         {% endif %}
>>>         <input id="id_password" type="password" name="password"
>>> class="input-block-level" placeholder="Password">
>>>
>>>         <button class="btn btn-large btn-primary" type="submit">Let me
>>> in</button>
>>>     </form>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>
>>
>> --
>> Jonathan D. Baker
>> Developer
>> http://jonathandbaker.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> --
> Jonathan D. Baker
> Developer
> http://jonathandbaker.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Jonathan D. Baker
Developer
http://jonathandbaker.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to