Merge Dev in Staging
This commit is contained in:
commit
5ab418748c
@ -1,67 +0,0 @@
|
|||||||
import { Response, Request } from "express";
|
|
||||||
import { Controller, Post } from "@ControllerPattern/index";
|
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
|
||||||
import { Service } from "typedi";
|
|
||||||
import AuthService, { ICustomerJwtPayload } from "@Services/common/AuthService/AuthService";
|
|
||||||
import { JwtPayload } from "jsonwebtoken";
|
|
||||||
|
|
||||||
@Controller()
|
|
||||||
@Service()
|
|
||||||
export default class CustomerController extends ApiController {
|
|
||||||
constructor(private authService: AuthService) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Post("/api/v1/france-connect/customer/login/:email")
|
|
||||||
// protected async login(req: Request, response: Response) {
|
|
||||||
// try {
|
|
||||||
// const email = req.params["email"];
|
|
||||||
// if (!email) throw new Error("email is required");
|
|
||||||
|
|
||||||
// const payload = await this.authService.getCustomerJwtPayload(email);
|
|
||||||
// if (!payload) {
|
|
||||||
// this.httpNotFoundRequest(response);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// const accessToken = this.authService.generateAccessToken(payload);
|
|
||||||
// const refreshToken = this.authService.generateRefreshToken(payload);
|
|
||||||
// //success
|
|
||||||
// this.httpSuccess(response, { accessToken, refreshToken });
|
|
||||||
// } catch (error) {
|
|
||||||
// this.httpInternalError(response);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Post("/api/v1/france-connect/customer/refresh-token")
|
|
||||||
protected async refreshToken(req: Request, response: Response) {
|
|
||||||
try {
|
|
||||||
const authHeader = req.headers["authorization"];
|
|
||||||
const token = authHeader && authHeader.split(" ")[1];
|
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
this.httpBadRequest(response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let accessToken;
|
|
||||||
this.authService.verifyRefreshToken(token, (err, customerPayload) => {
|
|
||||||
if (err) {
|
|
||||||
this.httpUnauthorized(response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const customer = customerPayload as JwtPayload;
|
|
||||||
delete customer.iat;
|
|
||||||
delete customer!.exp;
|
|
||||||
accessToken = this.authService.generateAccessToken({...customer} as ICustomerJwtPayload);
|
|
||||||
});
|
|
||||||
|
|
||||||
//success
|
|
||||||
this.httpSuccess(response, {accessToken});
|
|
||||||
} catch (error) {
|
|
||||||
this.httpInternalError(response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
|||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import Id360Service, { EnrollmentResponse } from "@Services/common/Id360Service/Id360Service";
|
import Id360Service, { EnrollmentResponse } from "@Services/common/Id360Service/Id360Service";
|
||||||
import CustomersService from "@Services/customer/CustomersService/CustomersService";
|
import CustomersService from "@Services/customer/CustomersService/CustomersService";
|
||||||
import AuthService from "@Services/common/AuthService/AuthService";
|
import AuthService, { ICustomerJwtPayload } from "@Services/common/AuthService/AuthService";
|
||||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@ -34,11 +34,9 @@ export default class CustomerController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
await new Promise( resolve => setTimeout(resolve, 3000)); // wait 3 seconds to be sure that the enrollment is finilazed
|
||||||
const res = await this.id360Service.getEnrollment(callbackToken);
|
const res = await this.id360Service.getEnrollment(callbackToken);
|
||||||
const enrollment = await res.json() as EnrollmentResponse;
|
const enrollment = await res.json() as EnrollmentResponse;
|
||||||
if(enrollment.status === "STARTED") {
|
|
||||||
this.loginCallback(req, response);
|
|
||||||
}
|
|
||||||
if (enrollment.status !== "OK") {
|
if (enrollment.status !== "OK") {
|
||||||
this.httpUnauthorized(response, "Enrollment status is not OK");
|
this.httpUnauthorized(response, "Enrollment status is not OK");
|
||||||
return;
|
return;
|
||||||
@ -88,4 +86,38 @@ export default class CustomerController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post("/api/v1/id360/customers/refresh-token")
|
||||||
|
protected async refreshToken(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const authHeader = req.headers["authorization"];
|
||||||
|
const token = authHeader && authHeader.split(" ")[1];
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
this.httpBadRequest(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let accessToken;
|
||||||
|
this.authService.verifyRefreshToken(token, (err, userPayload) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
this.httpUnauthorized(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = userPayload as ICustomerJwtPayload;
|
||||||
|
delete user.iat;
|
||||||
|
delete user.exp;
|
||||||
|
accessToken = this.authService.generateAccessToken(user);
|
||||||
|
});
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, { accessToken });
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
this.httpInternalError(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,12 +70,15 @@ export default class UserController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = userPayload as IUserJwtPayload;
|
const user = userPayload as IUserJwtPayload;
|
||||||
|
delete user.iat;
|
||||||
|
delete user.exp;
|
||||||
accessToken = this.authService.generateAccessToken(user);
|
accessToken = this.authService.generateAccessToken(user);
|
||||||
});
|
});
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpSuccess(response, { accessToken });
|
this.httpSuccess(response, { accessToken });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import DeedTypesControllerSuperAdmin from "./api/super-admin/DeedTypesController
|
|||||||
import DocumentsControllerSuperAdmin from "./api/super-admin/DocumentsController";
|
import DocumentsControllerSuperAdmin from "./api/super-admin/DocumentsController";
|
||||||
import DocumentTypesControllerSuperAdmin from "./api/super-admin/DocumentTypesController";
|
import DocumentTypesControllerSuperAdmin from "./api/super-admin/DocumentTypesController";
|
||||||
import IdNotUserController from "./api/idnot/UserController";
|
import IdNotUserController from "./api/idnot/UserController";
|
||||||
import FranceConnectCustomerController from "./api/franceConnect/CustomerController";
|
|
||||||
import FilesControllerSuperAdmin from "./api/super-admin/FilesController";
|
import FilesControllerSuperAdmin from "./api/super-admin/FilesController";
|
||||||
import RulesControllerSuperAdmin from "./api/super-admin/RulesController";
|
import RulesControllerSuperAdmin from "./api/super-admin/RulesController";
|
||||||
import RolesControllerSuperAdmin from "./api/super-admin/RolesController";
|
import RolesControllerSuperAdmin from "./api/super-admin/RolesController";
|
||||||
@ -64,7 +63,6 @@ export default {
|
|||||||
Container.get(DocumentTypesControllerSuperAdmin);
|
Container.get(DocumentTypesControllerSuperAdmin);
|
||||||
Container.get(LiveVoteController);
|
Container.get(LiveVoteController);
|
||||||
Container.get(IdNotUserController);
|
Container.get(IdNotUserController);
|
||||||
Container.get(FranceConnectCustomerController);
|
|
||||||
Container.get(FilesControllerSuperAdmin);
|
Container.get(FilesControllerSuperAdmin);
|
||||||
Container.get(DocumentsControllerSuperAdmin);
|
Container.get(DocumentsControllerSuperAdmin);
|
||||||
Container.get(RulesControllerSuperAdmin);
|
Container.get(RulesControllerSuperAdmin);
|
||||||
|
@ -45,6 +45,7 @@ export default abstract class BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected httpResponse(response: Response, httpCode: HttpCodes, responseData: IResponseData = {}) {
|
protected httpResponse(response: Response, httpCode: HttpCodes, responseData: IResponseData = {}) {
|
||||||
|
console.log("httpResponse", httpCode, responseData);
|
||||||
if (responseData instanceof Error) {
|
if (responseData instanceof Error) {
|
||||||
throw responseData;
|
throw responseData;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ export default class DocumentsService extends BaseService {
|
|||||||
public async refuse(uid: string, document: Partial<Document>, refused_reason: string): Promise<Documents> {
|
public async refuse(uid: string, document: Partial<Document>, refused_reason: string): Promise<Documents> {
|
||||||
if (document.files) {
|
if (document.files) {
|
||||||
for (let i = 0; i < document.files.length; i++) {
|
for (let i = 0; i < document.files.length; i++) {
|
||||||
console.log("archiving file", document.files[i]?.uid);
|
|
||||||
await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string);
|
await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ enum PROVIDER_OPENID {
|
|||||||
export interface ICustomerJwtPayload {
|
export interface ICustomerJwtPayload {
|
||||||
customerId: string;
|
customerId: string;
|
||||||
email: string;
|
email: string;
|
||||||
|
iat?: number;
|
||||||
|
exp?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IdNotJwtPayload {
|
export interface IdNotJwtPayload {
|
||||||
@ -31,6 +33,8 @@ export interface IUserJwtPayload {
|
|||||||
office_Id: string;
|
office_Id: string;
|
||||||
role: string;
|
role: string;
|
||||||
rules: string[];
|
rules: string[];
|
||||||
|
iat?: number;
|
||||||
|
exp?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
|
@ -46,7 +46,6 @@ export default class DocumentsService extends BaseService {
|
|||||||
public async refuse(uid: string, document: Partial<Document>, refused_reason: string): Promise<Documents> {
|
public async refuse(uid: string, document: Partial<Document>, refused_reason: string): Promise<Documents> {
|
||||||
if (document.files) {
|
if (document.files) {
|
||||||
for (let i = 0; i < document.files.length; i++) {
|
for (let i = 0; i < document.files.length; i++) {
|
||||||
console.log("archiving file", document.files[i]?.uid);
|
|
||||||
await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string);
|
await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ export default class DocumentsService extends BaseService {
|
|||||||
public async refuse(uid: string, document: Partial<Document>, refused_reason: string): Promise<Documents> {
|
public async refuse(uid: string, document: Partial<Document>, refused_reason: string): Promise<Documents> {
|
||||||
if (document.files) {
|
if (document.files) {
|
||||||
for (let i = 0; i < document.files.length; i++) {
|
for (let i = 0; i < document.files.length; i++) {
|
||||||
console.log("archiving file", document.files[i]?.uid);
|
|
||||||
await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string);
|
await this.filesRepository.deleteKeyAndArchive(document.files[i]?.uid as string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user