feat: login refs #6868

This commit is contained in:
Sergio De la torre 2024-06-06 07:01:55 +02:00
parent e4e7ae1699
commit d1214a998a
2 changed files with 89 additions and 0 deletions

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);