Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
bug 558507, Use ModelForm to save data
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed Aug 19, 2010
1 parent d19a052 commit c393e11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
8 changes: 7 additions & 1 deletion apps/users/models.py
Expand Up @@ -141,9 +141,15 @@ def anonymize(self):
self.picture_type = ""
self.save()

def generate_confirmationcode(self):
if not self.confirmationcode:
self.confirmationcode = ''.join(random.sample(string.letters +
string.digits, 60))
return self.confirmationcode

def save(self, force_insert=False, force_update=False, using=None):
# we have to fix stupid things that we defined poorly in remora
if self.resetcode_expires is None:
if not self.resetcode_expires:
self.resetcode_expires = datetime.now()

super(UserProfile, self).save(force_insert, force_update, using)
Expand Down
22 changes: 5 additions & 17 deletions apps/users/views.py
@@ -1,5 +1,3 @@
import random
import string
from django import http
from django.conf import settings
from django.core.mail import send_mail
Expand Down Expand Up @@ -310,20 +308,9 @@ def register(request):
form = forms.UserRegisterForm(request.POST)

if form.is_valid():
data = request.POST
u = UserProfile()
u.email = data.get('email')
u.emailhidden = data.get('emailhidden', False)
u.firstname = data.get('firstname', None)
u.lastname = data.get('lastname', None)
u.username = data.get('username', None)
u.display_name = data.get('display_name', None)
u.homepage = data.get('homepage', None)

u.set_password(data.get('password'))
u.confirmationcode = ''.join(random.sample(
string.letters + string.digits, 60))

u = form.save(commit=False)
u.set_password(form.cleaned_data['password'])
u.generate_confirmationcode()
u.save()
u.create_django_user()
log.info(u"Registered new account for user (%s)", u)
Expand All @@ -337,7 +324,8 @@ def register(request):
'activate your account by clicking on the link provided '
' in this email.').format(u.email))
messages.info(request, msg)
form = None
return http.HttpResponseRedirect(reverse('users.login'))

else:
messages.error(request, _(('There are errors in this form. Please '
'correct them and resubmit.')))
Expand Down

0 comments on commit c393e11

Please sign in to comment.