diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index f31b10b..6ac47c8 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -615,12 +615,15 @@ class MyPasswordResetSerializer(PasswordResetSerializer): class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer): def save(self): + request_id = self.data['token'][-10:] + data = dict( username=self.user.username, password1=self.data['new_password1'], ) if utils_ldap.is_configured(): + if request_id: utils_stats.set_progress(request_id, 'Changing LDAP password...') if utils_ldap.set_password(data) != 200: msg = 'Problem connecting to LDAP server: set.' utils.alert_tanner(msg) @@ -635,6 +638,7 @@ class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer): ) if utils_auth.wiki_is_configured(): + if request_id: utils_stats.set_progress(request_id, 'Changing Wiki password...') if utils_auth.set_wiki_password(data) != 200: msg = 'Problem connecting to Wiki Auth server: set.' utils.alert_tanner(msg) @@ -642,6 +646,7 @@ class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer): raise ValidationError(dict(non_field_errors=msg)) if utils_auth.discourse_is_configured(): + if request_id: utils_stats.set_progress(request_id, 'Changing Discourse password...') if utils_auth.set_discourse_password(data) != 200: msg = 'Problem connecting to Discourse Auth server: set.' utils.alert_tanner(msg) @@ -651,6 +656,9 @@ class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer): member = self.user.member logging.info('Password reset completed for: {} {} ({})'.format(member.first_name, member.last_name, member.id)) + if request_id: utils_stats.set_progress(request_id, 'Done!') + time.sleep(1) + super().save() diff --git a/webclient/src/PasswordReset.js b/webclient/src/PasswordReset.js index 8522f25..8cacb19 100644 --- a/webclient/src/PasswordReset.js +++ b/webclient/src/PasswordReset.js @@ -64,6 +64,7 @@ function ConfirmForm() { const { uid, token } = useParams(); const [input, setInput] = useState({ uid: uid, token: token }); const [error, setError] = useState({}); + const [progress, setProgress] = useState([]); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const history = useHistory(); @@ -74,8 +75,22 @@ function ConfirmForm() { const handleSubmit = (e) => { if (loading) return; setLoading(true); + + const request_id = token.slice(-10); + const getStatus = () => { + requester('/stats/progress/?request_id='+request_id, 'GET') + .then(res => { + setProgress(res); + }) + .catch(err => { + console.log(err); + }); + }; + const interval = setInterval(getStatus, 500); + requester('/password/reset/confirm/', 'POST', '', input) .then(res => { + clearInterval(interval); setLoading(false); setSuccess(true); setError({}); @@ -83,6 +98,7 @@ function ConfirmForm() { window.scrollTo(0, 0); }) .catch(err => { + clearInterval(interval); setLoading(false); console.log(err); setError(err.data); @@ -111,6 +127,10 @@ function ConfirmForm() { {(error.token || error.uid) &&

Error: Invalid password reset URL! Try doing another reset.

} +

+ {progress.map(x => <>{x}
)} +

+ Submit