Skip to content

Commit c9ff223

Browse files
committed
remove password fields after password reset is successful
1 parent 6216118 commit c9ff223

4 files changed

Lines changed: 44 additions & 36 deletions

File tree

messages/password/partials/en.msg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ NewPasswordMsg: new password
1010
NewPasswordConfirmationMsg: new password confirmation
1111
ChangePasswordMsg: change password
1212
RequestPasswordResetMsg: request password reset
13-
ChangePasswordAuthRequiredMsg: Can not change password because you are not logged in.
13+
ChangePasswordAuthRequiredMsg: Can not change password because you are not logged in
1414
PasswordChangedMsg: Password successfully updated
15-
15+
PasswordResetSuccess: Your password has been successfully reset

src/Happstack/Authenticate/Client.hs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import GHCJS.Nullable (Nullable(..), nullableToMaybe, maybeToNullable)
5353
import GHCJS.Types (JSVal, jsval)
5454
import Happstack.Authenticate.Core (ClientInitData(..), Email(..), User(..), Username(..), AuthenticateURL(AmAuthenticated, AuthenticationMethods, InitClient, Logout), AuthenticationMethod(..), JSONResponse(..), Status(..), jsonOptions)
5555
import qualified Happstack.Authenticate.Core as Authenticate
56-
import Happstack.Authenticate.Password.Core(ChangePasswordData(..), UserPass(..), NewAccountData(..), ResetPasswordData(..), RequestResetPasswordData(..))
56+
import Happstack.Authenticate.Password.Core(ChangePasswordData(..), UserPass(..), NewAccountData(..), ResetPasswordData(..), RequestResetPasswordData(..), PartialMsgs(..))
5757
import Happstack.Authenticate.Password.URL(AccountURL(Password), PasswordURL(Account, Token, PasswordRequestReset, PasswordReset),passwordAuthenticationMethod)
5858
import GHC.Generics (Generic)
5959
import GHCJS.DOM.Document (setCookie)
@@ -84,23 +84,8 @@ getElementByNameAttr :: JSElement -> JSString -> IO (Maybe JSElement)
8484
getElementByNameAttr node name =
8585
querySelector node ("[name='" <> name <> "']")
8686

87-
data HappstackAuthenticateI18N = HappstackAuthenticateI18N
8887

89-
data PartialMsgs
90-
= UsernameMsg
91-
| EmailMsg
92-
| PasswordMsg
93-
| PasswordConfirmationMsg
94-
| SignUpMsg
95-
| SignInMsg
96-
| LogoutMsg
97-
| OldPasswordMsg
98-
| NewPasswordMsg
99-
| NewPasswordConfirmationMsg
100-
| ChangePasswordMsg
101-
| ChangePasswordAuthRequiredMsg
102-
| RequestPasswordResetMsg
103-
| PasswordChangedMsg
88+
data HappstackAuthenticateI18N = HappstackAuthenticateI18N
10489

10590
mkMessageFor "HappstackAuthenticateI18N" "PartialMsgs" "messages/password/partials" "en"
10691

@@ -304,9 +289,7 @@ requestResetPasswordForm =
304289
-- let changePasswordFn = "resetPassword('" <> url <> "')"
305290
[domc|
306291
<d-if cond="(_passwordResetRequested model)">
307-
308292
<p>{{ _requestResetPasswordMsg model }}</p>
309-
310293
<form role="form">
311294
<div class="form-group happstack-authenticate-error">{{_requestResetPasswordMsg model}}</div>
312295
<div class="form-group">
@@ -326,17 +309,22 @@ resetPasswordForm =
326309
<div>
327310
<form role="form">
328311
<div class="form-group">{{_resetPasswordMsg model}}</div>
329-
<div class="form-group">
330-
<label class="sr-only" for="reset-password">{{ render PasswordMsg }}</label>
331-
<input class="form-control" type="password" id="rp-reset-password" name="reset-password" placeholder="{{render PasswordMsg}}" />
332-
</div>
333-
<div class="form-group">
334-
<label class="sr-only" for="reset-password-confirm">{{ render PasswordConfirmationMsg }}</label>
335-
<input class="form-control" type="password" id="rp-reset-password-confirm" name="reset-password-confirm" placeholder="{{render PasswordConfirmationMsg}}" />
336-
</div>
337-
<div class="form-group">
338-
<input class="form-control" type="submit" value="{{render ChangePasswordMsg}}" />
339-
</div>
312+
<d-if cond="(_passwordChanged model)">
313+
<div></div>
314+
<div>
315+
<div class="form-group">
316+
<label class="sr-only" for="reset-password">{{ render PasswordMsg }}</label>
317+
<input class="form-control" type="password" id="rp-reset-password" name="reset-password" placeholder="{{render PasswordMsg}}" />
318+
</div>
319+
<div class="form-group">
320+
<label class="sr-only" for="reset-password-confirm">{{ render PasswordConfirmationMsg }}</label>
321+
<input class="form-control" type="password" id="rp-reset-password-confirm" name="reset-password-confirm" placeholder="{{render PasswordConfirmationMsg}}" />
322+
</div>
323+
<div class="form-group">
324+
<input class="form-control" type="submit" value="{{render ChangePasswordMsg}}" />
325+
</div>
326+
</div>
327+
</d-if>
340328
</form>
341329
</div>
342330
|]
@@ -703,7 +691,7 @@ requestResetAjaxHandler modelTV xhr rrpSubmit e =
703691
ajaxHandler modelTV handler xhr e
704692
where
705693
handler jr =
706-
do -- debugStrLn $ "requestResetPasswordAjaxHandler - " ++ show jr
694+
do debugStrLn $ "requestResetPasswordAjaxHandler - " ++ show jr
707695
case _jrStatus jr of
708696
NotOk ->
709697
case _jrData jr of
@@ -713,7 +701,7 @@ requestResetAjaxHandler modelTV xhr rrpSubmit e =
713701
setProperty rrpSubmit "disabled" False
714702
doRedraws modelTV
715703
Ok ->
716-
do -- debugStrLn "requestResetPasswordAjaxHandler - cake"
704+
do debugStrLn "requestResetPasswordAjaxHandler - cake"
717705
case _jrData jr of
718706
(String msg) ->
719707
do atomically $ modifyTVar' modelTV $ \m ->
@@ -764,6 +752,7 @@ resetAjaxHandler modelTV xhr e =
764752
(String msg) ->
765753
do atomically $ modifyTVar' modelTV $ \m ->
766754
m & resetPasswordMsg .~ (Text.unpack msg)
755+
& passwordChanged .~ True
767756
doRedraws modelTV
768757

769758
pure ()

src/Happstack/Authenticate/Password/Core.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ instance FromJSON PasswordError where parseJSON = genericParseJSON jsonOptions
7777

7878
mkMessageFor "HappstackAuthenticateI18N" "PasswordError" "messages/password/error" ("en")
7979

80+
data PartialMsgs
81+
= UsernameMsg
82+
| EmailMsg
83+
| PasswordMsg
84+
| PasswordConfirmationMsg
85+
| SignUpMsg
86+
| SignInMsg
87+
| LogoutMsg
88+
| OldPasswordMsg
89+
| NewPasswordMsg
90+
| NewPasswordConfirmationMsg
91+
| ChangePasswordMsg
92+
| ChangePasswordAuthRequiredMsg
93+
| RequestPasswordResetMsg
94+
| PasswordChangedMsg
95+
| PasswordResetSuccess
96+
97+
mkMessageFor "HappstackAuthenticateI18N" "PartialMsgs" "messages/password/partials" ("en")
98+
8099
------------------------------------------------------------------------------
81100
-- HashedPass
82101
------------------------------------------------------------------------------

src/Happstack/Authenticate/Password/Handlers.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ token authenticateState authenticateConfig passwordState =
136136
(Just (UserPass username password)) ->
137137
do mUser <- query' authenticateState (GetUserByUsername username)
138138
case mUser of
139-
Nothing -> forbidden $ toJSONError InvalidUsername
139+
Nothing -> forbidden $ toJSONError InvalidUsernamePassword
140140
(Just u) ->
141141
do valid <- query' passwordState (VerifyPasswordForUserId (u ^. userId) password)
142142
if not valid
@@ -384,7 +384,7 @@ passwordReset authenticateState passwordState passwordConfig =
384384
Nothing -> do pw <- mkHashedPass password
385385
update' passwordState (SetPassword (user ^. userId) pw)
386386
-- FIXME: how can we immediately expire the reset token?
387-
ok $ Right "Password Reset." -- I18N
387+
ok $ Right (renderMessage HappstackAuthenticateI18N ["en"] PasswordResetSuccess) -- I18N
388388

389389
decodeAndVerifyResetToken :: (MonadIO m) =>
390390
AcidState AuthenticateState

0 commit comments

Comments
 (0)