import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
+import { SharedModule } from '../../shared/shared.module';
import { LoginComponent } from './login/login.component';
import { LogoutComponent } from './logout/logout.component';
@NgModule({
imports: [
CommonModule,
- FormsModule
+ FormsModule,
+ SharedModule
],
declarations: [LoginComponent, LogoutComponent],
exports: [LogoutComponent]
<!-- Password -->
<div class="form-group has-feedback"
[ngClass]="{'has-error': (loginForm.submitted || password.dirty) && password.invalid}">
- <input id="password"
- name="password"
- [(ngModel)]="model.password"
- #password="ngModel"
- type="password"
- placeholder="Enter your password..."
- class="form-control"
- required>
+ <div class="input-group">
+ <input id="password"
+ name="password"
+ [(ngModel)]="model.password"
+ #password="ngModel"
+ type="password"
+ placeholder="Enter your password..."
+ class="form-control"
+ required>
+ <span class="input-group-btn">
+ <button type="button"
+ class="btn btn-default btn-password"
+ cdPasswordButton="password">
+ </button>
+ </span>
+ </div>
<div class="help-block"
- *ngIf="(loginForm.submitted || password.dirty) && password.invalid">Password is required</div>
+ *ngIf="(loginForm.submitted || password.dirty) && password.invalid">Password is required
+ </div>
</div>
<!-- Stay signed in -->
margin-bottom: 30px;
}
+ .btn-password,
.form-control {
color: #ececec;
background-color: #555555;
}
+ .btn-password:focus {
+ outline-color: #66afe9;
+ }
+
.checkbox-primary input[type="checkbox"]:checked + label::before,
.checkbox-primary input[type="radio"]:checked + label::before {
background-color: $oa-color-blue;
--- /dev/null
+import { PasswordButtonDirective } from './password-button.directive';
+
+describe('PasswordButtonDirective', () => {
+ it('should create an instance', () => {
+ const directive = new PasswordButtonDirective(null, null);
+ expect(directive).toBeTruthy();
+ });
+});
--- /dev/null
+import { Directive, ElementRef, HostListener, Input, OnInit, Renderer2 } from '@angular/core';
+
+@Directive({
+ selector: '[cdPasswordButton]'
+})
+export class PasswordButtonDirective implements OnInit {
+ private inputElement: any;
+ private iElement: any;
+
+ @Input('cdPasswordButton') private cdPasswordButton: string;
+
+ constructor(private el: ElementRef, private renderer: Renderer2) { }
+
+ ngOnInit() {
+ this.inputElement = document.getElementById(this.cdPasswordButton);
+ this.iElement = this.renderer.createElement('i');
+ this.renderer.addClass(this.iElement, 'icon-prepend');
+ this.renderer.addClass(this.iElement, 'fa');
+ this.renderer.appendChild(this.el.nativeElement, this.iElement);
+ this.update();
+ }
+
+ private update() {
+ if (this.inputElement.type === 'text') {
+ this.renderer.removeClass(this.iElement, 'fa-eye');
+ this.renderer.addClass(this.iElement, 'fa-eye-slash');
+ } else {
+ this.renderer.removeClass(this.iElement, 'fa-eye-slash');
+ this.renderer.addClass(this.iElement, 'fa-eye');
+ }
+ }
+
+ @HostListener('click')
+ onClick() {
+ // Modify the type of the input field.
+ this.inputElement.type = (this.inputElement.type === 'password') ? 'text' : 'password';
+ // Update the button icon/tooltip.
+ this.update();
+ }
+}
import { NgModule } from '@angular/core';
import { ComponentsModule } from './components/components.module';
+import { PasswordButtonDirective } from './directives/password-button.directive';
import { PipesModule } from './pipes/pipes.module';
import { AuthGuardService } from './services/auth-guard.service';
import { AuthStorageService } from './services/auth-storage.service';
ComponentsModule,
ServicesModule
],
- exports: [PipesModule, ServicesModule],
- declarations: [],
+ exports: [
+ PipesModule,
+ ServicesModule,
+ PasswordButtonDirective
+ ],
+ declarations: [
+ PasswordButtonDirective
+ ],
providers: [
AuthService,
AuthStorageService,