2019-09-18 15:02:21 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { map } from 'rxjs/operators';
|
|
|
|
|
|
|
|
import {
|
|
|
|
ProtocolService,
|
|
|
|
PacketBody,
|
2019-09-19 18:05:59 +09:00
|
|
|
PacketBodyValue,
|
|
|
|
ServerMessage
|
2019-09-18 15:02:21 +09:00
|
|
|
} from '@ucap-webmessenger/protocol';
|
|
|
|
import { LoginRequest, LoginResponse } from '../models/login';
|
|
|
|
import {
|
|
|
|
SVC_TYPE_LOGIN,
|
|
|
|
SSVC_TYPE_LOGIN_REQ,
|
2019-09-19 17:03:39 +09:00
|
|
|
SVC_TYPE_LOGOUT,
|
2019-09-19 18:05:59 +09:00
|
|
|
SSVC_TYPE_LOGOUT_REQ,
|
|
|
|
SSVC_TYPE_LOGOUT_REMOTE_REQ
|
2019-09-18 15:02:21 +09:00
|
|
|
} from '../types/service';
|
|
|
|
import { RoleCode } from '../types/role-code';
|
2019-09-19 18:05:59 +09:00
|
|
|
import {
|
|
|
|
LogoutRequest,
|
|
|
|
LogoutResponse,
|
|
|
|
LogoutRemoteRequest,
|
|
|
|
LogoutRemoteResponse,
|
|
|
|
LogoutRemoteNotification
|
|
|
|
} from '../models/logout';
|
2019-09-18 15:02:21 +09:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class AuthenticationProtocolService {
|
|
|
|
constructor(private protocolService: ProtocolService) {}
|
|
|
|
|
|
|
|
public login(req: LoginRequest): Observable<LoginResponse> {
|
|
|
|
const bodyList: PacketBody[] = [];
|
|
|
|
|
|
|
|
bodyList.push(
|
|
|
|
{ type: PacketBodyValue.String, value: req.loginId },
|
|
|
|
{ type: PacketBodyValue.String, value: req.loginPw },
|
|
|
|
{ type: PacketBodyValue.String, value: req.deviceType },
|
|
|
|
{ type: PacketBodyValue.String, value: req.deviceId },
|
2019-09-19 15:51:42 +09:00
|
|
|
{ type: PacketBodyValue.String, value: req.token },
|
2019-09-18 15:02:21 +09:00
|
|
|
{ type: PacketBodyValue.String, value: req.localeCode },
|
|
|
|
{ type: PacketBodyValue.String, value: req.pushId },
|
|
|
|
{ type: PacketBodyValue.String, value: req.companyCode },
|
2019-09-19 15:51:42 +09:00
|
|
|
{ type: PacketBodyValue.Integer, value: req.passwordEncodingType },
|
2019-09-18 15:02:21 +09:00
|
|
|
{ type: PacketBodyValue.String, value: req.clientVersion },
|
|
|
|
{ type: PacketBodyValue.String, value: req.reconnect ? 'Y' : 'N' },
|
|
|
|
{ type: PacketBodyValue.String, value: req.ip },
|
|
|
|
{ type: PacketBodyValue.String, value: req.hostName },
|
|
|
|
{ type: PacketBodyValue.Integer, value: req.encriptionData ? 2 : 1 },
|
|
|
|
{ type: PacketBodyValue.String, value: req.userSpecificInformation },
|
|
|
|
{ type: PacketBodyValue.String, value: req.productId },
|
|
|
|
{ type: PacketBodyValue.String, value: req.productName }
|
|
|
|
);
|
|
|
|
|
|
|
|
if (req.encriptionData) {
|
|
|
|
bodyList.push(
|
|
|
|
{ type: PacketBodyValue.String, value: req.encriptionData },
|
|
|
|
{ type: PacketBodyValue.String, value: req.accessToken }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.protocolService
|
|
|
|
.call(SVC_TYPE_LOGIN, SSVC_TYPE_LOGIN_REQ, ...bodyList)
|
|
|
|
.pipe(
|
|
|
|
map(res => {
|
2019-09-19 18:05:59 +09:00
|
|
|
return this.decodeLoginResponse(res);
|
2019-09-18 15:02:21 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-19 17:03:39 +09:00
|
|
|
|
2019-09-19 18:05:59 +09:00
|
|
|
public decodeLoginResponse(message: ServerMessage): LoginResponse {
|
|
|
|
return {
|
|
|
|
loginId: message.bodyList[0],
|
|
|
|
userSeq: message.bodyList[1],
|
|
|
|
userInfo: message.bodyList[2],
|
|
|
|
token: message.bodyList[3],
|
|
|
|
companyCode: message.bodyList[4],
|
|
|
|
departmentCode: message.bodyList[5],
|
|
|
|
userId: message.bodyList[6],
|
|
|
|
passwordEncodingType: message.bodyList[7],
|
|
|
|
encriptionKey: message.bodyList[8],
|
|
|
|
existingPid: message.bodyList[9] === 'Y' ? true : false,
|
|
|
|
roleCode: message.bodyList[10] as RoleCode,
|
|
|
|
statusMessage1: message.bodyList[11],
|
|
|
|
statusMessage2: message.bodyList[12],
|
|
|
|
statusMessage3: message.bodyList[13],
|
|
|
|
fileDownloadAllow: message.bodyList[14] === 'Y' ? true : false,
|
|
|
|
fileRetentionPeriod: message.bodyList[15],
|
|
|
|
passwordValidityPeriod: message.bodyList[16],
|
|
|
|
privateInformationAgree: message.bodyList[17] === 'Y' ? true : false,
|
|
|
|
madn: message.bodyList[18],
|
|
|
|
hardPhoneSadn: message.bodyList[19],
|
|
|
|
fmcSadn: message.bodyList[20],
|
|
|
|
pbxIndex: message.bodyList[21],
|
|
|
|
passwordExpired: message.bodyList[22] === 'Y' ? true : false,
|
|
|
|
validAccount: message.bodyList[23] === 'Y' ? true : false,
|
|
|
|
validDevice: message.bodyList[24] === 'Y' ? true : false,
|
|
|
|
useableDevice: message.bodyList[25] === 'Y' ? true : false,
|
|
|
|
deviceScreenForcedLock: message.bodyList[26] === 'Y' ? true : false,
|
|
|
|
tokenString: message.bodyList[27],
|
|
|
|
havePermissionsForIntegratedMessageBox:
|
|
|
|
message.bodyList[28] === 'Y' ? true : false,
|
|
|
|
talkWithMeBotSeq: message.bodyList[29],
|
|
|
|
pinCode: message.bodyList[30],
|
|
|
|
permissionsForViewSchedule: message.bodyList[31],
|
|
|
|
havePermissionsForDevice: message.bodyList[32] === 'Y' ? true : false
|
|
|
|
} as LoginResponse;
|
|
|
|
}
|
|
|
|
|
2019-09-19 17:03:39 +09:00
|
|
|
public logout(req: LogoutRequest): Observable<LogoutResponse> {
|
|
|
|
return this.protocolService
|
|
|
|
.call(SVC_TYPE_LOGOUT, SSVC_TYPE_LOGOUT_REQ)
|
|
|
|
.pipe(
|
|
|
|
map(res => {
|
2019-09-19 18:05:59 +09:00
|
|
|
return this.decodeLogoutResponse(res);
|
2019-09-19 17:03:39 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-19 18:05:59 +09:00
|
|
|
|
|
|
|
public decodeLogoutResponse(message: ServerMessage): LogoutResponse {
|
2019-09-19 18:22:13 +09:00
|
|
|
return {
|
|
|
|
reasonCode: message.bodyList[0]
|
|
|
|
} as LogoutResponse;
|
2019-09-19 18:05:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public logoutRemote(
|
|
|
|
req: LogoutRemoteRequest
|
|
|
|
): Observable<LogoutRemoteResponse> {
|
|
|
|
const bodyList: PacketBody[] = [];
|
|
|
|
|
|
|
|
bodyList.push(
|
|
|
|
{ type: PacketBodyValue.String, value: req.targetDeviceType },
|
|
|
|
{ type: PacketBodyValue.String, value: req.requestDeviceType }
|
|
|
|
);
|
|
|
|
|
|
|
|
return this.protocolService
|
|
|
|
.call(SVC_TYPE_LOGOUT, SSVC_TYPE_LOGOUT_REMOTE_REQ, ...bodyList)
|
|
|
|
.pipe(
|
|
|
|
map(res => {
|
|
|
|
return this.decodeLogoutRemoteResponse(res);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public decodeLogoutRemoteResponse(
|
|
|
|
message: ServerMessage
|
|
|
|
): LogoutRemoteResponse {
|
|
|
|
return {
|
|
|
|
targetDeviceType: message.bodyList[0],
|
|
|
|
resultCode: message.bodyList[1]
|
|
|
|
} as LogoutRemoteResponse;
|
|
|
|
}
|
|
|
|
|
|
|
|
public decodeLogoutRemoteNotification(
|
|
|
|
message: ServerMessage
|
|
|
|
): LogoutRemoteNotification {
|
|
|
|
return {
|
|
|
|
requestDeviceType: message.bodyList[0]
|
|
|
|
} as LogoutRemoteNotification;
|
|
|
|
}
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|