Add option to "Stay signed in"

pull/82/head
Matthias Frey 4 years ago committed by Thomas
parent bcc9ac52a2
commit cf4d78a8b7

@ -87,7 +87,7 @@ export class HeaderComponent implements OnChanges {
public openLoginDialog(): void {
if(this.webAuthnService.isEnabled()){
this.webAuthnService.verifyWebAuthn().subscribe(({ authToken }) => {
this.setToken(authToken);
this.setToken(authToken, false);
});
return;
}
@ -114,14 +114,14 @@ export class HeaderComponent implements OnChanges {
takeUntil(this.unsubscribeSubject)
)
.subscribe(({ authToken }) => {
this.setToken(authToken);
this.setToken(authToken, data.staySignedIn);
});
}
});
}
public setToken(aToken: string) {
this.tokenStorageService.saveToken(aToken);
public setToken(aToken: string, staySignedIn: boolean) {
this.tokenStorageService.saveToken(aToken, staySignedIn);
this.router.navigate(['/']);
}

@ -19,6 +19,7 @@
[(ngModel)]="data.accessToken"
></textarea>
</mat-form-field>
<mat-checkbox [(ngModel)]="data.staySignedIn">Stay signed in</mat-checkbox>
</div>
</div>
<div class="float-right" mat-dialog-actions>

@ -6,6 +6,7 @@ import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatCheckboxModule} from "@angular/material/checkbox";
import { LoginWithAccessTokenDialog } from './login-with-access-token-dialog.component';
@ -16,6 +17,7 @@ import { LoginWithAccessTokenDialog } from './login-with-access-token-dialog.com
CommonModule,
FormsModule,
MatButtonModule,
MatCheckboxModule,
MatDialogModule,
MatFormFieldModule,
MatInputModule,

@ -11,11 +11,13 @@ export class TokenStorageService {
public constructor(private userService: UserService) {}
public getToken(): string {
return window.sessionStorage.getItem(TOKEN_KEY);
return window.localStorage.getItem(TOKEN_KEY) || window.sessionStorage.getItem(TOKEN_KEY);
}
public saveToken(token: string): void {
window.sessionStorage.removeItem(TOKEN_KEY);
public saveToken(token: string, staySignedIn: boolean = false): void {
if (staySignedIn) {
window.localStorage.setItem(TOKEN_KEY, token);
}
window.sessionStorage.setItem(TOKEN_KEY, token);
}
@ -23,6 +25,7 @@ export class TokenStorageService {
const utmSource = window.sessionStorage.getItem('utm_source');
window.sessionStorage.clear();
window.localStorage.removeItem(TOKEN_KEY);
this.userService.remove();

Loading…
Cancel
Save