Display progress updates during password resets

This commit is contained in:
Tanner Collin 2021-09-18 21:12:14 +00:00
parent 33a95d0604
commit 95295a712e
2 changed files with 28 additions and 0 deletions

View File

@ -615,12 +615,15 @@ class MyPasswordResetSerializer(PasswordResetSerializer):
class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer): class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer):
def save(self): def save(self):
request_id = self.data['token'][-10:]
data = dict( data = dict(
username=self.user.username, username=self.user.username,
password1=self.data['new_password1'], password1=self.data['new_password1'],
) )
if utils_ldap.is_configured(): if utils_ldap.is_configured():
if request_id: utils_stats.set_progress(request_id, 'Changing LDAP password...')
if utils_ldap.set_password(data) != 200: if utils_ldap.set_password(data) != 200:
msg = 'Problem connecting to LDAP server: set.' msg = 'Problem connecting to LDAP server: set.'
utils.alert_tanner(msg) utils.alert_tanner(msg)
@ -635,6 +638,7 @@ class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer):
) )
if utils_auth.wiki_is_configured(): 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: if utils_auth.set_wiki_password(data) != 200:
msg = 'Problem connecting to Wiki Auth server: set.' msg = 'Problem connecting to Wiki Auth server: set.'
utils.alert_tanner(msg) utils.alert_tanner(msg)
@ -642,6 +646,7 @@ class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer):
raise ValidationError(dict(non_field_errors=msg)) raise ValidationError(dict(non_field_errors=msg))
if utils_auth.discourse_is_configured(): 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: if utils_auth.set_discourse_password(data) != 200:
msg = 'Problem connecting to Discourse Auth server: set.' msg = 'Problem connecting to Discourse Auth server: set.'
utils.alert_tanner(msg) utils.alert_tanner(msg)
@ -651,6 +656,9 @@ class MyPasswordResetConfirmSerializer(PasswordResetConfirmSerializer):
member = self.user.member member = self.user.member
logging.info('Password reset completed for: {} {} ({})'.format(member.first_name, member.last_name, member.id)) 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() super().save()

View File

@ -64,6 +64,7 @@ function ConfirmForm() {
const { uid, token } = useParams(); const { uid, token } = useParams();
const [input, setInput] = useState({ uid: uid, token: token }); const [input, setInput] = useState({ uid: uid, token: token });
const [error, setError] = useState({}); const [error, setError] = useState({});
const [progress, setProgress] = useState([]);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
const history = useHistory(); const history = useHistory();
@ -74,8 +75,22 @@ function ConfirmForm() {
const handleSubmit = (e) => { const handleSubmit = (e) => {
if (loading) return; if (loading) return;
setLoading(true); 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) requester('/password/reset/confirm/', 'POST', '', input)
.then(res => { .then(res => {
clearInterval(interval);
setLoading(false); setLoading(false);
setSuccess(true); setSuccess(true);
setError({}); setError({});
@ -83,6 +98,7 @@ function ConfirmForm() {
window.scrollTo(0, 0); window.scrollTo(0, 0);
}) })
.catch(err => { .catch(err => {
clearInterval(interval);
setLoading(false); setLoading(false);
console.log(err); console.log(err);
setError(err.data); setError(err.data);
@ -111,6 +127,10 @@ function ConfirmForm() {
{(error.token || error.uid) && <p>Error: Invalid password reset URL! Try doing another reset.</p>} {(error.token || error.uid) && <p>Error: Invalid password reset URL! Try doing another reset.</p>}
<p>
{progress.map(x => <>{x}<br /></>)}
</p>
<Form.Button loading={loading} error={error.non_field_errors}> <Form.Button loading={loading} error={error.non_field_errors}>
Submit Submit
</Form.Button> </Form.Button>