239 lines
6.8 KiB
TypeScript
239 lines
6.8 KiB
TypeScript
/** @file
|
|
* @author Edouard DUPIN
|
|
* @copyright 2018, Edouard DUPIN, all right reserved
|
|
* @license PROPRIETARY (see license file)
|
|
*/
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
import { SSOService, UserService } from 'common/service';
|
|
import { AdminUserService } from 'base/service';
|
|
import { checkLoginValidity, checkEmailValidity, checkPasswordValidity } from '../forgot-password/forgot-password';
|
|
|
|
@Component({
|
|
selector: 'app-sign-up',
|
|
templateUrl: './sign-up.html',
|
|
styleUrls: ['./sign-up.less'],
|
|
})
|
|
export class SignUpScene implements OnInit {
|
|
private signUpIconWrong: string = 'icon-right-not-validate';
|
|
private signUpIconWait: string = 'icon-right-load';
|
|
private signUpIconRight: string = 'icon-right-validate';
|
|
|
|
public login: string = '';
|
|
public loginOK: boolean = false;
|
|
public loginHelp: string = '';
|
|
public loginIcon: string = '';
|
|
|
|
public email: string = '';
|
|
public emailOK: boolean = false;
|
|
public emailHelp: string = '';
|
|
public emailIcon: string = '';
|
|
|
|
public password: string = '';
|
|
public passOK: boolean = false;
|
|
public passHelp: string = '';
|
|
public passIcon: string = '';
|
|
|
|
public signUpButtonDisabled: boolean = true;
|
|
public error: string = '';
|
|
|
|
public rememberMe: boolean = true;
|
|
public signUpEnable: boolean = true;
|
|
|
|
constructor(
|
|
private userService: UserService,
|
|
private router: Router,
|
|
private ssoService: SSOService,
|
|
private adminUserService: AdminUserService
|
|
) {
|
|
this.signUpEnable = false;
|
|
}
|
|
|
|
ngOnInit() {
|
|
let self = this;
|
|
this.signUpEnable = false;
|
|
this.ssoService
|
|
.checkSignUpEnable()
|
|
.then((value: boolean) => {
|
|
console.log(`Get value signUp = ${value}`);
|
|
self.signUpEnable = value;
|
|
})
|
|
.catch((error: any) => {
|
|
self.error = `Can not call the sso to check the sign-up_interface: ${error}`;
|
|
});
|
|
}
|
|
|
|
updateButtonVisibility(): void {
|
|
if (this.loginOK === true && this.passOK === true && this.emailOK === true) {
|
|
this.signUpButtonDisabled = false;
|
|
} else {
|
|
this.signUpButtonDisabled = true;
|
|
}
|
|
this.error = '';
|
|
}
|
|
checkLogin(newValue: string): void {
|
|
// this.userService.loginSha("loooogin", "ekljkj", true);
|
|
this.login = newValue;
|
|
if (this.login === null || this.login.length === 0) {
|
|
this.loginOK = false;
|
|
this.loginIcon = '';
|
|
//this.loginIcon = this.signUpIconWrong;
|
|
this.loginHelp = '';
|
|
this.updateButtonVisibility();
|
|
return;
|
|
}
|
|
if (this.login.length < 6) {
|
|
this.loginOK = false;
|
|
this.loginHelp = 'Need 6 characters';
|
|
this.loginIcon = this.signUpIconWrong;
|
|
this.updateButtonVisibility();
|
|
return;
|
|
}
|
|
if (checkLoginValidity(this.login) === true) {
|
|
this.loginOK = false;
|
|
// this.loginHelp = "check in progress...";
|
|
this.loginIcon = this.signUpIconWait;
|
|
let self = this;
|
|
this.adminUserService
|
|
.checkLogin(this.login)
|
|
.then((isNotUsed: boolean) => {
|
|
// check if the answer is correct with the question
|
|
if (newValue !== self.login) {
|
|
return;
|
|
}
|
|
if (isNotUsed === false) {
|
|
// the login exist ... ==> it is found...
|
|
self.loginOK = false;
|
|
self.loginHelp = 'Login already used ...';
|
|
self.loginIcon = self.signUpIconWrong;
|
|
self.updateButtonVisibility();
|
|
} else {
|
|
self.loginOK = true;
|
|
self.loginHelp = '';
|
|
self.loginIcon = self.signUpIconRight;
|
|
self.updateButtonVisibility();
|
|
return;
|
|
}
|
|
})
|
|
.catch((error: number) => {
|
|
console.log(`Status ${error}`);
|
|
self.loginOK = false;
|
|
self.loginHelp = 'ErrorOccured in fetching data ...';
|
|
self.loginIcon = self.signUpIconWrong;
|
|
self.updateButtonVisibility();
|
|
});
|
|
} else {
|
|
this.loginOK = false;
|
|
this.loginHelp = 'Not valid: characters, numbers and "_-."';
|
|
}
|
|
this.updateButtonVisibility();
|
|
}
|
|
|
|
checkEmail(newValue: string): void {
|
|
this.email = newValue;
|
|
if (this.email === null || this.email.length === 0) {
|
|
this.emailOK = false;
|
|
this.updateButtonVisibility();
|
|
this.emailIcon = '';
|
|
this.emailHelp = '';
|
|
return;
|
|
}
|
|
if (this.email.length < 6) {
|
|
this.emailOK = false;
|
|
this.emailHelp = 'Need 6 characters';
|
|
this.updateButtonVisibility();
|
|
this.passIcon = '';
|
|
this.emailIcon = this.signUpIconWrong;
|
|
return;
|
|
}
|
|
if (checkEmailValidity(this.email) === true) {
|
|
this.emailOK = false;
|
|
this.emailHelp = '';
|
|
// this.loginHelp = "check in progress...";
|
|
this.emailIcon = this.signUpIconWait;
|
|
let self = this;
|
|
this.adminUserService.checkEMail(this.email).then(
|
|
(isNotUsed: boolean) => {
|
|
// check if the answer is correct with the question
|
|
if (newValue !== self.email) {
|
|
return;
|
|
}
|
|
if (isNotUsed === false) {
|
|
// the email exist ... ==> it is found...
|
|
self.emailOK = false;
|
|
self.emailHelp = 'email already used ...';
|
|
self.emailIcon = self.signUpIconWrong;
|
|
self.updateButtonVisibility();
|
|
} else {
|
|
self.emailOK = true;
|
|
self.emailHelp = '';
|
|
self.emailIcon = self.signUpIconRight;
|
|
self.updateButtonVisibility();
|
|
return;
|
|
}
|
|
},
|
|
(error: number) => {
|
|
console.log(`Status ${error}`);
|
|
self.emailOK = false;
|
|
self.emailHelp = 'ErrorOccured in fetching data ...';
|
|
self.emailIcon = self.signUpIconWrong;
|
|
self.updateButtonVisibility();
|
|
}
|
|
);
|
|
} else {
|
|
this.emailOK = false;
|
|
this.emailHelp = 'Not valid: characters, numbers, "_-." and email format: you@example.com';
|
|
}
|
|
this.updateButtonVisibility();
|
|
}
|
|
|
|
checkPassword(newValue: string): void {
|
|
this.password = newValue;
|
|
//console.log(`ooooooooooooooo ${ this.password}`);
|
|
if (this.password === null) {
|
|
this.passOK = false;
|
|
this.passHelp = '';
|
|
this.updateButtonVisibility();
|
|
return;
|
|
}
|
|
if (this.password.length < 6) {
|
|
this.passOK = false;
|
|
this.passHelp = 'Need 6 characters';
|
|
} else if (checkPasswordValidity(this.password) === true) {
|
|
this.passOK = true;
|
|
this.passHelp = '';
|
|
} else {
|
|
this.passOK = false;
|
|
this.passHelp = 'Not valid: characters, numbers and "_-:;.,?!*+=}{([|)]% @&~#/\\<>"';
|
|
}
|
|
this.updateButtonVisibility();
|
|
}
|
|
onSignUp(): void {
|
|
console.log('Validate ... ');
|
|
if (this.signUpButtonDisabled === true) {
|
|
// ... notify user ...
|
|
console.log('Not permited action ... ==> control does not validate this action ...');
|
|
return;
|
|
}
|
|
let self = this;
|
|
// disable the currect button
|
|
this.signUpButtonDisabled = true;
|
|
this.userService.create(this.login, this.email, this.password).then(
|
|
value => {
|
|
console.log('User created');
|
|
self.router.navigate(['login']);
|
|
// send a generic message in the pop-up enevts... self.emailHelp = "email already used ... (error 2)";
|
|
},
|
|
value => {
|
|
console.log('User NOT created');
|
|
// send a generic message in the pop-up enevts... self.emailHelp = "email already used ... (error 2)";
|
|
}
|
|
);
|
|
}
|
|
onCancel(): void {
|
|
console.log(`onCancel ... '${this.login}':'${this.password}'`);
|
|
// $rootScope.currentModal = "";
|
|
}
|
|
}
|