66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
import { NativeLoginService } from '../../services/login/native-login.service';
|
|
import { TokenService, TokenProvider } from '../../services/login/token.service';
|
|
import {Router} from '@angular/router';
|
|
|
|
import '../../../assets/custom.js';
|
|
declare function simple_notifier(type: string, title: string, message:string): any;
|
|
|
|
@Component({
|
|
selector: 'app-main-sign-in',
|
|
templateUrl: './main-sign-in.component.html',
|
|
styleUrls: ['./main-sign-in.component.css']
|
|
})
|
|
export class MainSignInComponent implements OnInit {
|
|
|
|
|
|
nativeLoginForm : any;
|
|
|
|
creds : any = {"username":"","password":""};
|
|
|
|
|
|
constructor( private fb: FormBuilder, private nativeLogin : NativeLoginService, private tokenService : TokenService, private router : Router) {
|
|
|
|
}
|
|
|
|
|
|
createProjectEditorForm(){
|
|
|
|
this.nativeLoginForm = this.fb.group({
|
|
username: ['', Validators.required ],
|
|
password: ['', Validators.required ]
|
|
});
|
|
|
|
}
|
|
|
|
|
|
ngOnInit() {
|
|
this.createProjectEditorForm();
|
|
//debugger;
|
|
if(this.tokenService.isLoggedIn()){
|
|
this.router.navigate(['/welcome'], { queryParams: { /*returnUrl: this.state.url*/ }});
|
|
}
|
|
}
|
|
|
|
|
|
login(){
|
|
//login using the credentials
|
|
|
|
this.nativeLogin.login(this.creds.username, this.creds.password).subscribe(
|
|
response => {
|
|
|
|
simple_notifier("success",null,"Successful login");
|
|
|
|
this.tokenService.login(response['token'], TokenProvider.native, this.creds.username, response['email']);
|
|
this.router.navigate(['/welcome'], { queryParams: { /*returnUrl: this.state.url*/ }});
|
|
},
|
|
err => {
|
|
simple_notifier("danger",null,"Failed to login");
|
|
}
|
|
);
|
|
|
|
}
|
|
|
|
}
|