mg-library 1.0.327 → 1.0.328
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/login.js +38 -0
- package/mg-library.rar +0 -0
- package/package.json +1 -1
package/login.js
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
import * as mgFunctionsLib from './functions.js';
|
2
|
+
import * as mgConstantsLib from './constants.js';
|
3
|
+
import axios from 'axios';
|
4
|
+
|
5
|
+
function onPressLogin(dispatch, actions, server, app, apiUrl, language, data) {
|
6
|
+
try {
|
7
|
+
if (validateForm(data, language)) {
|
8
|
+
let requestData = {
|
9
|
+
app: app,
|
10
|
+
userName: data.userName.toLowerCase(),
|
11
|
+
password: data.password,
|
12
|
+
language: mgConstantsLib.LANGUAGE_SPANISH
|
13
|
+
}
|
14
|
+
dispatch(actions.apiRequest());
|
15
|
+
axios.post(apiUrl + '/Login', requestData, mgFunctionsLib.getRequestHeader())
|
16
|
+
.then(response => {
|
17
|
+
let appSession = response.data;
|
18
|
+
dispatch(actions.login(appSession));
|
19
|
+
mgFunctionsLib.writeToLocalStorage(mgFunctionsLib.ACCESS_TOKEN, appSession.accessToken);
|
20
|
+
dispatch(actions.apiSuccess());
|
21
|
+
})
|
22
|
+
.catch(error => {
|
23
|
+
dispatch(actions.apiError());
|
24
|
+
mgFunctionsLib.showToastError(functionsLib.i18nMessage('credentialsInvalid', language));
|
25
|
+
})
|
26
|
+
}
|
27
|
+
} catch (error) {
|
28
|
+
mgFunctionsLib.showToastError(error);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
function validateForm(data, language) {
|
33
|
+
if (mgFunctionsLib.isEmpty(data.userName))
|
34
|
+
throw mgFunctionsLib.i18nMessage('userRequired', language);
|
35
|
+
if (mgFunctionsLib.isEmpty(data.password))
|
36
|
+
throw mgFunctionsLib.i18nMessage('passwordRequired', language);
|
37
|
+
return true;
|
38
|
+
}
|
package/mg-library.rar
ADDED
Binary file
|