gpt4 book ai didi

angular - 我如何更改登录组件,以便它使用用户名而不是电子邮件?

转载 作者:行者123 更新时间:2023-12-05 05:11:01 28 4
gpt4 key购买 nike

我有一个在登录中使用用户名和密码的 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>

更多内容在这里 docs

关于angular - 我如何更改登录组件,以便它使用用户名而不是电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55985772/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com