Skip to content
Permalink
06ac7bc75c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
60 lines (51 sloc) 1.8 KB
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { LoginService } from '../services/login.service';
import { Router } from '@angular/router';
import { ErrorHandler } from '@angular/core';
@Injectable()
@Component({
selector: 'app-authentication',
templateUrl: './authentication.component.html',
styleUrls: ['./authentication.component.css']
})
export class AuthenticationComponent implements OnInit {
// private items: Array<string>;
@ViewChild('email_input') email_input: ElementRef;
@ViewChild('password_input') password_input: ElementRef;
content = null;
constructor(private data: LoginService, private router: Router, private handleError: ErrorHandler) {
}
logOn () {
const loginjson = {
'user_email': this.email_input.nativeElement.value,
'user_password': this.password_input.nativeElement.value
};
const errMessage = document.getElementById('peep');
errMessage.innerHTML = '';
try {
this.data.authorizeUser(loginjson).subscribe((data) => {
const token = data['token'];
const message = data['message'];
if (message === 'Authorized') {
// Authorized
localStorage.setItem('auth_token', token);
this.router.navigateByUrl('/generator-search');
// console.log(token);
}
});
} catch (err) {
// document.getElementById("loginForm").reset();
errMessage.innerHTML = err.message;
}
}
ngOnInit() {
localStorage.removeItem('gen_id');
localStorage.removeItem('org_id');
localStorage.removeItem('gen_name');
localStorage.removeItem('data_type');
localStorage.removeItem('fault_type');
// localStorage.removeItem('auth_token');
}
}