Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
800 views
in Technique[技术] by (71.8m points)

django - 如何使用旧凭据自动登录到我的Django应用(how to auto login to a my django app with old credentials)

I want to login to my django app using details from another web applications Have tried googling but no clear solution.

(我想使用其他Web应用程序中的详细信息登录到django应用程序尝试使用谷歌搜索,但没有明确的解决方案。)

I thought a rest api could do.

(我以为可以使用rest api。)

  ask by LarryO translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would do something like this:

(我会做这样的事情:)

from allauth.account.models import EmailAddress

with transaction.atomic():
   # password with old one
   user.password = user_old_password
   user.save(update_fields=['password'])

   # validate user
   EmailAddress.objects.get_or_create(
       user=user,
       email=user.email,
       verified=True
   )

Atomic transaction here if you plan to do it in a migration file.

(如果您计划在迁移文件中进行原子事务,请在此处进行。)

See migration files in django doc

(查看Django文档中的迁移文件)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...