Skip to content
Permalink
9124e60009
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
55 lines (44 sloc) 1.45 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';
@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;
constructor(private data: LoginService, private router: Router) {
}
logOn () {
const loginjson = {
'user_email': this.email_input.nativeElement.value,
'user_password': this.password_input.nativeElement.value
};
this.data.authorizeUser(loginjson).subscribe((data) => {
if (data) {
const token = data['token'];
const message = data['message'];
if (message === 'Authorized') {
// Authorized
// console.log(token);
localStorage.setItem('auth_token', token);
this.router.navigateByUrl('/generator-search');
}
} else {
document.getElementById('peep').innerHTML = 'Username or Password is Invalid';
}
});
}
/*
this.data.getUser(token).subscribe((me) => {
console.log(me);
});
*/
ngOnInit() { }
}