As mentioned above that I want to use django "authenticate" method with one parameter as email because I use mastodon api for authenticating user and I already got access token from mastodon. After this I just want to check that whether that email is present in django's user table or not with the help of any django method. I used authenticate method but it fails in the use case of password reset. Is there any method in django which can authenticate user with only email. I mention my code below if any modification in the code make that code runs would be appreciable.
Django Code:
mastodon_var = mastodon.Mastodon(
client_id='gnowsys_ndf/ndf/NROER-client_cred.secret',
api_base_url='https://member.metastudio.org'
)
access_token = None
####GET ACCESS FROM MASTODON HERE#######
try:
access_token = mastodon_var.log_in(
Username,
Password,
to_file='gnowsys_ndf/ndf/NROER-access_token.secret',
)
except Exception as e:
print e
pass
name = Username
email = Username
password = Password
# userna = mastodon_var.u"username"
# print userna
#######IF USER GETS ACCESS TOKEN THEN FOLLOWING CODE WILL BE EXECUTED##########
if access_token:
if User.objects.filter(username=name).exists():
####SECOND AND BY-DEFAULT LAYER FOR AUTHENTICATION
user = authenticate(username=name,password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect( reverse('landing_page') )
else:
HttpResponse("Error1")
return HttpResponseRedirect( reverse('landing_page') )
else:
member = User.objects.create_user(name,email,password)
member.save()
####SECOND AND BY-DEFAULT LAYER FOR AUTHENTICATION
user = authenticate(username=name, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect( reverse('landing_page') )
else:
HttpResponse("Error2")
return HttpResponseRedirect( reverse('landing_page') )
else:
#t = TemplateResponse(request, 'login_template', {})
#return t.render()
return HttpResponse("OOps!!!!! You entered wrong credentials")
#return HttpResponseRedirect( reverse('landing_page') )
else:
return HttpResponse("Invalid Credentials.")