Load settings to redux and allow login via LDAP and CROWD
This commit is contained in:
parent
abd6d01b54
commit
10652002bc
|
@ -7,9 +7,13 @@ export function setCurrentServer(server) {
|
|||
};
|
||||
}
|
||||
|
||||
export function preventESLintError() {
|
||||
return {};
|
||||
export function setAllSettings(settings) {
|
||||
return {
|
||||
type: types.SET_ALL_SETTINGS,
|
||||
payload: settings
|
||||
};
|
||||
}
|
||||
|
||||
// // GENRES
|
||||
// export function retrieveMoviesGenresSuccess(res) {
|
||||
// return {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
export default {
|
||||
boolean: 'valueAsBoolean',
|
||||
int: 'valueAsNumber',
|
||||
string: 'valueAsString',
|
||||
select: 'valueAsString',
|
||||
code: 'valueAsString',
|
||||
relativeUrl: 'valueAsString',
|
||||
language: 'valueAsString',
|
||||
action: 'valueAsString',
|
||||
password: 'valueAsString',
|
||||
// asset: ' Object',
|
||||
color: 'valueAsString',
|
||||
font: 'valueAsString',
|
||||
roomPick: 'valueAsString'
|
||||
};
|
|
@ -7,4 +7,4 @@
|
|||
// export const RETRIEVE_MOVIES_SEARCH_RESULT_SUCCESS = 'RETRIEVE_MOVIES_SEARCH_RESULT_SUCCESS';
|
||||
|
||||
export const SET_CURRENT_SERVER = 'SET_CURRENT_SERVER';
|
||||
export const ESLINT_FIX = 'ESLINT_FIX';
|
||||
export const SET_ALL_SETTINGS = 'SET_ALL_SETTINGS';
|
||||
|
|
|
@ -13,10 +13,8 @@ if (__DEV__) {
|
|||
middleware = [...middleware];
|
||||
}
|
||||
|
||||
export default function configureStore(initialState) {
|
||||
return createStore(
|
||||
rootReducer,
|
||||
initialState,
|
||||
applyMiddleware(...middleware)
|
||||
);
|
||||
}
|
||||
export default createStore(
|
||||
rootReducer,
|
||||
undefined,
|
||||
applyMiddleware(...middleware)
|
||||
);
|
||||
|
|
|
@ -15,7 +15,9 @@ const settingsSchema = {
|
|||
properties: {
|
||||
_id: 'string',
|
||||
_server: 'servers',
|
||||
value: { type: 'string', optional: true }
|
||||
valueAsString: { type: 'string', optional: true },
|
||||
valueAsBoolean: { type: 'bool', optional: true },
|
||||
valueAsNumber: { type: 'int', optional: true }
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -70,13 +72,14 @@ const messagesSchema = {
|
|||
}
|
||||
};
|
||||
|
||||
// Realm.clearTestState();
|
||||
|
||||
const realm = new Realm({
|
||||
schema: [settingsSchema, serversSchema, subscriptionSchema, messagesSchema, usersSchema]
|
||||
});
|
||||
|
||||
export default realm;
|
||||
|
||||
// Realm.clearTestState();
|
||||
// realm.write(() => {
|
||||
// realm.create('servers', { id: 'https://demo.rocket.chat', current: false }, true);
|
||||
// realm.create('servers', { id: 'http://localhost:3000', current: false }, true);
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import Meteor from 'react-native-meteor';
|
||||
import Random from 'react-native-meteor/lib/Random';
|
||||
import { AsyncStorage } from 'react-native';
|
||||
import { hashPassword } from 'react-native-meteor/lib/utils';
|
||||
|
||||
import reduxStore from '../lib/createStore';
|
||||
import settingsType from '../constants/settings';
|
||||
import realm from './realm';
|
||||
import debounce from '../utils/debounce';
|
||||
import * as actions from '../actions';
|
||||
|
||||
export { Accounts } from 'react-native-meteor';
|
||||
|
||||
|
@ -76,19 +80,22 @@ const RocketChat = {
|
|||
console.error(err);
|
||||
}
|
||||
|
||||
const settings = {};
|
||||
realm.write(() => {
|
||||
data.forEach((item) => {
|
||||
const setting = {
|
||||
_id: item._id
|
||||
};
|
||||
setting._server = { id: RocketChat.currentServer };
|
||||
if (typeof item.value === 'string') {
|
||||
setting.value = item.value;
|
||||
if (settingsType[item.type]) {
|
||||
setting[settingsType[item.type]] = item.value;
|
||||
realm.create('settings', setting, true);
|
||||
}
|
||||
// write('settings', setting);
|
||||
realm.create('settings', setting, true);
|
||||
|
||||
settings[item._id] = item.value;
|
||||
});
|
||||
});
|
||||
reduxStore.dispatch(actions.setAllSettings(settings));
|
||||
|
||||
if (cb) {
|
||||
cb();
|
||||
|
@ -138,8 +145,53 @@ const RocketChat = {
|
|||
});
|
||||
},
|
||||
|
||||
loginWithPassword(selector, password, cb) {
|
||||
Meteor.loginWithPassword(selector, password, () => cb && cb());
|
||||
login(params, callback) {
|
||||
Meteor._startLoggingIn();
|
||||
Meteor.call('login', params, (err, result) => {
|
||||
Meteor._endLoggingIn();
|
||||
|
||||
Meteor._handleLoginCallback(err, result);
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
loginWithPassword(username, password, callback) {
|
||||
let params = {};
|
||||
const state = reduxStore.getState();
|
||||
|
||||
if (state.settings.LDAP_Enable) {
|
||||
params = {
|
||||
ldap: true,
|
||||
username,
|
||||
ldapPass: password,
|
||||
ldapOptions: {}
|
||||
};
|
||||
} else if (state.settings.CROWD_Enable) {
|
||||
params = {
|
||||
crowd: true,
|
||||
username,
|
||||
crowdPassword: password
|
||||
};
|
||||
} else {
|
||||
params = {
|
||||
password: hashPassword(password),
|
||||
user: {
|
||||
username
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof username === 'string') {
|
||||
if (username.indexOf('@') !== -1) {
|
||||
params.user = { email: username };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log({ params });
|
||||
this.login(params, callback);
|
||||
},
|
||||
|
||||
loadSubscriptions(cb) {
|
||||
|
@ -333,6 +385,10 @@ const RocketChat = {
|
|||
|
||||
export default RocketChat;
|
||||
|
||||
if (RocketChat.currentServer) {
|
||||
reduxStore.dispatch(actions.setCurrentServer(RocketChat.currentServer));
|
||||
}
|
||||
|
||||
Meteor.Accounts.onLogin(() => {
|
||||
Promise.all([call('subscriptions/get'), call('rooms/get')]).then(([subscriptions, rooms]) => {
|
||||
subscriptions = subscriptions.sort((s1, s2) => (s1.rid > s2.rid ? 1 : -1));
|
||||
|
|
|
@ -7,9 +7,7 @@ import ListServerView from './views/serverList';
|
|||
import RoomsListView from './views/roomsList';
|
||||
import RoomView from './views/room';
|
||||
import CreateChannel from './views/CreateChannel';
|
||||
import configureStore from './lib/createStore';
|
||||
|
||||
const store = configureStore();
|
||||
import store from './lib/createStore';
|
||||
|
||||
Navigation.registerComponent('Rooms', () => RoomsListView, store, Provider);
|
||||
Navigation.registerComponent('Room', () => RoomView, store, Provider);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import RocketChat from '../lib/rocketchat';
|
||||
|
||||
export default {
|
||||
server: RocketChat.currentServer,
|
||||
login: {}
|
||||
server: null,
|
||||
login: {},
|
||||
settings: {}
|
||||
};
|
||||
|
|
|
@ -2,51 +2,21 @@ import RocketChat from '../lib/rocketchat';
|
|||
import * as types from '../constants/types';
|
||||
import initialState from './initialState';
|
||||
|
||||
export default function(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case types.SET_CURRENT_SERVER:
|
||||
RocketChat.currentServer = action.payload;
|
||||
return {
|
||||
...state,
|
||||
server: action.payload
|
||||
};
|
||||
|
||||
// case types.RETRIEVE_POPULAR_MOVIES_SUCCESS:
|
||||
// return {
|
||||
// ...state,
|
||||
// popularMovies: action.popularMovies
|
||||
// };
|
||||
|
||||
// case types.RETRIEVE_NOWPLAYING_MOVIES_SUCCESS:
|
||||
// return {
|
||||
// ...state,
|
||||
// nowPlayingMovies: action.nowPlayingMovies
|
||||
// };
|
||||
|
||||
// case types.RETRIEVE_MOVIES_GENRES_SUCCESS:
|
||||
// return {
|
||||
// ...state,
|
||||
// genres: action.moviesGenres
|
||||
// };
|
||||
|
||||
// case types.RETRIEVE_MOVIES_LIST_SUCCESS:
|
||||
// return {
|
||||
// ...state,
|
||||
// list: action.list
|
||||
// };
|
||||
|
||||
// case types.RETRIEVE_MOVIE_DETAILS_SUCCESS:
|
||||
// return {
|
||||
// ...state,
|
||||
// details: action.details
|
||||
// };
|
||||
|
||||
// case types.RETRIEVE_MOVIES_SEARCH_RESULT_SUCCESS:
|
||||
// return {
|
||||
// ...state,
|
||||
// searchResults: action.searchResults
|
||||
// };
|
||||
default:
|
||||
return state;
|
||||
export function server(state = initialState.server, action) {
|
||||
if (action.type === types.SET_CURRENT_SERVER) {
|
||||
RocketChat.currentServer = action.payload;
|
||||
return action.payload;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
export function settings(state = initialState.settings, action) {
|
||||
if (action.type === types.SET_ALL_SETTINGS) {
|
||||
return {
|
||||
...action.payload
|
||||
};
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
// import { combineReducers } from 'redux';
|
||||
import reducers from './reducers';
|
||||
import { combineReducers } from 'redux';
|
||||
import * as reducers from './reducers';
|
||||
|
||||
// const rootReducer = combineReducers({
|
||||
// reducers
|
||||
// });
|
||||
const rootReducer = combineReducers({
|
||||
...reducers
|
||||
});
|
||||
|
||||
// export default rootReducer;
|
||||
export default reducers;
|
||||
export default rootReducer;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import ActionButton from 'react-native-action-button';
|
||||
import Icon from 'react-native-vector-icons/Ionicons';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
// import PropTypes from 'prop-types';
|
||||
import { TextInput, StyleSheet, View, Text, Switch } from 'react-native';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
|
||||
|
@ -45,9 +45,9 @@ const styles = StyleSheet.create({
|
|||
});
|
||||
const mainIcon = <Icon name='md-checkmark' style={styles.actionButtonIcon} />;
|
||||
export default class CreateChannelView extends React.Component {
|
||||
static propTypes = {
|
||||
navigation: PropTypes.object.isRequired
|
||||
}
|
||||
// static propTypes = {
|
||||
// navigation: PropTypes.object.isRequired
|
||||
// }
|
||||
|
||||
static navigationOptions = () => ({
|
||||
title: 'Create Channel'
|
||||
|
|
|
@ -100,23 +100,22 @@ class RoomsListItem extends React.PureComponent {
|
|||
}
|
||||
|
||||
@connect(state => ({
|
||||
server: state.server
|
||||
server: state.server,
|
||||
Site_Url: state.settings.Site_Url
|
||||
}), dispatch => ({
|
||||
actions: bindActionCreators(actions, dispatch)
|
||||
}))
|
||||
export default class RoomsListView extends React.Component {
|
||||
static propTypes = {
|
||||
navigator: PropTypes.object.isRequired,
|
||||
server: PropTypes.string
|
||||
server: PropTypes.string,
|
||||
Site_Url: PropTypes.string
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.data = realm.objects('subscriptions').filtered('_server.id = $0', this.props.server);
|
||||
const siteUrl = realm.objectForPrimaryKey('settings', 'Site_Url');
|
||||
if (siteUrl) {
|
||||
this.url = siteUrl.value;
|
||||
}
|
||||
this.state = {
|
||||
dataSource: ds.cloneWithRows([]),
|
||||
searching: false,
|
||||
|
@ -249,7 +248,6 @@ export default class RoomsListView extends React.Component {
|
|||
getSubscriptions = () => this.data.sorted('_updatedAt', true)
|
||||
|
||||
updateState = debounce(() => {
|
||||
this.url = realm.objectForPrimaryKey('settings', 'Site_Url').value;
|
||||
this.setState({
|
||||
dataSource: ds.cloneWithRows(this.data.filtered('_server.id = $0', this.props.server).sorted('ls', true))
|
||||
});
|
||||
|
@ -319,7 +317,7 @@ export default class RoomsListView extends React.Component {
|
|||
<RoomsListItem
|
||||
item={item}
|
||||
onPress={() => this._onPressItem(item._id, item)}
|
||||
baseUrl={this.url}
|
||||
baseUrl={this.props.Site_Url}
|
||||
/>
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue