SUPPORT-8427: Add logout
This commit is contained in:
parent
e98285c3eb
commit
1dacef1576
7 changed files with 180 additions and 55 deletions
|
|
@ -11,6 +11,7 @@ import esia.model.EmployeeModel;
|
|||
import esia.model.OrgInfoModel;
|
||||
import esia.model.OrganizationModel;
|
||||
import esia.service.EsiaAuthService;
|
||||
import esia.service.EsiaDataService;
|
||||
import esia.service.UlDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
|
@ -28,7 +29,7 @@ public class EsiaController {
|
|||
private EsiaAuthService esiaAuthService;
|
||||
|
||||
@Autowired
|
||||
private UlDataService ulDataService;
|
||||
private EsiaDataService esiaDataService;
|
||||
|
||||
@RequestMapping(value = "/esia/url")
|
||||
public String getEsiaUrl() {
|
||||
|
|
@ -47,58 +48,16 @@ public class EsiaController {
|
|||
|
||||
@RequestMapping(value = "/esia/org")
|
||||
public OrgInfoModel getOrgInfo(HttpServletRequest request) {
|
||||
String accessToken = null;
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie.getName().equals("access_token")) {
|
||||
accessToken = cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
OrganizationModel organizationModel = ulDataService.getOrganizationModel(accessToken);
|
||||
EmployeeModel chiefEmployeeModel = ulDataService.getChiefEmployeeModel(accessToken);
|
||||
EmployeeModel employeeModel = ulDataService.getEmployeeModel(accessToken);
|
||||
OrgInfoModel orgInfoModel = new OrgInfoModel();
|
||||
return esiaDataService.getOrgInfo(request);
|
||||
}
|
||||
|
||||
orgInfoModel.empFullname =
|
||||
employeeModel.getPerson().getLastName() + " " + employeeModel.getPerson().getFirstName()
|
||||
+ " " + employeeModel.getPerson().getMiddleName();
|
||||
orgInfoModel.empPosition = employeeModel.getPosition();
|
||||
orgInfoModel.fullName = organizationModel.getFullName();
|
||||
orgInfoModel.shortName = organizationModel.getShortName();
|
||||
Addresses addresses = organizationModel.getAddresses();
|
||||
if (addresses != null) {
|
||||
Arrays.stream(addresses.getElements()).forEach(addressModel -> {
|
||||
if (addressModel.getType().equals("OLG")) {
|
||||
orgInfoModel.olgAddress = addressModel.getAddressStr();
|
||||
}
|
||||
else if (addressModel.getType().equals("OPS")) {
|
||||
orgInfoModel.opsAddress = addressModel.getAddressStr();
|
||||
}
|
||||
} );
|
||||
}
|
||||
orgInfoModel.chiefFullname =
|
||||
chiefEmployeeModel.getPerson().getLastName() + " " + chiefEmployeeModel.getPerson()
|
||||
.getFirstName() + " " + chiefEmployeeModel.getPerson().getMiddleName();
|
||||
orgInfoModel.chiefPosition = chiefEmployeeModel.getPosition();
|
||||
orgInfoModel.ogrn = organizationModel.getOgrn();
|
||||
orgInfoModel.kpp = organizationModel.getKpp();
|
||||
orgInfoModel.inn = organizationModel.getInn();
|
||||
Contacts contacts = organizationModel.getContacts();
|
||||
if (contacts != null) {
|
||||
Arrays.stream(contacts.getElements()).forEach(contactModel -> {
|
||||
if (contactModel.getType().equals("OPH") && contactModel.getVrfStu().equals("VERIFIED")) {
|
||||
orgInfoModel.mobile = contactModel.getValue();
|
||||
}
|
||||
else if (contactModel.getType().equals("OEM") && contactModel.getVrfStu().equals("VERIFIED")) {
|
||||
orgInfoModel.email = contactModel.getValue();
|
||||
}
|
||||
} );
|
||||
}
|
||||
return orgInfoModel;
|
||||
@RequestMapping(value = "/esia/userfullname")
|
||||
public String getUserFullname(HttpServletRequest request) {
|
||||
return esiaDataService.getUserFullname(request);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/esia/orgunitname")
|
||||
public String getOrgUnitName(HttpServletRequest request) {
|
||||
return esiaDataService.getOrgUnitName(request);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
100
backend/src/main/java/esia/service/EsiaDataService.java
Normal file
100
backend/src/main/java/esia/service/EsiaDataService.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
package esia.service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import esia.model.*;
|
||||
import org.bouncycastle.asn1.x509.sigi.PersonalData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* @author Eduard Tihomirov
|
||||
*/
|
||||
@Service
|
||||
public class EsiaDataService {
|
||||
|
||||
@Autowired
|
||||
private UlDataService ulDataService;
|
||||
|
||||
public OrgInfoModel getOrgInfo(HttpServletRequest request) {
|
||||
String accessToken = getAccessToken(request);
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
OrganizationModel organizationModel = ulDataService.getOrganizationModel(accessToken);
|
||||
EmployeeModel chiefEmployeeModel = ulDataService.getChiefEmployeeModel(accessToken);
|
||||
EmployeeModel employeeModel = ulDataService.getEmployeeModel(accessToken);
|
||||
OrgInfoModel orgInfoModel = new OrgInfoModel();
|
||||
|
||||
orgInfoModel.empFullname =
|
||||
employeeModel.getPerson().getLastName() + " " + employeeModel.getPerson().getFirstName()
|
||||
+ " " + employeeModel.getPerson().getMiddleName();
|
||||
orgInfoModel.empPosition = employeeModel.getPosition();
|
||||
orgInfoModel.fullName = organizationModel.getFullName();
|
||||
orgInfoModel.shortName = organizationModel.getShortName();
|
||||
Addresses addresses = organizationModel.getAddresses();
|
||||
if (addresses != null) {
|
||||
Arrays.stream(addresses.getElements()).forEach(addressModel -> {
|
||||
if (addressModel.getType().equals("OLG")) {
|
||||
orgInfoModel.olgAddress = addressModel.getAddressStr();
|
||||
}
|
||||
else if (addressModel.getType().equals("OPS")) {
|
||||
orgInfoModel.opsAddress = addressModel.getAddressStr();
|
||||
}
|
||||
} );
|
||||
}
|
||||
orgInfoModel.chiefFullname =
|
||||
chiefEmployeeModel.getPerson().getLastName() + " " + chiefEmployeeModel.getPerson()
|
||||
.getFirstName() + " " + chiefEmployeeModel.getPerson().getMiddleName();
|
||||
orgInfoModel.chiefPosition = chiefEmployeeModel.getPosition();
|
||||
orgInfoModel.ogrn = organizationModel.getOgrn();
|
||||
orgInfoModel.kpp = organizationModel.getKpp();
|
||||
orgInfoModel.inn = organizationModel.getInn();
|
||||
Contacts contacts = organizationModel.getContacts();
|
||||
if (contacts != null) {
|
||||
Arrays.stream(contacts.getElements()).forEach(contactModel -> {
|
||||
if (contactModel.getType().equals("OPH") && contactModel.getVrfStu().equals("VERIFIED")) {
|
||||
orgInfoModel.mobile = contactModel.getValue();
|
||||
}
|
||||
else if (contactModel.getType().equals("OEM") && contactModel.getVrfStu().equals("VERIFIED")) {
|
||||
orgInfoModel.email = contactModel.getValue();
|
||||
}
|
||||
} );
|
||||
}
|
||||
return orgInfoModel;
|
||||
}
|
||||
|
||||
public String getOrgUnitName(HttpServletRequest request) {
|
||||
String accessToken = getAccessToken(request);
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
OrganizationModel organizationModel = ulDataService.getOrganizationModel(accessToken);
|
||||
return organizationModel.getFullName();
|
||||
}
|
||||
|
||||
public String getUserFullname(HttpServletRequest request) {
|
||||
String accessToken = getAccessToken(request);
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
EsiaAccessToken esiaAccessToken = ulDataService.readToken(accessToken);
|
||||
PersonModel personModel = ulDataService.getPersonData(accessToken, esiaAccessToken.getSbj_id());
|
||||
return personModel.getLastName() + " " + personModel.getFirstName().charAt(0) + ". " + personModel.getMiddleName().charAt(0) + ".";
|
||||
}
|
||||
|
||||
private String getAccessToken(HttpServletRequest request) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie.getName().equals("access_token")) {
|
||||
return cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,9 @@ package esia.service;
|
|||
import java.util.Map;
|
||||
|
||||
import esia.model.EmployeeModel;
|
||||
import esia.model.EsiaAccessToken;
|
||||
import esia.model.OrganizationModel;
|
||||
import esia.model.PersonModel;
|
||||
|
||||
/**
|
||||
* @author Eduard Tihomirov
|
||||
|
|
@ -17,4 +19,8 @@ public interface UlDataService {
|
|||
EmployeeModel getChiefEmployeeModel(String accessToken);
|
||||
|
||||
OrganizationModel getOrganizationModel(String accessToken);
|
||||
|
||||
PersonModel getPersonData(String prnsId, String accessToken);
|
||||
|
||||
EsiaAccessToken readToken(String accessToken);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,8 @@ public class UlDataServiceImpl implements UlDataService {
|
|||
}
|
||||
}
|
||||
|
||||
private PersonModel getPersonData(String prnsId, String accessToken) {
|
||||
@Override
|
||||
public PersonModel getPersonData(String prnsId, String accessToken) {
|
||||
try {
|
||||
String url = esiaConfig.getEsiaBaseUri() + "rs/prns/" + prnsId;
|
||||
HttpRequest getReq = HttpRequest.newBuilder(URI.create(url))
|
||||
|
|
@ -125,7 +126,8 @@ public class UlDataServiceImpl implements UlDataService {
|
|||
}
|
||||
}
|
||||
|
||||
private EsiaAccessToken readToken(String accessToken) {
|
||||
@Override
|
||||
public EsiaAccessToken readToken(String accessToken) {
|
||||
try {
|
||||
byte[] decodedBytes = Base64.getDecoder()
|
||||
.decode(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<button class="user-info" ngbDropdownToggle *ngIf="getIsAuth()">{{getUserFullname()}}</button>
|
||||
<div ngbDropdownMenu *ngIf="getIsAuth()">
|
||||
<div class="user-department">{{getOrgUnitName()}}</div>
|
||||
<a routerLink="/mydata" class="data">Данные организации</a>
|
||||
<button ngbDropdownItem class="exit" (click)="logout()">Выйти</button>
|
||||
</div>
|
||||
|
|
@ -13,6 +13,7 @@ import {
|
|||
} from "@webbpm/base-package";
|
||||
import {AppHeaderComponent} from "./component/app-header.component";
|
||||
import {AppFooterComponent} from "./component/app-footer.component";
|
||||
import {LogOutComponent} from "./component/logout.component";
|
||||
import {AccessDeniedComponent} from "./component/access-denied.component";
|
||||
import {ApplicationVersionComponent} from "./component/application-version.component";
|
||||
import {RouterModule} from "@angular/router";
|
||||
|
|
@ -28,6 +29,7 @@ export const DIRECTIVES = [
|
|||
forwardRef(() => AppHeaderComponent),
|
||||
forwardRef(() => AppFooterComponent),
|
||||
forwardRef(() => ApplicationVersionComponent),
|
||||
forwardRef(() => LogOutComponent),
|
||||
forwardRef(() => AccessDeniedComponent),
|
||||
forwardRef(() => AppProgressIndicationComponent),
|
||||
forwardRef(() => ErvuFileUpload)
|
||||
|
|
|
|||
50
frontend/src/ts/modules/app/component/logout.component.ts
Normal file
50
frontend/src/ts/modules/app/component/logout.component.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import {Component} from "@angular/core";
|
||||
import {Router} from "@angular/router";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {CookieService} from "ngx-cookie";
|
||||
|
||||
@Component({
|
||||
moduleId: module.id,
|
||||
selector: "[log-out]",
|
||||
templateUrl: "../../../../../src/resources/template/app/component/log_out.html"
|
||||
})
|
||||
export class LogOutComponent {
|
||||
|
||||
private userFullname: string;
|
||||
private orgUnitName: string;
|
||||
|
||||
|
||||
constructor(private router: Router, private httpClient: HttpClient,
|
||||
private cookieService: CookieService) {
|
||||
let isAuth = this.getIsAuth();
|
||||
if (isAuth) {
|
||||
this.httpClient.get<string>("esia/userfullname")
|
||||
.toPromise()
|
||||
.then(userFullname => {
|
||||
this.userFullname = userFullname;
|
||||
})
|
||||
this.httpClient.get<string>("esia/orgunitname")
|
||||
.toPromise()
|
||||
.then(orgUnitName => {
|
||||
this.orgUnitName = orgUnitName;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public logout(): void {
|
||||
this.cookieService.remove("isAuth");
|
||||
this.router.navigateByUrl("/");
|
||||
}
|
||||
|
||||
public getUserFullname(): string {
|
||||
return this.userFullname;
|
||||
}
|
||||
|
||||
public getIsAuth(): boolean {
|
||||
return this.cookieService.get("isAuth") != null;
|
||||
}
|
||||
|
||||
public getOrgUnitName(): string {
|
||||
return this.orgUnitName;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue