6868_createLogin #2598
|
@ -1,5 +1,4 @@
|
||||||
const {setDefaultHighWaterMark} = require('form-data');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
const {setLocale} = require('i18n');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('loginApp', {
|
Self.remoteMethodCtx('loginApp', {
|
||||||
|
@ -53,20 +52,55 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
await models.Account.login(ctx, user, password, myOptions);
|
const login = await models.Account.login(ctx, user, password, myOptions);
|
||||||
|
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
const isUserInOperator = await models.Operator.findById(userId);
|
const resultCheckLogin =
|
||||||
if (!isUserInOperator)
|
await Self.rawSql('CALL vn.device_checkLogin(?, ?);',
|
||||||
await models.Operator.create({'workerFk': userId});
|
[userId, android_id], myOptions);
|
||||||
|
|
||||||
const device = await models.DeviceProduction.findById(deviceId);
|
const [{vIsAuthorized, vMessage}] = resultCheckLogin[0];
|
||||||
|
|
||||||
// const [serialNumber] = await models.DeviceProductionUser.findOne({
|
if (!vIsAuthorized)
|
||||||
// where: {id: '100'}
|
throw new UserError('Not authorized');
|
||||||
// });
|
|
||||||
|
|
||||||
|
const isUserInOperator = await models.Operator.findOne({
|
||||||
|
where: {
|
||||||
|
workerFk: userId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!isUserInOperator){
|
||||||
|
await models.Operator.create({ 'workerFk': userId });
|
||||||
|
|
||||||
|
const getDataUser = await models.Operator.findOne({
|
||||||
|
where: {
|
||||||
|
workerFk: userId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const resultDevice = await models.DeviceProduction.findOne({
|
||||||
|
where: {
|
||||||
|
android_id: android_id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (resultDevice)
|
||||||
|
serialNumber = resultDevice.serialNumber ?? '';
|
||||||
|
|
||||||
|
await models.DeviceLog.create({
|
||||||
|
'android_id': android_id,
|
||||||
|
'userFk': userId,
|
||||||
|
'nameApp': nameApp,
|
||||||
|
'versionApp': versionApp,
|
||||||
|
'serialNumber': serialNumber
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
console.log(vIsAuthorized);
|
||||||
|
console.log(vMessage);
|
||||||
// const insertDeviceLog = await models.DeviceLog.create(
|
// const insertDeviceLog = await models.DeviceLog.create(
|
||||||
// {
|
// {
|
||||||
// 'android_id': android_id,
|
// 'android_id': android_id,
|
||||||
|
|
Loading…
Reference in New Issue