Misc Updates (#665)

* Do not allow non-admins to change their passwords when authentication is disabled

* Clean up the login page so that input field text is black

* cleanup some resizing when typing a password and having a lot of users

* Changed the LastActive for a user to not just be login, but also when they open an already authenticated session.
This commit is contained in:
Joseph Milazzo 2021-10-13 11:13:55 -07:00 committed by GitHub
parent 40ea4235fe
commit 70f324669b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 57 additions and 48 deletions

View file

@ -1,5 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { environment } from 'src/environments/environment';
import { ServerSettings } from './_models/server-settings';
@ -37,6 +38,8 @@ export class SettingsService {
}
getAuthenticationEnabled() {
return this.http.get<boolean>(this.baseUrl + 'settings/authentication-enabled', {responseType: 'text' as 'json'});
return this.http.get<string>(this.baseUrl + 'settings/authentication-enabled', {responseType: 'text' as 'json'}).pipe(map((res: string) => {
return res === 'true';
}));
}
}

View file

@ -1,6 +1,6 @@
<div class="mx-auto login">
<ng-container *ngIf="isLoaded">
<ng-container *ngIf="isLoaded">
<div class="display: inline-block" *ngIf="firstTimeFlow">
<h3 class="card-title text-center">Create an Admin Account</h3>
<div class="card p-3">
@ -12,7 +12,7 @@
<form [formGroup]="loginForm" (ngSubmit)="login()" novalidate class="needs-validation" *ngIf="!firstTimeFlow">
<div class="row row-cols-4 row-cols-md-4 row-cols-sm-2 row-cols-xs-2">
<ng-container *ngFor="let member of memberNames">
<div class="col align-self-center card p-3 m-3" style="width: 12rem;">
<div class="col align-self-center card p-3 m-3" style="max-width: 12rem;">
<span tabindex="0" (click)="select(member)" a11y-click="13,32">
<div class="logo-container">
<h3 class="card-title text-center">{{member | sentenceCase}}</h3>

View file

@ -8,6 +8,8 @@
height: calc(100vh);
min-height: 289px;
position: relative;
width: 100vw;
max-width: 100vw;
&::before {
@ -80,4 +82,5 @@
input {
background-color: #fff !important;
color: black;
}

View file

@ -47,7 +47,7 @@ export class UserLoginComponent implements OnInit {
this.settingsService.getAuthenticationEnabled().pipe(take(1)).subscribe((enabled: boolean) => {
// There is a bug where this is coming back as a string not a boolean.
this.authDisabled = enabled + '' === 'false';
this.authDisabled = !enabled;
if (this.authDisabled) {
this.loginForm.get('password')?.setValidators([]);

View file

@ -175,37 +175,42 @@
</div>
</ng-template>
<ng-template ngbPanelContent>
<p>Change your Password</p>
<div class="alert alert-danger" role="alert" *ngIf="resetPasswordErrors.length > 0">
<div *ngFor="let error of resetPasswordErrors">{{error}}</div>
</div>
<form [formGroup]="passwordChangeForm">
<div class="form-group">
<label for="new-password">New Password</label>
<input class="form-control" type="password" id="new-password" formControlName="password" required>
<div id="password-validations" class="invalid-feedback" *ngIf="passwordChangeForm.dirty || passwordChangeForm.touched">
<div *ngIf="password?.errors?.required">
This field is required
<ng-container *ngIf="isAuthenticationEnabled || isAdmin; else authDisabled">
<p>Change your Password</p>
<div class="alert alert-danger" role="alert" *ngIf="resetPasswordErrors.length > 0">
<div *ngFor="let error of resetPasswordErrors">{{error}}</div>
</div>
<form [formGroup]="passwordChangeForm">
<div class="form-group">
<label for="new-password">New Password</label>
<input class="form-control" type="password" id="new-password" formControlName="password" required>
<div id="password-validations" class="invalid-feedback" *ngIf="passwordChangeForm.dirty || passwordChangeForm.touched">
<div *ngIf="password?.errors?.required">
This field is required
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="confirm-password">Confirm Password</label>
<input class="form-control" type="password" id="confirm-password" formControlName="confirmPassword" aria-describedby="password-validations" required>
<div id="password-validations" class="invalid-feedback" *ngIf="passwordChangeForm.dirty || passwordChangeForm.touched">
<div *ngIf="!passwordsMatch">
Passwords must match
</div>
<div *ngIf="confirmPassword?.errors?.required">
This field is required
<div class="form-group">
<label for="confirm-password">Confirm Password</label>
<input class="form-control" type="password" id="confirm-password" formControlName="confirmPassword" aria-describedby="password-validations" required>
<div id="password-validations" class="invalid-feedback" *ngIf="passwordChangeForm.dirty || passwordChangeForm.touched">
<div *ngIf="!passwordsMatch">
Passwords must match
</div>
<div *ngIf="confirmPassword?.errors?.required">
This field is required
</div>
</div>
</div>
</div>
<div class="float-right mb-3">
<button type="button" class="btn btn-secondary mr-2" aria-describedby="password-panel" (click)="resetPasswordForm()">Reset</button>
<button type="submit" class="btn btn-primary" aria-describedby="password-panel" (click)="savePasswordForm()" [disabled]="!passwordChangeForm.valid || !(passwordChangeForm.dirty || passwordChangeForm.touched)">Save</button>
</div>
</form>
<div class="float-right mb-3">
<button type="button" class="btn btn-secondary mr-2" aria-describedby="password-panel" (click)="resetPasswordForm()">Reset</button>
<button type="submit" class="btn btn-primary" aria-describedby="password-panel" (click)="savePasswordForm()" [disabled]="!passwordChangeForm.valid || !(passwordChangeForm.dirty || passwordChangeForm.touched)">Save</button>
</div>
</form>
</ng-container>
<ng-template #authDisabled>
<p class="text-warning">Authentication is disabled on this server. A password is not required to authenticate.</p>
</ng-template>
</ng-template>
</ngb-panel>
<ngb-panel id="api-panel" title="OPDS">

View file

@ -11,8 +11,6 @@ import { AccountService } from 'src/app/_services/account.service';
import { NavService } from 'src/app/_services/nav.service';
import { ActivatedRoute } from '@angular/router';
import { SettingsService } from 'src/app/admin/settings.service';
import { keyframes } from '@angular/animations';
import { environment } from 'src/environments/environment';
@Component({
selector: 'app-user-preferences',
@ -29,6 +27,8 @@ export class UserPreferencesComponent implements OnInit, OnDestroy {
settingsForm: FormGroup = new FormGroup({});
passwordChangeForm: FormGroup = new FormGroup({});
user: User | undefined = undefined;
isAdmin: boolean = false;
isAuthenticationEnabled: boolean = true;
passwordsMatch = false;
resetPasswordErrors: string[] = [];
@ -75,7 +75,10 @@ export class UserPreferencesComponent implements OnInit, OnDestroy {
this.settingsService.getOpdsEnabled().subscribe(res => {
this.opdsEnabled = res;
})
});
this.settingsService.getAuthenticationEnabled().subscribe(res => {
this.isAuthenticationEnabled = res;
});
}
ngOnInit(): void {
@ -83,6 +86,7 @@ export class UserPreferencesComponent implements OnInit, OnDestroy {
this.accountService.currentUser$.pipe(take(1)).subscribe((user: User) => {
if (user) {
this.user = user;
this.isAdmin = this.accountService.hasAdminRole(user);
if (this.fontFamilies.indexOf(this.user.preferences.bookReaderFontFamily) < 0) {
this.user.preferences.bookReaderFontFamily = 'default';