logout after password change
This commit is contained in:
parent
954782ca3b
commit
8c206f35c8
@ -11,14 +11,15 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
|||||||
import {
|
import {
|
||||||
NgbAccordionModule,
|
NgbAccordionModule,
|
||||||
NgbActiveModal,
|
NgbActiveModal,
|
||||||
|
NgbModal,
|
||||||
NgbModalModule,
|
NgbModalModule,
|
||||||
|
NgbModalRef,
|
||||||
} from '@ng-bootstrap/ng-bootstrap'
|
} from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { HttpClientModule } from '@angular/common/http'
|
import { HttpClientModule } from '@angular/common/http'
|
||||||
import { TextComponent } from '../input/text/text.component'
|
import { TextComponent } from '../input/text/text.component'
|
||||||
import { PasswordComponent } from '../input/password/password.component'
|
import { PasswordComponent } from '../input/password/password.component'
|
||||||
import { of, throwError } from 'rxjs'
|
import { of, throwError } from 'rxjs'
|
||||||
import { ToastService } from 'src/app/services/toast.service'
|
import { ToastService } from 'src/app/services/toast.service'
|
||||||
import { By } from '@angular/platform-browser'
|
|
||||||
import { Clipboard } from '@angular/cdk/clipboard'
|
import { Clipboard } from '@angular/cdk/clipboard'
|
||||||
|
|
||||||
const profile = {
|
const profile = {
|
||||||
@ -35,6 +36,7 @@ describe('ProfileEditDialogComponent', () => {
|
|||||||
let profileService: ProfileService
|
let profileService: ProfileService
|
||||||
let toastService: ToastService
|
let toastService: ToastService
|
||||||
let clipboard: Clipboard
|
let clipboard: Clipboard
|
||||||
|
let modalService: NgbModal
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -55,6 +57,7 @@ describe('ProfileEditDialogComponent', () => {
|
|||||||
profileService = TestBed.inject(ProfileService)
|
profileService = TestBed.inject(ProfileService)
|
||||||
toastService = TestBed.inject(ToastService)
|
toastService = TestBed.inject(ToastService)
|
||||||
clipboard = TestBed.inject(Clipboard)
|
clipboard = TestBed.inject(Clipboard)
|
||||||
|
modalService = TestBed.inject(NgbModal)
|
||||||
fixture = TestBed.createComponent(ProfileEditDialogComponent)
|
fixture = TestBed.createComponent(ProfileEditDialogComponent)
|
||||||
component = fixture.componentInstance
|
component = fixture.componentInstance
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
@ -160,6 +163,28 @@ describe('ProfileEditDialogComponent', () => {
|
|||||||
expect(component.saveDisabled).toBeFalsy()
|
expect(component.saveDisabled).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should logout on save if password changed', fakeAsync(() => {
|
||||||
|
const getSpy = jest.spyOn(profileService, 'get')
|
||||||
|
getSpy.mockReturnValue(of(profile))
|
||||||
|
component.ngOnInit()
|
||||||
|
component['newPassword'] = 'new*pass'
|
||||||
|
component.form.get('password').patchValue('new*pass')
|
||||||
|
component.form.get('password_confirm').patchValue('new*pass')
|
||||||
|
|
||||||
|
const updateSpy = jest.spyOn(profileService, 'update')
|
||||||
|
updateSpy.mockReturnValue(of(null))
|
||||||
|
Object.defineProperty(window, 'location', {
|
||||||
|
value: {
|
||||||
|
href: 'http://localhost/',
|
||||||
|
},
|
||||||
|
writable: true, // possibility to override
|
||||||
|
})
|
||||||
|
component.save()
|
||||||
|
expect(updateSpy).toHaveBeenCalled()
|
||||||
|
tick(2600)
|
||||||
|
expect(window.location.href).toContain('logout')
|
||||||
|
}))
|
||||||
|
|
||||||
it('should support auth token copy', fakeAsync(() => {
|
it('should support auth token copy', fakeAsync(() => {
|
||||||
const getSpy = jest.spyOn(profileService, 'get')
|
const getSpy = jest.spyOn(profileService, 'get')
|
||||||
getSpy.mockReturnValue(of(profile))
|
getSpy.mockReturnValue(of(profile))
|
||||||
|
@ -112,8 +112,6 @@ export class ProfileEditDialogComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onPasswordChange(): void {
|
onPasswordChange(): void {
|
||||||
console.log(this.currentPassword, this.newPassword)
|
|
||||||
|
|
||||||
this.showPasswordConfirm = this.currentPassword !== this.newPassword
|
this.showPasswordConfirm = this.currentPassword !== this.newPassword
|
||||||
|
|
||||||
if (this.showPasswordConfirm) {
|
if (this.showPasswordConfirm) {
|
||||||
@ -131,6 +129,7 @@ export class ProfileEditDialogComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
save(): void {
|
save(): void {
|
||||||
|
const passwordChanged = this.currentPassword !== this.newPassword
|
||||||
const profile = Object.assign({}, this.form.value)
|
const profile = Object.assign({}, this.form.value)
|
||||||
this.networkActive = true
|
this.networkActive = true
|
||||||
this.profileService
|
this.profileService
|
||||||
@ -138,7 +137,16 @@ export class ProfileEditDialogComponent implements OnInit, OnDestroy {
|
|||||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
|
console.log('next', passwordChanged)
|
||||||
this.toastService.showInfo($localize`Profile updated successfully`)
|
this.toastService.showInfo($localize`Profile updated successfully`)
|
||||||
|
if (passwordChanged) {
|
||||||
|
this.toastService.showInfo(
|
||||||
|
$localize`Password has been changed, you will be logged out momentarily.`
|
||||||
|
)
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = `${window.location.origin}/accounts/logout/?next=/accounts/login/`
|
||||||
|
}, 2500)
|
||||||
|
}
|
||||||
this.activeModal.close()
|
this.activeModal.close()
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user