@saltcorn/mobile-app 0.8.5 → 0.8.6-beta.2
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/package.json
CHANGED
package/www/index.html
CHANGED
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
config.pluginHeaders.push(prepareHeader(header));
|
|
125
125
|
}
|
|
126
126
|
else if (typeof pluginHeaders === "function") {
|
|
127
|
-
const headerResult = pluginHeaders(row.configuration);
|
|
127
|
+
const headerResult = pluginHeaders(row.configuration || {});
|
|
128
128
|
if (Array.isArray(headerResult)) {
|
|
129
129
|
for (const header of headerResult)
|
|
130
130
|
config.pluginHeaders.push(prepareHeader(header));
|
|
@@ -146,10 +146,9 @@
|
|
|
146
146
|
const initJwt = async () => {
|
|
147
147
|
if (!(await saltcorn.data.db.tableExists("jwt_table"))) {
|
|
148
148
|
await createJwtTable();
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
149
|
+
} else {
|
|
151
150
|
const jwt = await getJwt();
|
|
152
|
-
if(jwt) {
|
|
151
|
+
if (jwt) {
|
|
153
152
|
const state = saltcorn.data.state.getState();
|
|
154
153
|
state.mobileConfig.jwt = jwt;
|
|
155
154
|
}
|
|
@@ -159,14 +158,13 @@
|
|
|
159
158
|
const checkJWT = async () => {
|
|
160
159
|
const state = saltcorn.data.state.getState();
|
|
161
160
|
const jwt = state.mobileConfig.jwt;
|
|
162
|
-
if(jwt && jwt !== "undefined") {
|
|
161
|
+
if (jwt && jwt !== "undefined") {
|
|
163
162
|
const response = await apiCall({
|
|
164
163
|
method: "GET",
|
|
165
164
|
path: "/auth/authenticated",
|
|
166
165
|
});
|
|
167
166
|
return response.data.authenticated;
|
|
168
|
-
}
|
|
169
|
-
else return false;
|
|
167
|
+
} else return false;
|
|
170
168
|
};
|
|
171
169
|
|
|
172
170
|
const initI18Next = async () => {
|
package/www/js/mocks/request.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*global i18next, saltcorn*/
|
|
2
2
|
|
|
3
3
|
function MobileRequest({ xhr = false, files = undefined, query = undefined }) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const cfg = saltcorn.data.state.getState().mobileConfig;
|
|
5
|
+
const roleId = cfg.role_id ? cfg.role_id : 10;
|
|
6
|
+
const userId = cfg.user_id ? cfg.user_id : undefined;
|
|
7
7
|
const flashMessages = [];
|
|
8
8
|
|
|
9
9
|
return {
|
|
@@ -21,6 +21,7 @@ function MobileRequest({ xhr = false, files = undefined, query = undefined }) {
|
|
|
21
21
|
return mobileCfg?.language ? mobileCfg.language : "en";
|
|
22
22
|
},
|
|
23
23
|
user: {
|
|
24
|
+
id: userId,
|
|
24
25
|
role_id: roleId,
|
|
25
26
|
},
|
|
26
27
|
flash: (type, msg) => {
|
package/www/js/routes/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*global sbAdmin2Layout, apiCall, removeJwt, saltcorn*/
|
|
1
|
+
/*global sbAdmin2Layout, apiCall, removeJwt, saltcorn, clearHistory*/
|
|
2
2
|
|
|
3
3
|
const prepareAuthForm = () => {
|
|
4
4
|
return new saltcorn.data.models.Form({
|
|
@@ -90,6 +90,7 @@ const logoutAction = async () => {
|
|
|
90
90
|
const response = await apiCall({ method: "GET", path: "/auth/logout" });
|
|
91
91
|
if (response.data.success) {
|
|
92
92
|
await removeJwt();
|
|
93
|
+
clearHistory();
|
|
93
94
|
config.jwt = undefined;
|
|
94
95
|
return {
|
|
95
96
|
content: renderLoginView(config.entry_point, config.version_tag),
|
|
@@ -16,6 +16,10 @@ function addRoute(routeEntry) {
|
|
|
16
16
|
routingHistory.push(routeEntry);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function clearHistory() {
|
|
20
|
+
routingHistory = [];
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
async function apiCall({ method, path, params, body, responseType }) {
|
|
20
24
|
const config = saltcorn.data.state.getState().mobileConfig;
|
|
21
25
|
const serverPath = config.server_path;
|
|
@@ -155,8 +159,12 @@ async function handleRoute(route, query, files) {
|
|
|
155
159
|
files: files,
|
|
156
160
|
});
|
|
157
161
|
if (page.redirect) {
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
if (page.redirect.startsWith("http://localhost")) {
|
|
163
|
+
await gotoEntryView();
|
|
164
|
+
} else {
|
|
165
|
+
const { path, query } = splitPathQuery(page.redirect);
|
|
166
|
+
await handleRoute(path, query);
|
|
167
|
+
}
|
|
160
168
|
} else if (page.content) {
|
|
161
169
|
if (!page.replaceIframe) await replaceIframeInnerContent(page.content);
|
|
162
170
|
else await replaceIframe(page.content);
|
|
@@ -173,7 +181,10 @@ async function handleRoute(route, query, files) {
|
|
|
173
181
|
}
|
|
174
182
|
|
|
175
183
|
async function goBack(steps = 1, exitOnFirstPage = false) {
|
|
176
|
-
if (
|
|
184
|
+
if (
|
|
185
|
+
routingHistory.length === 0 ||
|
|
186
|
+
(exitOnFirstPage && routingHistory.length === 1)
|
|
187
|
+
) {
|
|
177
188
|
navigator.app.exitApp();
|
|
178
189
|
} else if (routingHistory.length <= steps) {
|
|
179
190
|
routingHistory = [];
|
|
@@ -100,6 +100,7 @@ async function login(e, entryPoint, isSignup) {
|
|
|
100
100
|
const config = parent.saltcorn.data.state.getState().mobileConfig;
|
|
101
101
|
config.role_id = decodedJwt.user.role_id ? decodedJwt.user.role_id : 10;
|
|
102
102
|
config.user_name = decodedJwt.user.email;
|
|
103
|
+
config.user_id = decodedJwt.user.id;
|
|
103
104
|
config.language = decodedJwt.user.language;
|
|
104
105
|
config.isPublicUser = false;
|
|
105
106
|
await parent.setJwt(loginResult);
|
|
@@ -46,18 +46,21 @@ async function updateUserDefinedTables() {
|
|
|
46
46
|
const existingTables = await saltcorn.data.db.listUserDefinedTables();
|
|
47
47
|
const tables = await saltcorn.data.models.Table.find();
|
|
48
48
|
for (const table of tables) {
|
|
49
|
+
const sanitized = saltcorn.data.db.sqlsanitize(table.name);
|
|
49
50
|
if (
|
|
50
51
|
table.name !== "users" &&
|
|
51
|
-
!existingTables.find((row) => row.name ===
|
|
52
|
+
!existingTables.find((row) => row.name === sanitized)
|
|
52
53
|
) {
|
|
53
54
|
// CREATE TABLE without inserting into _sc_tables
|
|
54
55
|
await saltcorn.data.models.Table.create(table.name, {}, table.id);
|
|
55
56
|
}
|
|
56
57
|
const existingFields = (
|
|
57
|
-
await saltcorn.data.db.query(`PRAGMA table_info('${
|
|
58
|
+
await saltcorn.data.db.query(`PRAGMA table_info('${sanitized}')`)
|
|
58
59
|
).rows.map((row) => row.name);
|
|
59
60
|
for (const field of await table.getFields()) {
|
|
60
|
-
if (
|
|
61
|
+
if (
|
|
62
|
+
existingFields.indexOf(saltcorn.data.db.sqlsanitize(field.name)) < 0
|
|
63
|
+
) {
|
|
61
64
|
// field is new
|
|
62
65
|
await saltcorn.data.models.Field.create(field, false, field.id);
|
|
63
66
|
}
|