簡體   English   中英

自定義用戶模型擴展AbstractUser,驗證返回無

[英]Custom User Model extending AbstractUser, authenticate return None

我想創建擴展AbstractUser的自定義用戶,但是當我想對自定義用戶進行身份驗證時,返回None。

當我創建CustomUser()時,它存儲在數據庫中,但passwowrd未加密。 我可以使用banckend默認的身份驗證功能嗎? 否則我必須為我的自定義用戶創建一個自定義后端。

我補充說:

AUTH_USER_MODEL = 'mysite.customuser'

我認為是AbstractUser的擴展,我的類沒有相同的方法,或者出了點問題

解決了!

問題不是擴展AbstracUser,問題是當我保存用戶CustomUser(username ='myusername',password ='mypassword')時,密碼被保存為純文本,並且de功能authenticate()無法使用這個。

必須使用UserCreationForm來保存用戶或對其進行擴展,最重要的是save()方法,因為使用set_password()方法來設置加密密碼,以便authenticate()方法起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM