Skip to content

Commit

Permalink
chore: finish some implementations on requirePasswordChange
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlsilva committed Jun 4, 2024
1 parent fa22d3e commit 6165c8a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/containers/ChangePasswordRequired.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { useDispatch } from 'react-redux';

import { logout } from '../actions/login';
import { logout, setUser } from '../actions/login';
import I18n from '../i18n';
import { useSetting } from '../lib/hooks/useSetting';
import { showErrorAlert } from '../lib/methods/helpers';
Expand All @@ -28,6 +28,7 @@ export const ChangePasswordRequired = () => {
setLoading(true);
try {
await Services.setUserPassword(password);
dispatch(setUser({ requirePasswordChange: false }));
hideActionSheet();
} catch (error: any) {
showErrorAlert(error?.reason || error?.message, I18n.t('Oops'));
Expand Down
7 changes: 6 additions & 1 deletion app/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -836,5 +836,10 @@
"Your_invite_link_will_never_expire": "Your invite link will never expire.",
"Your_password_is": "Your password is",
"Your_push_was_sent_to_s_devices": "Your push was sent to {{s}} devices",
"Your_workspace": "Your workspace"
"Your_workspace": "Your workspace",
"You_need_to_change_your_password": "You need to change your password",
"To_continue_using_RocketChat": "To continue using the mobile app, you need to change your password.",
"Change_password": "Change password",
"Please_Enter_your_new_password": "Please enter your new password",
"Confirm_your_password": "Confirm your password"
}
14 changes: 10 additions & 4 deletions app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,22 @@ const handleLogout = function* handleLogout({ forcedByServer, message }) {
};

const handleSetUser = function* handleSetUser({ user }) {
if ('avatarETag' in user) {
if ('avatarETag' in user || 'requirePasswordChange' in user) {
const userId = yield select(state => state.login.user.id);
const serversDB = database.servers;
const userCollections = serversDB.get('users');
yield serversDB.write(async () => {
try {
const userRecord = await userCollections.find(userId);
await userRecord.update(record => {
record.avatarETag = user.avatarETag;
});
if ('avatarETag' in user) {
await userRecord.update(record => {
record.avatarETag = user.avatarETag;
});
} else if ('requirePasswordChange' in user) {
await userRecord.update(record => {
record.requirePasswordChange = user.requirePasswordChange;
});
}
} catch {
//
}
Expand Down
3 changes: 3 additions & 0 deletions app/views/RoomsListView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewS
this.shouldUpdate = false;
return true;
}
if (nextProps?.user?.requirePasswordChange !== this.props?.user?.requirePasswordChange) {
return true;
}
return false;
}

Expand Down

0 comments on commit 6165c8a

Please sign in to comment.