flask-praetorian
flask-praetorian copied to clipboard
send_reset_email is referencing a non existent User attribute
https://github.com/dusktreader/flask-praetorian/blob/4740713858965e4c933b12e7d33d8972cd1d5618/flask_praetorian/base.py#L896-L899
send_reset_email
attempts to pass the attribute user.email
to the function send_token_email
. The User
object may not necessarily have an email attribute (I for instance have set it up as username in my model), and is causing the execution of send_reset_email
to fail.
Can we update the function to return email
instead of user.email
? Similar to how its currently done for send_registration_email
https://github.com/dusktreader/flask-praetorian/blob/4740713858965e4c933b12e7d33d8972cd1d5618/flask_praetorian/base.py#L827-L831
I am also having this issue. When calling as such:
data = request.get_json()
user = User.lookup(data['username']) # works
guard.send_reset_email(user.username, subject="Password Reset Request")
I am receiving the following error:
'User' object has no attribute 'email'
I don't have an email
attribute in my User
class/model, so it fails. I'm using username
as that's how the rest of the system seems to be working.
However, unlike the request by @sathyanmurugan I want it to return username
. What would be the best way forward here? Do I need to have duplicate data in my database?
As a temporary solution, you can add a class property as email
that returns username
.
Something like this :
class User(object):
def __init__(self, user_id, password, username, roles=""):
self.user_id = user_id
self.username = username
self.password = password
self.roles = roles
def __repr__(self):
return str(self.user_id)
@property
def email(self):
return self.username
@mukeshsharma1201 that did it and it's now working.
May I ask why you consider it to be temporary? Is there a change in how the code will work in the future?
Thanks so much, really appreciate your help there.
Sorry I'm so slow getting to this one. Yeah, that's a legitimate issue! I'll be thinking about how best to address this. It will be one of two ways, I think:
- Just document that email features require the user class to have an email attribute
- Update the code so that email is supplied in a different way Thanks for opening this issue!
Addressed with Merge Request #251
Will get this merged into master and then do some regression and integration testing to make sure it's working as expected. There are also going to be some updats such as dropping support for python 3.5 and adding some other automation for linting, etc. Hopefully a new release will be coming soon.