I am stucking in the creation of an Angular project.
During the call to the LOGI
webservice, which allows the user to connect. In the DEPO
input: I added the account number 979963840303
hardcoded.
signIn(model: SignInModel): Observable < ApiResponse > {
const header: ApiHeader = this.store.selectSnapshot(AuthState.header);
header.USER = model.uid;
return this.generateToken().pipe(
switchMap(token => {
model.token = token;
return this.http.post < AuthResponse > (this.api + `/LOGI`, {
HEADER: {
...header,
USER: model.uid,
VERSION: model.version,
LANGUAGE: model.language,
},
SSO_IN: {
VIA_SSO: "TRUE",
DEPO: 979963840303,
MODE: "Trans",
TOKEN: token
},
});
}),
switchMap(response => {
if (response.RETURNCODE === ApiResponseCodeEnum.Ok) {
if (!response.SSO_OUT) {
this.logout().subscribe();
}
this.store.dispatch(new SetAuthStateAction({
user: model.uid,
session: response.IDSESSION,
language: model.language,
numTrx: response.INFO_HEADER.NUMTRX,
channel: response.INFO_HEADER.CHANNEL,
lastConnexionTime: response.INFO_HEADER.LAHECO,
lastConnexionDate: response.INFO_HEADER.LADACO,
lastErrorTime: response.INFO_HEADER.LAHEPWD,
lastErrorDate: response.INFO_HEADER.LADAPWD,
tiers: response.INFO_HEADER.TIERS,
version: model.version,
userType: response.INFO_HEADER.IDENTIF
}));
this.store.dispatch(new SetPortfoliosAction(response.SSO_OUT));
this.store.dispatch(new SetCurrentPortfolioAction({
CLER: response.SSO_OUT.CLER,
DEPO: response.SSO_OUT.DEPO,
INT_PTF: response.SSO_OUT.INT_PTF,
COD_TIT: response.SSO_OUT.COD_TIT,
AGENCE_NUM: response.SSO_OUT.AGENCE_NUM,
AGENCE_LIB: response.SSO_OUT.AGENCE_LIB,
IAT: response.SSO_OUT.IAT,
GRANTS: response.SSO_OUT.GRANTS
}));
return this.getSolde().pipe(
switchMap(soldeResponse => {
if (soldeResponse.RETURNCODE === ApiResponseCodeEnum.Ok) {
this.store.dispatch(new SetAuthStateAction({
user: model.uid,
session: response.IDSESSION,
language: model.language,
numTrx: response.INFO_HEADER.NUMTRX,
channel: response.INFO_HEADER.CHANNEL,
lastConnexionTime: response.INFO_HEADER.LAHECO,
lastConnexionDate: response.INFO_HEADER.LADACO,
lastErrorTime: response.INFO_HEADER.LAHEPWD,
lastErrorDate: response.INFO_HEADER.LADAPWD,
tiers: response.INFO_HEADER.TIERS,
version: model.version,
userType: response.INFO_HEADER.IDENTIF,
solde: soldeResponse.PTF.SOLDE,
}));
}
return of(soldeResponse);
})
);
}
return of(response);
})
);
}
The user connects and the client’s account information is displayed, here is what I retrieve in the console log.
The variable REFERENCE
retrieves the account number 979963840303
.
Now my problem is that I should not display this account number as a hard-coded value! Because, each user has a different account number!
I have modified
DEPO: 979963840303,
By
DEPO: model.depo,
I reconnect and I see this in payload, is the DEPO
variable empty?
In the console log, the REFERENCE
variable is equal to 0
.
Why is the account number empty when I use a variable? However, everything works if I add the value directly -> 979963840303
?
Here are my two components
identity.service.ts
@Injectable()
export class IdentityService {
private readonly api: string = environment.api;
constructor(
private http: HttpClient,
private store: Store,
private router: Router
) {}
generateToken(): Observable<string> {
const header: ApiHeader = this.store.selectSnapshot(AuthState.header);
return this.http
.post<{ TOKEN: string }>(this.api + `/MKTK`, {
HEADER: header,
MODE: "Trans",
})
.pipe(
map((response) => {
return response.TOKEN;
})
);
}
signIn(model: SignInModel): Observable<ApiResponse> {
const header: ApiHeader = this.store.selectSnapshot(AuthState.header);
header.USER = model.uid;
return this.generateToken().pipe(
switchMap((token) => {
model.token = token;
return this.http.post<AuthResponse>(this.api + `/LOGI`, {
HEADER: {
...header,
USER: model.uid,
VERSION: model.version,
LANGUAGE: model.language,
},
SSO_IN: {
VIA_SSO: "TRUE",
DEPO: model.depo,
MODE: "Trans",
TOKEN: token,
},
});
}),
switchMap((response) => {
if (response.RETURNCODE === ApiResponseCodeEnum.Ok) {
if (!response.SSO_OUT) {
this.logout().subscribe();
}
this.store.dispatch(
new SetAuthStateAction({
user: model.uid,
session: response.IDSESSION,
language: model.language,
numTrx: response.INFO_HEADER.NUMTRX,
channel: response.INFO_HEADER.CHANNEL,
lastConnexionTime: response.INFO_HEADER.LAHECO,
lastConnexionDate: response.INFO_HEADER.LADACO,
lastErrorTime: response.INFO_HEADER.LAHEPWD,
lastErrorDate: response.INFO_HEADER.LADAPWD,
tiers: response.INFO_HEADER.TIERS,
version: model.version,
userType: response.INFO_HEADER.IDENTIF,
})
);
this.store.dispatch(new SetPortfoliosAction(response.SSO_OUT));
this.store.dispatch(
new SetCurrentPortfolioAction({
CLER: response.SSO_OUT.CLER,
DEPO: response.SSO_OUT.DEPO,
INT_PTF: response.SSO_OUT.INT_PTF,
COD_TIT: response.SSO_OUT.COD_TIT,
AGENCE_NUM: response.SSO_OUT.AGENCE_NUM,
AGENCE_LIB: response.SSO_OUT.AGENCE_LIB,
IAT: response.SSO_OUT.IAT,
GRANTS: response.SSO_OUT.GRANTS,
})
);
return this.getSolde().pipe(
switchMap((soldeResponse) => {
if (soldeResponse.RETURNCODE === ApiResponseCodeEnum.Ok) {
this.store.dispatch(
new SetAuthStateAction({
user: model.uid,
session: response.IDSESSION,
language: model.language,
numTrx: response.INFO_HEADER.NUMTRX,
channel: response.INFO_HEADER.CHANNEL,
lastConnexionTime: response.INFO_HEADER.LAHECO,
lastConnexionDate: response.INFO_HEADER.LADACO,
lastErrorTime: response.INFO_HEADER.LAHEPWD,
lastErrorDate: response.INFO_HEADER.LADAPWD,
tiers: response.INFO_HEADER.TIERS,
version: model.version,
userType: response.INFO_HEADER.IDENTIF,
solde: soldeResponse.PTF.SOLDE,
})
);
}
return of(soldeResponse);
})
);
}
return of(response);
})
);
}
logout(redirect: boolean = true): Observable<any> {
return this.store.dispatch(new ResetAuthStateAction()).pipe(
concatMap(() => this.store.dispatch(new ResetProfileStateAction())),
tap(() => {
if (redirect) {
this.router.navigate(["/sessions/signin"]);
}
})
);
}
signOut(): Observable<ApiResponse> {
return this.http
.post<AuthResponse>(this.api + `/LOGO`, {})
.pipe(concatMap(() => this.logout()));
}
getSolde(): Observable<SoldeResponse> {
return this.http.post<SoldeResponse>(
this.api + `/GPTF`,
{},
{ headers: { AddCustomer: "" } }
);
}
}
identity.sandbox.ts
@Injectable()
export class IdentitySandbox {
@Select(AuthState.isAuthenticated) isAuthenticated$!: Observable<boolean>;
constructor(private service: IdentityService) {}
signIn(model: SignInModel): Observable<ApiResponse> {
return this.service.signIn(model);
}
logout(): void {
this.service.logout();
}
signOut(): Observable<ApiResponse> {
return this.service.signOut();
}
}
identity.component.ts
export class IdentityComponent implements OnInit {
readonly supportedLangs: string[] = environment.supportedLanguages;
constructor(private sandbox: IdentitySandbox, private router: Router) {}
ngOnInit(): void {
this.sandbox.isAuthenticated$.pipe(take(1)).subscribe((res) => {
if (res) {
this.router.navigate(["/"]);
}
});
}
}
identity.component.html
<router-outlet></router-outlet>
signin.service.ts
@Injectable()
export class SigninService {
private readonly api: string = environment.api;
constructor(
private http: HttpClient,
private store: Store,
private identitySandbox: IdentitySandbox
) {}
signIn(model: SignInModel): Observable<ApiResponse> {
return this.identitySandbox.signIn(model);
}
}
signin.component.ts
export class SigninComponent implements OnInit {
private unsubscribe$ = new Subject<void>();
tokens: SignatureOtpModel = new SignatureOtpModel();
ngUnsubscribe = new Subject<void>();
private model: SignInModel = new SignInModel();
readonly supportedLangs: string[] = environment.supportedLanguages;
constructor(
private router: Router,
private service: SigninService,
private sandbox: AppSandbox
) {}
ngOnInit(): void {}
signIn(): void {
this.model.uid = this.tokens.user;
this.model.language = "FR";
this.model.mode = "Trans";
// this.model.depo = 979963840303;
this.service
.signIn(this.model)
.pipe(takeUntil(this.unsubscribe$))
.subscribe((res) => {
console.log("SignIn response:", res);
if (res.RETURNCODE === ApiResponseCodeEnum.Ok) {
this.router.navigate(["/online/portfolio/stocks"]);
} else {
console.error("SignIn failed, redirecting to logon");
this.logon();
}
});
}
logon(): void {
console.log("Before navigating, model values are:", {
MODE: this.model.mode,
TOKEN: this.model.token,
DEPO: this.model.depo,
});
this.router.navigate(["/sessions/logon"], {
queryParams: {
DEPO: this.model.depo,
MODE: this.model.mode,
TOKEN: this.model.token,
},
});
}
selectLanguage(language: string): void {
this.sandbox.setLanguage(language);
}
}
signIn.model.ts
export class SignInModel {
uid: string;
version: string;
modeCtrl: string;
todo: string;
menu: number;
date: string;
url: string;
language: string;
mode: string;
token: any;
depo: any;
constructor() {
this.uid = "";
this.version = "";
this.modeCtrl = "";
this.todo = "";
this.menu = 0;
this.date = "";
this.url = "";
this.language = "";
this.mode = "";
this.token = "";
this.depo = "";
}
}
I thank you for your help and the time you dedicated to my problem.
1