angular - 如何更改登录组件以使其使用用户名而不是电子邮件?
问题描述
我有一个在登录时使用用户名和密码的 spring boot api。那么如何更改 ngx 管理员以接受用户名而不是电子邮件作为凭据?
解决方案
我有一个类似的问题。最终创建自定义身份验证组件,因为需要更正布局(其中包含与电子邮件相关的内容)。
登录组件.ts:
import { Component } from '@angular/core';
import { NbLoginComponent } from '@nebular/auth';
@Component({
selector: 'ngx-login',
styleUrls: ['./login.component.scss'],
templateUrl: './login.component.html',
})
export class NgxLoginComponent extends NbLoginComponent {
}
简单的 HTML 模板:
<h1 class="title">Sign In</h1>
<form (ngSubmit)="login()" #form="ngForm" aria-labelledby="title">
<div class="form-control-group">
<label class="label">Username</label>
<input nbInput
fullWidth
[(ngModel)]="user.username"
name="username"
autofocus
class="form-control">
</div>
<div class="form-control-group">
<label class="label" for="input-password">Password:</label>
<input nbInput
fullWidth
[(ngModel)]="user.password"
#password="ngModel"
name="password"
type="password"
id="input-password"
placeholder="Password"
[status]="password.dirty ? (password.invalid ? 'danger' : 'success') : ''"
[required]="getConfigValue('forms.validation.password.required')"
[minlength]="getConfigValue('forms.validation.password.minLength')"
[maxlength]="getConfigValue('forms.validation.password.maxLength')"
[attr.aria-invalid]="password.invalid && password.touched ? true : null"
class="form-control">
<ng-container *ngIf="password.invalid && password.touched ">
<p class="error-message" *ngIf="password.errors?.required">
Password is required!
</p>
<p class="error-message" *ngIf="(password.errors?.minlength || password.errors?.maxlength)">
Password should contains
from {{ getConfigValue('forms.validation.password.minLength') }}
to {{ getConfigValue('forms.validation.password.maxLength') }}
characters
</p>
</ng-container>
</div>
<div class="form-control-group accept-group">
<nb-checkbox name="rememberMe" [(ngModel)]="user.rememberMe"
*ngIf="rememberMe">Remember me</nb-checkbox>
</div>
<button nbButton
fullWidth
status="success"
[class.btn-pulse]="submitted"
class="btn btn-block btn-hero-success"
style="cursor: pointer;">
Sign In
</button>
</form>
更多是这里文档
推荐阅读
- java - 有没有办法重定向 WOPI 休息调用以读取共享点文件?
- react-native - 如何从获取的 API 在渲染部分创建组件?
- azure-devops - 用于逻辑应用和天蓝色功能的 CI/CD 管道模板
- jquery - Multiple instance of jquery and sending value to php via ajax
- unit-testing - Can unit/integration tests have no assert? And what about this particular case?
- python - 没有使用 cx_Freeze 冻结模块 _cffi_
- scala - Scala pattern matching for tuple with options still needs unwrapping for the some case
- python - How to kill a Windows running exe with Python
- python - 为什么解析的标签名称不同?
- python - sqlite3.IntegrityError:UNIQUE 约束失败:即使我输入的值是唯一的,也会出错?