Login Functionality added (accepted credentials: username=sba password=12345678)
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44972 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
c1699f317d
commit
79b54ca975
|
@ -1,14 +0,0 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
|
||||
import { LoginComponent } from './login.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forChild([
|
||||
{ path: 'login', component: LoginComponent }
|
||||
|
||||
])
|
||||
]
|
||||
})
|
||||
export class LoginRoutingModule { }
|
|
@ -1,100 +0,0 @@
|
|||
// import { Component } from '@angular/core';
|
||||
// import { Router } from '@angular/router';
|
||||
// import { Http } from '@angular/http';
|
||||
// // import { contentHeaders } from '../../common/headers';
|
||||
//
|
||||
// // const styles = require('./login.css');
|
||||
// // const template = require('./login.html');
|
||||
//
|
||||
// @Component({
|
||||
// selector: 'login',
|
||||
// template: template,
|
||||
// styles: [ styles ]
|
||||
// })
|
||||
// export class Login {
|
||||
// constructor(public router: Router, public http: Http) {
|
||||
// }
|
||||
//
|
||||
// login(event, username, password) {
|
||||
// event.preventDefault();
|
||||
// let body = JSON.stringify({ username, password });
|
||||
// localStorage.setItem('id_token',"test");
|
||||
// // this.http.post('http://localhost:3001/sessions/create', body, { headers: contentHeaders })
|
||||
// // .subscribe(
|
||||
// // response => {
|
||||
// // localStorage.setItem('id_token', response.json().id_token);
|
||||
// // this.router.navigate(['home']);
|
||||
// // },
|
||||
// // error => {
|
||||
// // alert(error.text());
|
||||
// // console.log(error.text());
|
||||
// // }
|
||||
// // );
|
||||
// }
|
||||
//
|
||||
// signup(event) {
|
||||
// event.preventDefault();
|
||||
// this.router.navigate(['signup']);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
import {Component, ElementRef, Input} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {LoginService} from '../services/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'login',
|
||||
template: `
|
||||
<div class="container" >
|
||||
<div>
|
||||
Welcome in Login
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<!--div class="row">
|
||||
<div class="input-group">
|
||||
<input [(ngModel)]="email" name="email" type="email">
|
||||
<label for="email">Email</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="input-group">
|
||||
<input [(ngModel)]="password" type="password">
|
||||
<label for="password">Password</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form class = "search-form">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" placeholder="Type keywords..." aria-describedby="sizing-addon2" [(ngModel)]="keyword" name="keyword" >
|
||||
</div>
|
||||
</form-->
|
||||
|
||||
<button (click)="login()"
|
||||
type="submit">Login Button
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
|
||||
export class LoginComponent {
|
||||
|
||||
@Input() email: string = "sba";
|
||||
@Input() password: string = "12345678";
|
||||
|
||||
constructor( private _loginService: LoginService ) {}
|
||||
|
||||
login() {
|
||||
this._loginService.authenticate(this.email, this.password).subscribe(
|
||||
data => {
|
||||
console.info(data);
|
||||
},
|
||||
err => {
|
||||
console.log(err);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
import { NgModule} from '@angular/core';
|
||||
//import { CommonModule } from '@angular/common';
|
||||
//import { FormsModule } from '@angular/forms';
|
||||
|
||||
//import {UtilsModule} from '../utils/utils.module';
|
||||
//import {ClaimModule} from '../claimPages/claim.module';
|
||||
import {ServicesModule} from '../services/services.module';
|
||||
|
||||
//import {SearchModule} from '../searchPages/search.module';
|
||||
|
||||
import {LoginComponent} from './login.component';
|
||||
|
||||
|
||||
import {LoginRoutingModule} from './login-routing.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
//CommonModule, FormsModule,
|
||||
//UtilsModule,
|
||||
//ClaimModule,
|
||||
ServicesModule,
|
||||
LoginRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
LoginComponent
|
||||
],
|
||||
providers:[
|
||||
],
|
||||
exports: [
|
||||
LoginComponent
|
||||
]
|
||||
})
|
||||
export class LoginModule { }
|
|
@ -7,24 +7,36 @@ import 'rxjs/add/operator/share';
|
|||
|
||||
import { CacheService } from '../shared/cache.service';
|
||||
import {PersonInfo} from '../utils/entities/personInfo';
|
||||
import {OpenaireProperties} from '../utils/properties/openaireProperties'
|
||||
import {OpenaireProperties} from '../utils/properties/openaireProperties';
|
||||
import {User} from '../utils/entities/user';
|
||||
|
||||
@Injectable()
|
||||
export class LoginService {
|
||||
|
||||
constructor(private http: Http, public _cache: CacheService) {}
|
||||
|
||||
authenticate (email: string, password: string):any {
|
||||
authenticate (user: User):any {
|
||||
|
||||
let url = OpenaireProperties.getLoginAPIURL()+email+"&password="+password;
|
||||
let url = OpenaireProperties.getLoginAPIURL()+user.username+"&password="+user.password;
|
||||
let key = url;
|
||||
if (this._cache.has(key)) {
|
||||
return Observable.of(this._cache.get(key));
|
||||
}
|
||||
return this.http.get(url)
|
||||
.map(res => <any> res.json())
|
||||
.map(res => this.parseUserInfo(res['data'], user))
|
||||
.do(res => {
|
||||
this._cache.set(key, res);
|
||||
});
|
||||
}
|
||||
|
||||
private parseUserInfo(data: any, user: User): User {
|
||||
user.email = data.email;
|
||||
user.id = data.id;
|
||||
user.fullname = data.fullname;
|
||||
|
||||
localStorage.setItem("user", JSON.stringify(user));
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
import {Component, ElementRef} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {LoginService} from '../services/login.service';
|
||||
import {User} from '../utils/entities/user';
|
||||
|
||||
@Component({
|
||||
selector: 'login',
|
||||
template: `
|
||||
<div class="container-fluid">
|
||||
<div *ngIf="!loggedIn">
|
||||
<div *ngIf="errorMessage.length > 0" class="alert alert-danger" role="alert">
|
||||
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
|
||||
{{errorMessage}}
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="input-group">
|
||||
<label>Username:</label>
|
||||
<input [(ngModel)]="user.username" type="username">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="input-group">
|
||||
<label for="password">Password:</label>
|
||||
<input [(ngModel)]="user.password" type="password">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="btn" (click)="login()"
|
||||
type="submit">Login
|
||||
</button>
|
||||
</div>
|
||||
<div *ngIf="loggedIn">
|
||||
Hello {{user.fullname}}!
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
|
||||
export class LoginComponent {
|
||||
public user: User;
|
||||
private loggedIn: boolean;
|
||||
private errorMessage: string;
|
||||
|
||||
constructor( private _loginService: LoginService ) {}
|
||||
|
||||
ngOnInit() {
|
||||
if( typeof localStorage !== 'undefined') {
|
||||
if(localStorage.getItem("user")) {
|
||||
this.user = JSON.parse(localStorage.getItem("user"));
|
||||
this.loggedIn = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.loggedIn == undefined) {
|
||||
this.user = new User();
|
||||
this.loggedIn = false;
|
||||
}
|
||||
this.errorMessage = "";
|
||||
}
|
||||
|
||||
login() {
|
||||
this._loginService.authenticate(this.user).subscribe(
|
||||
data => {
|
||||
this.loggedIn = true;
|
||||
},
|
||||
err => {
|
||||
console.log(err);
|
||||
if(err.status == "404") {
|
||||
this.errorMessage = "Wrong username";
|
||||
} else if(err.status == "401") {
|
||||
this.errorMessage = "Wrong password";
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ import 'rxjs/Rx';
|
|||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Search <span class=""></span></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="/search/find/publications">Publications</a></li>
|
||||
<li><a href="/search/find/datasets">Datasets</a></li>
|
||||
<li><a href="/search/find/datasets">Research Data</a></li>
|
||||
<li><a href="/search/find/projects">Projects</a></li>
|
||||
<li><a href="/search/find/dataproviders">Data Providers</a></li>
|
||||
<li><a href="/search/find/organizations">Organizations</a></li>
|
||||
|
|
|
@ -5,6 +5,7 @@ import { FormsModule } from '@angular/forms';
|
|||
import { RouterModule } from "@angular/router";
|
||||
|
||||
import {NavigationBarComponent} from './navigationBar.component';
|
||||
import {LoginComponent} from './login.component';
|
||||
|
||||
|
||||
@NgModule({
|
||||
|
@ -14,12 +15,11 @@ import {NavigationBarComponent} from './navigationBar.component';
|
|||
],
|
||||
declarations: [
|
||||
NavigationBarComponent,
|
||||
|
||||
|
||||
LoginComponent
|
||||
],
|
||||
exports: [
|
||||
NavigationBarComponent
|
||||
|
||||
NavigationBarComponent,
|
||||
LoginComponent
|
||||
]
|
||||
})
|
||||
export class SharedComponentsModule{ }
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
export class User {
|
||||
password:string;
|
||||
email:string;
|
||||
username: string;
|
||||
id: string;
|
||||
fullname: string;
|
||||
}
|
|
@ -40,7 +40,7 @@ export class OpenaireProperties {
|
|||
// private searchAPIURL = "http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2.0/api/";
|
||||
// private static searchAPIURL = "http://scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/";
|
||||
|
||||
private static searchAPIURLLAst = "http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
|
||||
private static searchAPIURLLAst = "http://scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/"
|
||||
|
||||
// private static searchAPIURLLAst = "http://scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT-new/rest/v2/api/";
|
||||
|
||||
|
|
Loading…
Reference in New Issue