简体   繁体   English

如何在jhipster打字稿文件angular 5中根据用户角色检查条件

[英]How to check condition based on user role in jhipster typescript file angular 5

I know how to use hasAnyAuthority directive in jhipster for HTML part. 我知道如何在jhipster中将hasAnyAuthority指令用于HTML部分。 But i am searching how can i do this in typescript part like if user has role farmer navigate to farmer profile, for admin navigate to dashboard. 但是我正在搜索如何在打字稿部分中执行此操作,例如如果用户具有角色农夫,请导航到农夫配置文件,而管理员则导航到仪表板。

Use the hasAnyAuthority() or related functions of Principal (see principal.service.ts ) in a click handler for instance. 例如,在单击处理程序中使用hasAnyAuthority()Principal相关功能(请参阅principal.service.ts )。

Also set authorities property on your route's data according to your needs. 还要根据需要在路线数据上设置authorities属性。

export const adminState: Routes = [
    {
        path: '',
        data: {
            authorities: ['ROLE_ADMIN']
        },
        canActivate: [UserRouteAccessService],
        children: ADMIN_ROUTES
    }
];

See JHipster doc about authorizations in Angular: https://www.jhipster.tech/using-angular 有关Angular中的授权,请参阅JHipster文档: https ://www.jhipster.tech/using-angular

Through HTML : 通过HTML:

*jhiHasAnyAuthority="{authorities: 'ROLE_ADMIN', enable:true/false}"

Through TS : 通过TS:

this.principal.identity().then(account => {
        if(account.authorities.includes('ROLE_ADMIN')){}
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Angular 中 -> 如何检查用户是否具有使用基于角色的访问权限且角色保存在数据库中的权限 - In Angular -> how to check if the user has permission using role-based access with the role save in the data base Angular - 如何根据用户角色重定向到仪表板 - Angular - How to redirect to Dashboard based on user role 带有枚举的 Angular 8 中基于角色的用户 - Role based user in Angular 8 with enum 如何在 angular 应用程序中从 wordpress 检查用户角色 - how to check user role from wordpress in a angular application 如何根据 Angular 中的用户角色将登录重定向到仪表板 - How to redirect login to dashboard based on user role in Angular 如何根据 angular 中的当前用户角色导入 svg - How to import an svg based on the current user role in angular 如何向jhipster(4.0.3)应用程序添加新的用户角色 - How to add new user role to jhipster(4.0.3) application 如何使基于Angular2反应形式的复选框选中和取消选中的条件起作用 - how to make condition work based on check box check and Uncheck using angular2 reactive forms 如何初始化 Angular 基于角色的安全性? - How to initialize Angular role based security? 如何使用Typescript根据Angular 4中的某些条件为html标签动态添加属性 - how to dynamically add property for a html tag based on some condition in angular 4 using typescript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM