8032-devToTest_2440 #3009
|
@ -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;
|
||||
};
|
||||
};
|
|
@ -10,6 +10,7 @@ module.exports = Self => {
|
|||
require('../methods/account/logout')(Self);
|
||||
require('../methods/account/change-password')(Self);
|
||||
require('../methods/account/set-password')(Self);
|
||||
require('../methods/account/login-app')(Self);
|
||||
|
||||
Self.setUnverifiedPassword = async(id, pass, options) => {
|
||||
const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options);
|
||||
|
|
Loading…
Reference in New Issue