6868_createLogin #2598

Merged
sergiodt merged 20 commits from 6868_createLogin into dev 2024-09-13 09:43:32 +00:00
2 changed files with 89 additions and 0 deletions
Showing only changes of commit d1214a998a - Show all commits

View File

@ -0,0 +1,88 @@
const {setDefaultHighWaterMark} = require('form-data');
const {setLocale} = require('i18n');
module.exports = Self => {
Self.remoteMethodCtx('loginApp', {
description: 'Login a user with username/email and password',
accepts: [
{
arg: 'user',
type: 'String',
description: 'The user name or email',
required: true
}, {
arg: 'password',
type: 'String',
description: 'The password'
}, {
arg: 'deviceId',
type: 'String',
description: 'Device id'
}, {
arg: 'android_id',
type: 'String',
description: 'Android id'
}, {
arg: 'versionApp',
type: 'String',
description: 'Version app'
}, {
arg: 'nameApp',
type: 'String',
description: 'Version app'
}, {
arg: 'serialNumber',
type: 'String',
description: 'Serial number'
}
],
returns: {
type: 'object',
root: true
},
http: {
path: `/loginApp`,
verb: 'POST'
}
});
Self.loginApp = async(ctx, user, password, deviceId, android_id, versionApp, nameApp, options) => {
const models = Self.app.models;
const login = await Self.app.models.VnUser.signIn(ctx, user, password, options);
const userId = login.user;
const query =
`INSERT IGNORE INTO operator (workerFk)
VALUES (?);`;
const insertOperator = await Self.rawSql(query, [userId], options);
const [serialNumber] = await models.DeviceProductionUser.findOne({
where: {id: '100'}
});
const insertDeviceLog = await models.DeviceLog.create(
{
'android_id': android_id,
'userFk': userId,
'versionApp': versionApp,
'nameApp': nameApp,
'serialNumber': [serialNumber]
},
options
);
const queryDeviceCheck =
`CALL device_checkLogin(?, ?)`;
const [queryDeviceCheckLogin] = await Self.rawSql(queryDeviceCheck, [userId, android_id], options);
if (!queryDeviceCheckLogin.vIsAuthorized)
throw new UserError('User not authorized');
return insertDeviceLog;
};
};

View File

@ -10,6 +10,7 @@ module.exports = Self => {
require('../methods/account/logout')(Self); require('../methods/account/logout')(Self);
require('../methods/account/change-password')(Self); require('../methods/account/change-password')(Self);
require('../methods/account/set-password')(Self); require('../methods/account/set-password')(Self);
require('../methods/account/login-app')(Self);
Self.setUnverifiedPassword = async(id, pass, options) => { Self.setUnverifiedPassword = async(id, pass, options) => {
const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options); const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options);