This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import {Http, Headers} from '@angular/http'; | |
import 'rxjs/add/operator/map'; | |
@Injectable() | |
export class AuthService { | |
authToken: any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {AuthService} from '../../services/auth.service'; | |
import {Router} from '@angular/router'; | |
onRegisterSubmit(){ | |
// Required Fields | |
// Required Fields for email | |
// Register user | |
this.authService.registerUser(user).subscribe(data => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2 class="page-header">Login</h2> | |
<form (submit) = "onLoginSubmit()"> | |
<div class="form-group"> | |
<label>Username</label> | |
<input type="text" class="form-control" [(ngModel)] = "username" name="username"> | |
</div> | |
<div class="form-group"> | |
<label>Password</label> | |
<input type="password" class="form-control" [(ngModel)] = "password" name="password" > |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import {AuthService} from '../../services/auth.service'; | |
import {Router} from '@angular/router'; | |
import {FlashMessagesService} from 'angular2-flash-messages'; | |
@Component({ | |
selector: 'app-login', | |
templateUrl: './login.component.html', | |
styleUrls: ['./login.component.css'] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// register user function | |
// function for authenticate user | |
authenticateUser(user){ | |
let headers = new Headers(); | |
headers.append('Content-Type', 'application/json'); | |
return this.http.post('http://localhost:9090/users/authenticate', user, {headers: headers}).map(res => res.json()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onLoginSubmit(){ | |
//console.log(this.username); | |
const user = { | |
username: this.username, | |
password: this.password | |
} | |
this.authService.authenticateUser(user).subscribe(data => { | |
//console.log(data); | |
if(data.success){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function to register user | |
// function for authenticate user | |
// function to store user data (token) | |
storeUserData(token, user){ | |
localStorage.setItem('id_token', token); | |
localStorage.setItem('user', JSON.stringify(user)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function for authenticate user | |
// function to get profile | |
getProfile(){ | |
let headers = new Headers(); | |
this.loadToken(); | |
headers.append('Authorization', this.authToken); | |
headers.append('Content-Type', 'application/json'); | |
return this.http.get('http://localhost:9090/users/profile', {headers: headers}).map(res => res.json()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import {AuthService} from '../../services/auth.service'; | |
import {Router} from '@angular/router'; | |
@Component({ | |
selector: 'app-profile', | |
templateUrl: './profile.component.html', | |
styleUrls: ['./profile.component.css'] | |
}) | |
export class ProfileComponent implements OnInit { |
OlderNewer