我使用新方法 create_inactive_user 扩展了我的 UserManager。但是如何使用 UserCreationForm?
class UserManager(UserManager):
def create_inactive_user(self, username, email, password):
user = self.create_user(username, email, password)
user.is_active = False
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
activation_key = hashlib.sha1(salt+user.username).hexdigest()
user.activation_key = activation_key
user.save()
return user
我可以在https://github.com/django/django/blob/master/django/contrib/auth/forms.py中看到 UserCreationForm 是一个保存对象的 ModelForm,所以我怎样才能确保注册用户虽然我的 FormView 中的 create_inactive_user() ?
是这样的吗:
class SignupView(FormView):
form_class = UserCreationForm
template_name = 'signup.html'
def form_valid(self, form):
User.objects.create_inative_user(form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password'])
return super(SignupView, self).form_valid(form)