minor changes
This commit is contained in:
parent
b551221222
commit
f29f2e7af3
|
@ -11,7 +11,6 @@ import { ReactiveFormsModule } from '@angular/forms';
|
|||
import { ContextMenuModule } from 'ngx-contextmenu';
|
||||
import { Ng2Webstorage } from 'ngx-webstorage';
|
||||
|
||||
import { AuthInterceptor } from './services/interceptors/auth-interceptor';
|
||||
import { RestBase } from './services/rest-base';
|
||||
import { TokenService } from './services/login/token.service';
|
||||
import { NativeLoginService } from './services/login/native-login.service';
|
||||
|
|
|
@ -41,15 +41,15 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let dataset of mf.data" class="hover">
|
||||
<td [ngClass]="{true:'visible', false:'invisible'}[showIDs]">{{dataset.id}}</td>
|
||||
<td [ngClass]="{true:'visible', false:'invisible'}[showIDs]">{{dataset?.id}}</td>
|
||||
<td><input class="noborder" type="text" [(ngModel)]="dataset.label" (focusin)="onFocusIn($event)" (ngModelChange)="onValueChanged($event)" (focusout)="onFocusOutLabel($event)"></td>
|
||||
<td>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-primary dropdown-toggle dmp-btn-width" type="button" data-toggle="dropdown">{{dataset.dmp.label}}
|
||||
<button class="btn btn-primary dropdown-toggle dmp-btn-width" type="button" data-toggle="dropdown">{{dataset?.dmp?.label}}
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" >
|
||||
<li class="margined" *ngFor="let idLabel of dmpsIDLabels" (click)="assignDMPToDataset($event, idLabel.id)"><a style="cursor:pointer;">{{idLabel.label}}</a></li>
|
||||
<li class="margined" *ngFor="let idLabel of dmpsIDLabels" (click)="assignDMPToDataset($event, idLabel.id)"><a style="cursor:pointer;">{{idLabel?.label}}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
@ -18,7 +18,7 @@ export class NativeLoginService implements OnInit {
|
|||
|
||||
login(username, password){
|
||||
var credentials = {"username": username, "password":password};
|
||||
return this.restBase.post("project/create", credentials);
|
||||
return this.restBase.post("nativeLogin", credentials);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,16 +1,29 @@
|
|||
import { Injectable, } from '@angular/core';
|
||||
import { Injectable, Inject} from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import {LocalStorageService} from 'ngx-webstorage';
|
||||
import 'rxjs/add/operator/map';
|
||||
import { DOCUMENT } from '@angular/platform-browser';
|
||||
|
||||
declare var jQuery : any;
|
||||
|
||||
@Injectable()
|
||||
export class TokenService {
|
||||
|
||||
|
||||
constructor (private storage : LocalStorageService) {
|
||||
|
||||
constructor (private storage : LocalStorageService, @Inject(DOCUMENT) private document) {
|
||||
var csrfToken : string = jQuery(document).find('meta[name="csrf-token"]').attr('content');
|
||||
this.setCSRFToken(csrfToken);
|
||||
}
|
||||
|
||||
|
||||
getCSRFToken() : string{
|
||||
return this.storage.retrieve('csrf-token');
|
||||
}
|
||||
|
||||
setCSRFToken(csrfToken : string){
|
||||
this.storage.store('csrf-token',csrfToken);
|
||||
}
|
||||
|
||||
|
||||
getProvider() : TokenProvider {
|
||||
return this.storage.retrieve('provider');
|
||||
|
|
|
@ -41,12 +41,14 @@ export class RestBase {
|
|||
private createOptions(){
|
||||
var token = this.tokenService.getToken();
|
||||
var provider: TokenProvider = this.tokenService.getProvider();
|
||||
var csrfToken : string = this.tokenService.getCSRFToken();
|
||||
|
||||
const params = new HttpParams();
|
||||
var headers;
|
||||
var headers;
|
||||
if(provider == TokenProvider.google)
|
||||
headers = new HttpHeaders().set('Content-Type', 'application/json').set("google-token", token);
|
||||
if(provider == TokenProvider.google)
|
||||
headers = new HttpHeaders().set('Content-Type', 'application/json').set("google-token", token);
|
||||
headers = new HttpHeaders().set('Content-Type', 'application/json').set('X-CSRF-Token', csrfToken).set("google-token", token);
|
||||
if(provider == TokenProvider.native)
|
||||
headers = new HttpHeaders().set('Content-Type', 'application/json').set('X-CSRF-Token', csrfToken).set("native-token", token);
|
||||
let options = { params: params, headers: headers };
|
||||
return options;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>DmpAdmin</title>
|
||||
<base href="/">
|
||||
<meta name="csrf-token" content="2c64def7de30197c40276fe1a7ea874ca8871f70be7d7dc3305465a4d5c565e4">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
|
||||
|
|
|
@ -5366,6 +5366,11 @@
|
|||
"integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=",
|
||||
"dev": true
|
||||
},
|
||||
"ngx-webstorage": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/ngx-webstorage/-/ngx-webstorage-1.8.0.tgz",
|
||||
"integrity": "sha1-zQhbmPvHpyzI8qqkDGyASzjUVt4="
|
||||
},
|
||||
"no-case": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/no-case/-/no-case-2.3.1.tgz",
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"bootstrap": "^3.3.7",
|
||||
"core-js": "^2.4.1",
|
||||
"jquery": "^3.2.1",
|
||||
"ngx-webstorage": "^1.8.0",
|
||||
"rxjs": "^5.4.2",
|
||||
"zone.js": "^0.8.17"
|
||||
},
|
||||
|
|
|
@ -9,6 +9,7 @@ import { AppComponent } from './app.component';
|
|||
import { DynamicFormComponent } from './form/dynamic-form.component';
|
||||
import { DynamicFormFieldComponent } from './form/fields/dynamic-form-field.component';
|
||||
import { ServerService } from './services/server.service';
|
||||
import { TokenService, TokenProvider } from './services/token.service';
|
||||
import { dataModelBuilder } from './services/dataModelBuilder.service';
|
||||
import { DynamicFormGroupComponent } from './form/dynamic-form-group/dynamic-form-group.component';
|
||||
import { LoginComponent } from './login/login-page';
|
||||
|
@ -41,7 +42,7 @@ import { PaginationService } from './services/pagination.service';
|
|||
AppRoutingModule
|
||||
|
||||
],
|
||||
providers: [ServerService, dataModelBuilder, AuthGuard, PaginationService],
|
||||
providers: [ServerService, dataModelBuilder, AuthGuard, PaginationService, TokenService],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Component, OnInit, NgZone } from '@angular/core';
|
||||
import {GoogleSignInSuccess} from 'angular-google-signin';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { TokenService, TokenProvider } from '../services/token.service';
|
||||
|
||||
@Component({
|
||||
selector: 'login-page',
|
||||
|
@ -9,12 +10,14 @@ import { Router, ActivatedRoute } from '@angular/router';
|
|||
})
|
||||
export class LoginComponent implements OnInit{
|
||||
returnUrl: string;
|
||||
public static token : string;
|
||||
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private ngZone: NgZone){
|
||||
private ngZone: NgZone,
|
||||
private tokenService : TokenService
|
||||
){
|
||||
|
||||
}
|
||||
|
||||
|
@ -31,13 +34,29 @@ export class LoginComponent implements OnInit{
|
|||
let googleUser: gapi.auth2.GoogleUser = event.googleUser;
|
||||
let id: string = googleUser.getId();
|
||||
let profile: gapi.auth2.BasicProfile = googleUser.getBasicProfile();
|
||||
LoginComponent.token = googleUser.getAuthResponse().id_token;
|
||||
this.tokenService.setToken(googleUser.getAuthResponse().id_token);
|
||||
|
||||
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
|
||||
console.log('Name: ' + profile.getName());
|
||||
console.log('token: ' + LoginComponent.token);
|
||||
console.log('token: ' + this.tokenService.getToken());
|
||||
|
||||
this.tokenService.setProvider(TokenProvider.google);
|
||||
this.tokenService.setLoggedIn(true);
|
||||
this.tokenService.setEmail(profile.getEmail());
|
||||
this.tokenService.setUsername(); //GEMISE AYTO...
|
||||
|
||||
/* AYTA FEYGOUN, xanontai me to refresh tis selidas
|
||||
|
||||
localStorage.setItem('currentUser', JSON.stringify(googleUser));
|
||||
var currentUser = JSON.parse(localStorage.getItem('currentUser'));
|
||||
console.log('current user local storage:' +currentUser)
|
||||
*/
|
||||
|
||||
// STO LOGOUT, KATHARIZEIS TO tokenService (apo opoudipote... e;inai apo pantou prosvasimo, kai den xanei tis times toy oso exeis to browser anoixto.)
|
||||
|
||||
|
||||
|
||||
|
||||
//this.router.navigateByUrl('dynamic-form');
|
||||
this.ngZone.run(() => this.router.navigateByUrl('projects'));
|
||||
//this.router.navigate(['/projects']);
|
||||
|
|
|
@ -46,6 +46,8 @@ export class ServerService {
|
|||
//let headers = new HttpHeaders();
|
||||
let headers = new HttpHeaders().set("google-token", LoginComponent.token);
|
||||
|
||||
console.log("google-token: "+ LoginComponent.token);
|
||||
|
||||
return this.http.get(this.fetchURL)
|
||||
.map(
|
||||
(response: Response) => {
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
import { Injectable, Inject} from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import {LocalStorageService} from 'ngx-webstorage';
|
||||
import 'rxjs/add/operator/map';
|
||||
import { DOCUMENT } from '@angular/platform-browser';
|
||||
|
||||
declare var jQuery : any;
|
||||
|
||||
@Injectable()
|
||||
export class TokenService {
|
||||
|
||||
|
||||
constructor (private storage : LocalStorageService, @Inject(DOCUMENT) private document) {
|
||||
var csrfToken : string = jQuery(document).find('meta[name="csrf-token"]').attr('content');
|
||||
this.setCSRFToken(csrfToken);
|
||||
}
|
||||
|
||||
|
||||
getCSRFToken() : string{
|
||||
return this.storage.retrieve('csrf-token');
|
||||
}
|
||||
|
||||
setCSRFToken(csrfToken : string){
|
||||
this.storage.store('csrf-token',csrfToken);
|
||||
}
|
||||
|
||||
|
||||
getProvider() : TokenProvider {
|
||||
return this.storage.retrieve('provider');
|
||||
}
|
||||
|
||||
setProvider(provider : TokenProvider){
|
||||
this.storage.store('provider',provider);
|
||||
}
|
||||
|
||||
getToken() : string{
|
||||
return this.storage.retrieve('token');
|
||||
}
|
||||
|
||||
setToken(token : string){
|
||||
this.storage.store('token',token);
|
||||
}
|
||||
|
||||
isLoggedIn(){
|
||||
return this.storage.retrieve('loggedIn');
|
||||
}
|
||||
|
||||
setLoggedIn(boolStatus){
|
||||
this.storage.store('loggedIn',boolStatus);
|
||||
}
|
||||
|
||||
getEmail(){
|
||||
return this.storage.retrieve('email');
|
||||
}
|
||||
|
||||
setEmail(email){
|
||||
this.storage.store('email',email);
|
||||
}
|
||||
|
||||
getUsername(){
|
||||
return this.storage.retrieve('username');
|
||||
}
|
||||
|
||||
setUsername(username){
|
||||
this.storage.store('username',username);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export enum TokenProvider {
|
||||
native,
|
||||
google
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue