Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########
- login-fca.component.ts
- ########
- export class LoginFcaComponent implements OnInit {
- account: Account;
- modalRef: NgbModalRef;
- authenticationError: boolean;
- password: string;
- rememberMe: boolean;
- username: string;
- credentials: any;
- constructor(
- private principal: Principal,
- private loginService: LoginService,
- private eventManager: JhiEventManager,
- private router: Router,
- private stateStorageService: StateStorageService
- ) {
- this.credentials = {};
- }
- ngOnInit() {
- this.principal.identity().then((account) => {
- this.account = account;
- });
- this.registerAuthenticationSuccess();
- }
- registerAuthenticationSuccess() {
- this.eventManager.subscribe('authenticationSuccess', (message) => {
- this.principal.identity().then((account) => {
- this.account = account;
- });
- });
- }
- isAuthenticated() {
- return this.principal.isAuthenticated();
- }
- login() {
- this.loginService.login({
- username: this.username,
- password: this.password,
- rememberMe: this.rememberMe
- }).then(() => {
- this.authenticationError = false;
- if (this.router.url === '/register' || (/^\/activate\//.test(this.router.url)) ||
- (/^\/reset\//.test(this.router.url))) {
- this.router.navigate(['']);
- }
- this.eventManager.broadcast({
- name: 'authenticationSuccess',
- content: 'Sending Authentication Success'
- });
- // // previousState was set in the authExpiredInterceptor before being redirected to login modal.
- // // since login is succesful, go to stored previousState and clear previousState
- const redirect = this.stateStorageService.getUrl();
- if (redirect) {
- this.stateStorageService.storeUrl(null);
- this.router.navigate([redirect]);
- }
- this.router.navigate(['dashboard']);
- }).catch(() => {
- this.authenticationError = true;
- });
- }
- }
- ########
- login-fca.component.spec.ts
- ########
- describe('Login Tests', () => {
- describe('LoginFcaComponent', () => {
- let comp: LoginFcaComponent;
- let fixture: ComponentFixture<LoginFcaComponent>;
- let mockAuth: any;
- let mockPrincipal: any;
- beforeEach(async(() => {
- TestBed.configureTestingModule({
- imports: [FcaSystemIntegrationToolTestModule],
- declarations: [LoginFcaComponent],
- providers: [
- {
- provider: Principal,
- useClass: MockPrincipal
- },
- {
- provider: AccountService,
- useClass: MockAccountService
- },
- {
- provider: LoginService,
- useClass: null
- },
- {
- provider: Router,
- useClass: MockActivatedRoute
- },
- JhiEventManager
- ]
- }).overrideTemplate(LoginFcaComponent, '')
- .compileComponents();
- }));
- beforeEach(() => {
- fixture = TestBed.createComponent(LoginFcaComponent);
- comp = fixture.componentInstance;
- mockAuth = fixture.debugElement.injector.get(AccountService);
- mockPrincipal = fixture.debugElement.injector.get(Principal);
- });
- it('should ensure the two passwords entered match', () => {
- comp.login();
- expect(true).toEqual(true);
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement