spring - 在 jhipster 的导航栏中显示用户名
问题描述
在 jhispter 应用程序中,有没有办法在导航栏中添加我们实际登录的用户 l 登录?我试图在 navbar.component.html 中添加以下内容,但没有成功。
谢谢
<div [ngSwitch]="isAuthenticated()">
<div class="alert alert-success" *ngSwitchCase="true">
<span *ngIf="account" jhiTranslate="home.logged.message"
translateValues="{username: '{{account.login}}'}"> You are logged in as user "{{account.login}}". </span>
</div>
<div class="alert alert-warning" *ngSwitchCase="false">
<span jhiTranslate="global.messages.info.authenticated.prefix">If you want to </span>
<a class="alert-link" (click)="login()" jhiTranslate="global.messages.info.authenticated.link">sign in</a></span>
</div>
</div>
解决方案
同样对于 jhipster react 项目
在 app.tsx 中
<Header
isAuthenticated={this.props.isAuthenticated}
login={this.props.account.login}
isAdmin={this.props.isAdmin}
currentLocale={this.props.currentLocale}
onLocaleChange={this.props.setLocale}
ribbonEnv={this.props.ribbonEnv}
isInProduction={this.props.isInProduction}
isSwaggerEnabled={this.props.isSwaggerEnabled}
/>
.
.
.
const mapStateToProps = ({ authentication, applicationProfile, locale }: IRootState) => ({
currentLocale: locale.currentLocale,
isAuthenticated: authentication.isAuthenticated,
account: authentication.account,
isAdmin: hasAnyAuthority(authentication.account.authorities, [AUTHORITIES.ADMIN]),
ribbonEnv: applicationProfile.ribbonEnv,
isInProduction: applicationProfile.inProduction,
isSwaggerEnabled: applicationProfile.isSwaggerEnabled
});
在 header.tsx
const { currentLocale, isAuthenticated, login, isAdmin, isSwaggerEnabled, isInProduction } = this.props;
.
.
.
<AccountMenu login={login} isAuthenticated={isAuthenticated} closeNav={this.closeNav} />
在 account.tsx 中
export const AccountMenu = props => (
<NavDropdown
closeNav={props.closeNav}
icon="user"
name={props.isAuthenticated ? props.login : translate('global.menu.account.main')}
id="account-menu"
>
{props.isAuthenticated ? accountMenuItemsAuthenticated : accountMenuItems}
</NavDropdown>
);
推荐阅读
- ios - YTPlayerView 不在模拟器上播放内容(解码失败,错误代码)
- java - log4j2中的“配置状态”和“根级别”有什么区别
- compiler-construction - Coq中的部分函数/未定义?
- bison - flex bison:创建多个字符变量
- kiwi-tcms - Kiwi 向 Bugzilla 报告问题
- apache-nifi - NiFi 阻塞/挂起
- magento - Magento 2 Success.phtml 输出订单值
- chisel - 如何在 Chisel 中生成带有参数化模块的 Verilog 代码?
- verilog - 不能在verilog中使用else总是阻塞
- bash - 为什么这个命令不从文件中获取输入,尽管重新编排?