This seems like it should be fine, since I'm not touching the User model itself.

I want to register users purely based on email and password. Username is required in the User model. My thought is that I can just create a custom UserCreationForm that saves email address AS username and validates the email address.

Unfortunately, with that, I'll have to refer to email address via user.username going forward.

Is this standard? Is there a better way?

Thanks

有帮助吗?

解决方案

My thought is that I can just create a custom UserCreationForm that saves email address AS username and validates the email address.

Close.

Use the clean method to copy email address to username. This works out pretty well for everything but the default login form.

The default login form needs to be tweaked to allow username to be an email address. The default form expects characters only, and rejects punctuation.

其他提示

Some answers here.

Seems like the best method may be to write a custom auth backend (not too difficult) to accept email addresses to log in, and store a hash of the email in the username field to satisfy the required, unique username.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top