Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/lib/database/model/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ export default class User extends Model {

@field('statusText') statusText;

@field('login_email_password') loginEmailPassword;

@json('roles', sanitizer) roles;
}
11 changes: 11 additions & 0 deletions app/lib/database/model/serversMigrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ export default schemaMigrations({
]
})
]
},
{
toVersion: 6,
steps: [
addColumns({
table: 'users',
columns: [
{ name: 'login_email_password', type: 'boolean', isOptional: true }
]
})
]
}
]
});
5 changes: 3 additions & 2 deletions app/lib/database/schema/servers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { appSchema, tableSchema } from '@nozbe/watermelondb';

export default appSchema({
version: 5,
version: 6,
tables: [
tableSchema({
name: 'users',
Expand All @@ -12,7 +12,8 @@ export default appSchema({
{ name: 'language', type: 'string', isOptional: true },
{ name: 'status', type: 'string', isOptional: true },
{ name: 'statusText', type: 'string', isOptional: true },
{ name: 'roles', type: 'string', isOptional: true }
{ name: 'roles', type: 'string', isOptional: true },
{ name: 'login_email_password', type: 'boolean', isOptional: true }
]
}),
tableSchema({
Expand Down
7 changes: 5 additions & 2 deletions app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE
result = yield call(loginCall, credentials);
} else {
result = yield call(loginWithPasswordCall, credentials);
result.loginEmailPassword = credentials.loginEmailPassword;
Comment thread
EzequielDeOliveira marked this conversation as resolved.
Outdated
}
if (!result.username) {
yield put(serverFinishAdd());
Expand Down Expand Up @@ -114,11 +115,13 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
language: user.language,
status: user.status,
statusText: user.statusText,
roles: user.roles
roles: user.roles,
loginEmailPassword: user.loginEmailPassword
};
yield serversDB.action(async() => {
try {
const userRecord = await usersCollection.find(user.id);
u.loginEmailPassword = userRecord?.loginEmailPassword;
await userRecord.update((record) => {
record._raw = sanitizedRaw({ id: user.id, ...record._raw }, usersCollection.schema);
Object.assign(record, u);
Expand All @@ -133,7 +136,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {

yield RNUserDefaults.set(`${ RocketChat.TOKEN_KEY }-${ server }`, user.id);
yield RNUserDefaults.set(`${ RocketChat.TOKEN_KEY }-${ user.id }`, user.token);
yield put(setUser(user));
yield put(setUser({ ...user, loginEmailPassword: u.loginEmailPassword }));
Comment thread
EzequielDeOliveira marked this conversation as resolved.
Outdated
EventEmitter.emit('connected');

let currentRoot;
Expand Down
7 changes: 5 additions & 2 deletions app/utils/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import I18n from '../i18n';

export const showErrorAlert = (message, title, onPress = () => {}) => Alert.alert(title, message, [{ text: 'OK', onPress }], { cancelable: true });

export const showConfirmationAlert = ({ message, callToAction, onPress }) => (
export const showConfirmationAlert = ({
title, message, callToAction, onPress, onCancel
}) => (
Alert.alert(
I18n.t('Are_you_sure_question_mark'),
title || I18n.t('Are_you_sure_question_mark'),
message,
[
{
text: I18n.t('Cancel'),
onPress: onCancel,
style: 'cancel'
},
{
Expand Down
3 changes: 2 additions & 1 deletion app/views/LoginView.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ class LoginView extends React.Component {

const { user, password } = this.state;
const { loginRequest } = this.props;
const loginEmailPassword = true;
Keyboard.dismiss();
loginRequest({ user, password });
loginRequest({ user, password, loginEmailPassword });
Comment thread
EzequielDeOliveira marked this conversation as resolved.
Outdated
}

renderUserForm = () => {
Expand Down
32 changes: 26 additions & 6 deletions app/views/SettingsView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import AsyncStorage from '@react-native-community/async-storage';
import FastImage from '@rocket.chat/react-native-fast-image';
import CookieManager from '@react-native-community/cookies';

import { logout as logoutAction } from '../../actions/login';
import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
Expand Down Expand Up @@ -66,7 +67,7 @@ class SettingsView extends React.Component {

static propTypes = {
navigation: PropTypes.object,
server: PropTypes.object,
server: PropTypes.object,
allowCrashReport: PropTypes.bool,
toggleCrashReport: PropTypes.func,
theme: PropTypes.string,
Expand All @@ -75,7 +76,8 @@ class SettingsView extends React.Component {
selectServerRequest: PropTypes.func,
user: PropTypes.shape({
roles: PropTypes.array,
statusLivechat: PropTypes.string
statusLivechat: PropTypes.string,
loginEmailPassword: PropTypes.bool
}),
appStart: PropTypes.func
}
Expand All @@ -87,15 +89,33 @@ class SettingsView extends React.Component {
return roles?.includes('livechat-agent');
}

logout = () => {
const { logout, user } = this.props;
if (!user.loginEmailPassword) {
Comment thread
EzequielDeOliveira marked this conversation as resolved.
Outdated
showConfirmationAlert({
title: 'Clear all cookies from login OAuth?',
Comment thread
EzequielDeOliveira marked this conversation as resolved.
Outdated
message: 'This action will clear all cookies from the OAuth/SSO webview, allowing you to login to other accounts via OAuth',
onPress: () => {
CookieManager.clearAll()
.then(() => {
logout();
});
},
onCancel: () => {
logout();
}
});
} else {
logout();
}
}

handleLogout = () => {
logEvent(events.SE_LOG_OUT);
showConfirmationAlert({
message: I18n.t('You_will_be_logged_out_of_this_application'),
callToAction: I18n.t('Logout'),
onPress: () => {
const { logout } = this.props;
logout();
}
onPress: this.logout
});
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@react-native-community/art": "^1.2.0",
"@react-native-community/async-storage": "1.11.0",
"@react-native-community/cameraroll": "4.0.0",
"@react-native-community/cookies": "^4.0.0",
"@react-native-community/datetimepicker": "2.6.0",
"@react-native-community/hooks": "2.6.0",
"@react-native-community/masked-view": "^0.1.10",
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,13 @@
sudo-prompt "^9.0.0"
wcwidth "^1.0.1"

"@react-native-community/cookies@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cookies/-/cookies-4.0.0.tgz#561f7788e706b9902e25eefb80a093fe8ec5cd93"
integrity sha512-6j5Qatc0lVvaUgnhCydbmWofrwDURXxYp8f0cnfpN1LEltsxbhQU26n1ItXY79ZBnvxkkW6lEkw55Egah6uUKQ==
dependencies:
invariant "^2.2.4"

"@react-native-community/datetimepicker@2.6.0":
version "2.6.0"
resolved "https://registry.yarnpkg.com/@react-native-community/datetimepicker/-/datetimepicker-2.6.0.tgz#260715abc88dac2485f525f046bd33ac0e62a281"
Expand Down