Skip to content

Commit

Permalink
fix reset password form for authenticated user
Browse files Browse the repository at this point in the history
  • Loading branch information
sidloki committed Aug 4, 2014
1 parent bd13f62 commit 286c817
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
32 changes: 19 additions & 13 deletions ptahcrowd/resetpassword.py
Expand Up @@ -101,26 +101,28 @@ def passcode(self):
passcode = None
if self.request.subpath:
passcode = self.request.subpath[0]
else:
user = ptah.auth_service.get_current_principal()
if user:
passcode = ptah.pwd_tool.generate_passcode(user)
return passcode

def update(self):
self.principal = principal = ptah.pwd_tool.get_principal(self.passcode)
@reify
def principal(self):
principal = None
if self.passcode:
principal = ptah.pwd_tool.get_principal(self.passcode)
else:
principal = ptah.auth_service.get_current_principal()
return principal


if principal is not None and \
ptah.pwd_tool.can_change_password(principal):
self.title = principal.name or principal.login
def update(self):
principal = self.principal
if principal and ptah.pwd_tool.can_change_password(principal):
return super(ResetPasswordForm, self).update()
else:
if self.passcode:
self.request.add_message(_("Passcode is invalid."), 'warning')
return HTTPFound(
location='%s/resetpassword.html' % self.request.application_url)

return super(ResetPasswordForm, self).update()

@pform.button(_("Change password"),
name='change', actype=pform.AC_PRIMARY)
def changePassword(self):
Expand All @@ -129,8 +131,11 @@ def changePassword(self):
if errors:
self.add_error_message(errors)
else:
principal = ptah.pwd_tool.get_principal(self.passcode)
ptah.pwd_tool.change_password(self.passcode, data['password'])
principal = self.principal
passcode = self.passcode
if principal and not passcode:
passcode = ptah.pwd_tool.generate_passcode(principal)
ptah.pwd_tool.change_password(passcode, data['password'])

self.request.registry.notify(
PrincipalPasswordChangedEvent(principal))
Expand Down Expand Up @@ -173,3 +178,4 @@ def update(self):
info = self.context

self.to_address = ptah.mail.formataddr((info.name, info.email))

2 changes: 1 addition & 1 deletion ptahcrowd/templates/resetpasswordform.pt
@@ -1,7 +1,7 @@
<tal:block i18n:domain="ptahcrowd">
<div class="page-header">
<h1 i18n:translate="">Reset password</h1>
<p i18n:translate="">Password reset confirmation for <span tal:replace="view.title" i18n:name="user" /></p>
<p tal:condition="view.passcode" i18n:translate="">Password reset confirmation for <span tal:replace="view.principal" i18n:name="user" /></p>
</div>

<tal:block content="structure request.render_tmpl(view.tmpl_view, view)" />
Expand Down

0 comments on commit 286c817

Please sign in to comment.