Re: custom signup form

2013-09-08 Thread Germán
Anil, please beware that there are lots of code posted on the internet, 
many of which are faulty or at least don't follow best or standard 
practices. Copy & pasting will bite you, sooner or later. I recommend you 
to go over the (excellent) documentation of Django before actually working 
with some feature/topic of the framework.

Cheers

On Sunday, September 8, 2013 12:41:06 PM UTC-5, Anil 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 
>  
> 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  >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 
>>  
>> 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 > > 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:
>>>
>>> 
>>> {% csrf_token %}
>>> Signup for Globexch account
>>> It's free. You can also Login.
>>>
>>> {% if form.username.errors %}
>>> {{ form.username.errors|join:", 
>>> " }}
>>> {% endif %}
>>> >> form.username.value %}value="{{ form.username.value }}" {% endif %} 
>>> class="input-block-level" placeholder="Login name">
>>>
>>>
>>> {% if form.mail.errors %}
>>> {{ form.mail.errors|join:", " 
>>> }}
>>> {% endif %}
>>> >> form.mail.value %}value="{{ form.mail.value }}" {% endif %} 
>>> class="input-block-level" placeholder="us...@example.com ">
>>>
>>>
>>> {% if form.password.errors %}
>>> {{ form.password.errors|join:", 
>>> " }}
>>> {% endif %}
>>> >> class="input-block-level" placeholder="Password">
>>>
>>> Let me 
>>> in
>>> 
>>>
>>>
>>> -- 
>>> 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...@googlegroups.com .
>>> To post to this group, send email to django...@googlegroups.com
>>> .
>>> 

Re: custom signup form

2013-09-08 Thread Jonathan Baker
Ah, I missed that you included your model in your original email. You're
definitely using a custom User class (anything other than
django.contrib.auth.models.User), which explains why it can't find the
set_password() method.

Which version of Django are you developing with? If you definitely need to
go the custom User model route, you'll want to read about everything this
entails: 
https://docs.djangoproject.com/en/dev/topics/auth/customizing/


On Sun, Sep 8, 2013 at 11:57 AM, Anil Jangity  wrote:

> No, I am not using the custom user model, but it seems like I should be?
> (even though, I don't think I am changing anything that requires this). I
> still have user name as the authenticator.
>
> When I subclass UserCreationForm, it was complaining about not having
> password1 and 2 not in my form.
>
> On Sep 8, 2013, at 10:52 AM, Jonathan Baker 
> wrote:
>
> 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  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 
>> 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  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  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:

 
 {% csrf_token %}
 Signup for Globexch account
 It's free. You can also Login.

 {% if form.username.errors %}
 {{ 

Re: custom signup form

2013-09-08 Thread Anil Jangity
No, I am not using the custom user model, but it seems like I should be? (even 
though, I don't think I am changing anything that requires this). I still have 
user name as the authenticator.

When I subclass UserCreationForm, it was complaining about not having password1 
and 2 not in my form.

On Sep 8, 2013, at 10:52 AM, Jonathan Baker  
wrote:

> 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  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  
> 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  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  
>> 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  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:
>>> 
>>> 
>>> {% csrf_token %}
>>> Signup for Globexch account
>>> It's free. You can also Login.
>>> 
>>> {% if form.username.errors %}
>>> {{ form.username.errors|join:", " 
>>> }}
>>> {% endif %}
>>> >> form.username.value %}value="{{ form.username.value }}" {% endif %} 
>>> class="input-block-level" placeholder="Login name">
>>> 
>>> 
>>> {% if form.mail.errors %}
>>> {{ form.mail.errors|join:", " }}
>>> {% endif %}
>>> >> %}value="{{ form.mail.value }}" {% endif %} class="input-block-level" 
>>> placeholder="u...@example.com">
>>> 
>>> 
>>> {% if form.password.errors %}
>>> {{ form.password.errors|join:", " 
>>> }}
>>> {% endif %}
>>> >> class="input-block-level" placeholder="Password">
>>> 
>>> Let me 
>>> in
>>> 
>>> 
>>> 
>>> -- 

Re: custom signup form

2013-09-08 Thread Jonathan Baker
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  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 
> 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  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 
>> 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  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:
>>>
>>> 
>>> {% csrf_token %}
>>> Signup for Globexch account
>>> It's free. You can also Login.
>>>
>>> {% if form.username.errors %}
>>> {{ form.username.errors|join:",
>>> " }}
>>> {% endif %}
>>> >> form.username.value %}value="{{ form.username.value }}" {% endif %}
>>> class="input-block-level" placeholder="Login name">
>>>
>>>
>>> {% if form.mail.errors %}
>>> {{ form.mail.errors|join:", "
>>> }}
>>> {% endif %}
>>> >> form.mail.value %}value="{{ form.mail.value }}" {% endif %}
>>> class="input-block-level" placeholder="u...@example.com">
>>>
>>>
>>> {% if form.password.errors %}
>>> {{ form.password.errors|join:",
>>> " }}
>>> {% endif %}
>>> >> class="input-block-level" placeholder="Password">
>>>
>>> Let me
>>> in
>>> 
>>>
>>>
>>> --
>>> 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.

Re: custom signup form

2013-09-08 Thread Anil Jangity
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  
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  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  
> 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  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:
>> 
>> 
>> {% csrf_token %}
>> Signup for Globexch account
>> It's free. You can also Login.
>> 
>> {% if form.username.errors %}
>> {{ form.username.errors|join:", " 
>> }}
>> {% endif %}
>> > form.username.value %}value="{{ form.username.value }}" {% endif %} 
>> class="input-block-level" placeholder="Login name">
>> 
>> 
>> {% if form.mail.errors %}
>> {{ form.mail.errors|join:", " }}
>> {% endif %}
>> > %}value="{{ form.mail.value }}" {% endif %} class="input-block-level" 
>> placeholder="u...@example.com">
>> 
>> 
>> {% if form.password.errors %}
>> {{ form.password.errors|join:", " 
>> }}
>> {% endif %}
>> > class="input-block-level" placeholder="Password">
>> 
>> Let me 
>> in
>> 
>> 
>> 
>> -- 
>> 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 

Re: custom signup form

2013-09-08 Thread Jonathan Baker
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  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 
> 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  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:
>>
>> 
>> {% csrf_token %}
>> Signup for Globexch account
>> It's free. You can also Login.
>>
>> {% if form.username.errors %}
>> {{ form.username.errors|join:", "
>> }}
>> {% endif %}
>> > form.username.value %}value="{{ form.username.value }}" {% endif %}
>> class="input-block-level" placeholder="Login name">
>>
>>
>> {% if form.mail.errors %}
>> {{ form.mail.errors|join:", "
>> }}
>> {% endif %}
>> > %}value="{{ form.mail.value }}" {% endif %} class="input-block-level"
>> placeholder="u...@example.com">
>>
>>
>> {% if form.password.errors %}
>> {{ form.password.errors|join:", "
>> }}
>> {% endif %}
>> > class="input-block-level" placeholder="Password">
>>
>> Let me
>> in
>> 
>>
>>
>> --
>> 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 

Re: custom signup form

2013-09-08 Thread Anil Jangity
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  
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  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:
> 
> 
> {% csrf_token %}
> Signup for Globexch account
> It's free. You can also Login.
> 
> {% if form.username.errors %}
> {{ form.username.errors|join:", " 
> }}
> {% endif %}
>  form.username.value %}value="{{ form.username.value }}" {% endif %} 
> class="input-block-level" placeholder="Login name">
> 
> 
> {% if form.mail.errors %}
> {{ form.mail.errors|join:", " }}
> {% endif %}
>  %}value="{{ form.mail.value }}" {% endif %} class="input-block-level" 
> placeholder="u...@example.com">
> 
> 
> {% if form.password.errors %}
> {{ form.password.errors|join:", " 
> }}
> {% endif %}
>  class="input-block-level" placeholder="Password">
> 
> Let me 
> in
> 
> 
> 
> -- 
> 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.


Re: custom signup form

2013-09-08 Thread Jonathan Baker
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  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:
>
> 
> {% csrf_token %}
> Signup for Globexch account
> It's free. You can also Login.
>
> {% if form.username.errors %}
> {{ form.username.errors|join:", "
> }}
> {% endif %}
>  form.username.value %}value="{{ form.username.value }}" {% endif %}
> class="input-block-level" placeholder="Login name">
>
>
> {% if form.mail.errors %}
> {{ form.mail.errors|join:", "
> }}
> {% endif %}
>  %}value="{{ form.mail.value }}" {% endif %} class="input-block-level"
> placeholder="u...@example.com">
>
>
> {% if form.password.errors %}
> {{ form.password.errors|join:", "
> }}
> {% endif %}
>  class="input-block-level" placeholder="Password">
>
> Let me
> in
> 
>
>  --
> 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.