Frage

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

War es hilfreich?

Lösung

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.

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top