fix save correctly the new password and fix save profile

This commit is contained in:
Cayo Puigdefabregas 2022-04-12 16:59:13 +02:00
parent 9d4ca5a2dc
commit 46bfc7fd47
2 changed files with 2 additions and 6 deletions

View file

@ -104,7 +104,7 @@ class ProfileForm(FlaskForm):
self.last_name.data = user.last_name self.last_name.data = user.last_name
self.email.data = user.email self.email.data = user.email
self.telephone.data = user.telephone self.telephone.data = user.telephone
self.country.data = user.country self.country.data = user.country.name
def save(self, commit=True): def save(self, commit=True):
agent = g.user.individual agent = g.user.individual
@ -143,18 +143,15 @@ class PasswordForm(FlaskForm):
return False return False
if not g.user.check_password(self.password.data): if not g.user.check_password(self.password.data):
self.password.errors = ['Incorrect password']
return False return False
if self.newpassword.data != self.renewpassword.data: if self.newpassword.data != self.renewpassword.data:
self.newpassword.errors = ['Is not the same password']
self.renewpassword.errors = ['Is not the same password']
return False return False
return True return True
def save(self, commit=True): def save(self, commit=True):
g.user.password = generate_password_hash(self.newpassword.data) g.user.password = self.newpassword.data
db.session.add(g.user) db.session.add(g.user)
if commit: if commit:

View file

@ -81,7 +81,6 @@ class UserPasswordView(View):
def dispatch_request(self): def dispatch_request(self):
form = PasswordForm() form = PasswordForm()
# import pdb; pdb.set_trace()
db.session.commit() db.session.commit()
if form.validate_on_submit(): if form.validate_on_submit():
form.save(commit=False) form.save(commit=False)