From 5fb2605a45cfb8bdd17cf22616155355fc46fdb0 Mon Sep 17 00:00:00 2001 From: Steven Zou Date: Mon, 27 Mar 2017 15:58:00 +0800 Subject: [PATCH] support 'remember me' and root cert downloading --- .gitignore | 3 ++ .../account/sign-in/sign-in.component.html | 2 +- .../app/account/sign-in/sign-in.component.ts | 48 ++++++++++++++++++- src/ui_ng/src/app/app-config.ts | 2 + .../base/navigator/navigator.component.html | 1 + .../app/base/navigator/navigator.component.ts | 7 +++ src/ui_ng/src/i18n/lang/en-lang.json | 3 +- src/ui_ng/src/i18n/lang/zh-lang.json | 3 +- 8 files changed, 64 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 87860b72d..d28836632 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,8 @@ src/ui_ng/typings/ **/*yarn-error.log.* .idea/ .DS_Store +**/node_modules +**/ssl/ +**/proxy.config.json diff --git a/src/ui_ng/src/app/account/sign-in/sign-in.component.html b/src/ui_ng/src/app/account/sign-in/sign-in.component.html index 6244d5a6c..3cf3e4ba9 100644 --- a/src/ui_ng/src/app/account/sign-in/sign-in.component.html +++ b/src/ui_ng/src/app/account/sign-in/sign-in.component.html @@ -23,7 +23,7 @@
- + {{'SIGN_IN.FORGOT_PWD' | translate}}
diff --git a/src/ui_ng/src/app/account/sign-in/sign-in.component.ts b/src/ui_ng/src/app/account/sign-in/sign-in.component.ts index 406e76821..4ea042dd2 100644 --- a/src/ui_ng/src/app/account/sign-in/sign-in.component.ts +++ b/src/ui_ng/src/app/account/sign-in/sign-in.component.ts @@ -14,10 +14,14 @@ import { AppConfigService } from '../../app-config.service'; import { AppConfig } from '../../app-config'; import { User } from '../../user/user'; +import { CookieService, CookieOptions } from 'angular2-cookie/core'; + //Define status flags for signing in states export const signInStatusNormal = 0; export const signInStatusOnGoing = 1; export const signInStatusError = -1; +const remCookieKey = "rem-username"; +const expireDays = 10; @Component({ selector: 'sign-in', @@ -28,6 +32,9 @@ export const signInStatusError = -1; export class SignInComponent implements AfterViewChecked, OnInit { private redirectUrl: string = ""; private appConfig: AppConfig = new AppConfig(); + //Remeber me indicator + private rememberMe: boolean = false; + private rememberedName: string = ""; //Form reference signInForm: NgForm; @ViewChild('signInForm') currentForm: NgForm; @@ -47,13 +54,14 @@ export class SignInComponent implements AfterViewChecked, OnInit { private router: Router, private session: SessionService, private route: ActivatedRoute, - private appConfigService: AppConfigService + private appConfigService: AppConfigService, + private cookie: CookieService ) { } ngOnInit(): void { //Make sure the updated configuration can be loaded this.appConfigService.load() - .then(updatedConfig => this.appConfig = updatedConfig); + .then(updatedConfig => this.appConfig = updatedConfig); this.route.queryParams .subscribe(params => { this.redirectUrl = params["redirect_url"] || ""; @@ -62,6 +70,14 @@ export class SignInComponent implements AfterViewChecked, OnInit { this.signUp();//Open sign up } }); + + let remUsername = this.cookie.get(remCookieKey); + remUsername = remUsername ? remUsername.trim() : ""; + if (remUsername) { + this.signInCredential.principal = remUsername; + this.rememberMe = true; + this.rememberedName = remUsername; + } } //For template accessing @@ -84,6 +100,31 @@ export class SignInComponent implements AfterViewChecked, OnInit { && this.appConfig.self_registration; } + private clickRememberMe($event): void { + if ($event && $event.target) { + this.rememberMe = $event.target.checked; + if (!this.rememberMe) { + //Remove cookie data + this.cookie.remove(remCookieKey); + this.rememberedName = ""; + } + } + } + + private remeberMe(): void { + if (this.rememberMe) { + if (this.rememberedName != this.signInCredential.principal) { + //Set expire time + let expires: number = expireDays * 3600 * 24 * 1000; + let date = new Date(Date.now() + expires); + let cookieptions = new CookieOptions({ + expires: date + }); + this.cookie.put(remCookieKey, this.signInCredential.principal, cookieptions); + } + } + } + //General error handler private handleError(error) { //Set error status @@ -150,6 +191,9 @@ export class SignInComponent implements AfterViewChecked, OnInit { //Set status this.signInStatus = signInStatusNormal; + //Remeber me + this.remeberMe(); + //Redirect to the right route if (this.redirectUrl === "") { //Routing to the default location diff --git a/src/ui_ng/src/app/app-config.ts b/src/ui_ng/src/app/app-config.ts index 80bf3f61c..5715716a6 100644 --- a/src/ui_ng/src/app/app-config.ts +++ b/src/ui_ng/src/app/app-config.ts @@ -8,6 +8,7 @@ export class AppConfig { this.registry_url = ""; this.project_creation_restriction = "everyone"; this.self_registration = true; + this.has_ca_root = false; } with_notary: boolean; @@ -17,4 +18,5 @@ export class AppConfig { registry_url: string; project_creation_restriction: string; self_registration: boolean; + has_ca_root: boolean; } \ No newline at end of file diff --git a/src/ui_ng/src/app/base/navigator/navigator.component.html b/src/ui_ng/src/app/base/navigator/navigator.component.html index 46db50d5e..1fbeb6c59 100644 --- a/src/ui_ng/src/app/base/navigator/navigator.component.html +++ b/src/ui_ng/src/app/base/navigator/navigator.component.html @@ -31,6 +31,7 @@