sign in gmail and routing

This commit is contained in:
annampak 2017-09-26 18:16:04 +03:00
parent 9a545bcf24
commit 1abb322f59
14 changed files with 184 additions and 31 deletions

View File

@ -209,6 +209,19 @@
"source-map": "0.5.7"
}
},
"@types/gapi": {
"version": "0.0.35",
"resolved": "https://registry.npmjs.org/@types/gapi/-/gapi-0.0.35.tgz",
"integrity": "sha512-6E+WHil3a2+ZQXxa+2Fg9WMi1SwVx9KXT3P/7VmfTwK9Uqw2F+TQ97Ig2yJ7cOa0fUEk4qgdQNKP4rzKZfNMOQ=="
},
"@types/gapi.auth2": {
"version": "0.0.31",
"resolved": "https://registry.npmjs.org/@types/gapi.auth2/-/gapi.auth2-0.0.31.tgz",
"integrity": "sha1-P5F/mcHxjgv05HghTYME/60cXe8=",
"requires": {
"@types/gapi": "0.0.35"
}
},
"@types/jasmine": {
"version": "2.5.54",
"resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.5.54.tgz",
@ -352,6 +365,14 @@
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=",
"dev": true
},
"angular-google-signin": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/angular-google-signin/-/angular-google-signin-0.1.5.tgz",
"integrity": "sha1-VQbMWeTCRWIOsJDoOGnH9MoXUTw=",
"requires": {
"@types/gapi.auth2": "0.0.31"
}
},
"angular-ide": {
"version": "0.9.31",
"resolved": "https://registry.npmjs.org/angular-ide/-/angular-ide-0.9.31.tgz",
@ -8065,12 +8086,6 @@
"integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=",
"dev": true
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
@ -8098,6 +8113,12 @@
}
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
},
"stringstream": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",

View File

@ -21,6 +21,7 @@
"@angular/platform-browser": "^4.3.6",
"@angular/platform-browser-dynamic": "^4.3.6",
"@angular/router": "^4.3.6",
"angular-google-signin": "^0.1.5",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"jquery": "^3.2.1",

View File

@ -0,0 +1,32 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { PageNotFoundComponent } from './not-found.component';
import { DynamicFormComponent } from './form/dynamic-form.component';
import { LoginComponent } from './login/login-page';
import { AuthGuard } from './guards/auth.guard';
const appRoutes: Routes = [
{ path: 'dynamic-form.component', component: DynamicFormComponent, canActivate: [AuthGuard] },
{ path: 'login-page', component: LoginComponent },
{ path: '', redirectTo: '/login-page', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{
enableTracing: true // <-- debugging purposes only
}
)
],
exports: [
RouterModule
],
providers: [
]
})
export class AppRoutingModule { }

View File

@ -7,25 +7,19 @@ import { JsonObjest } from '../app/entities/JsonObject.class';
@Component({
selector: 'app-root',
template: `
<div>
<dynamic-form></dynamic-form>
</div>
<h1 class="title">Angular Router</h1>
<router-outlet></router-outlet>
`,
// template: `
// <div>
// <login-page></login-page>
// </div>
// `,
providers: []
})
export class AppComponent {
fields: any[];
//constructor(service: FieldService) {
//this.fields = service.getFields();
// this.serverService.getHTTPFields()
// .subscribe(
// (data:any[])=> {
// console.log(data);
// fieldService.getFieldVisibility(data);
// },
// (error) => console.log(error)
// );
//}
}
//<dynamic-form></dynamic-form>

View File

@ -3,6 +3,7 @@ import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { HttpModule } from '@angular/http';
import { RouterModule, Routes, Router } from '@angular/router';
import { AppComponent } from './app.component';
import { DynamicFormComponent } from './form/dynamic-form.component';
@ -10,23 +11,31 @@ import { DynamicFormFieldComponent } from './form/fields/dynamic-form-field.comp
import { ServerService } from './services/server.service';
import { dataModelBuilder } from './services/dataModelBuilder.service';
import { DynamicFormGroupComponent } from './form/dynamic-form-group/dynamic-form-group.component';
import { LoginComponent } from './login/login-page';
import {GoogleSignInComponent} from 'angular-google-signin';
import { AppRoutingModule } from './app-routing.module';
import { AuthGuard } from './guards/auth.guard';
import { PageNotFoundComponent } from './not-found.component';
@NgModule({
declarations: [
AppComponent,
DynamicFormComponent,
DynamicFormFieldComponent,
DynamicFormGroupComponent
DynamicFormGroupComponent,
LoginComponent,
GoogleSignInComponent,
PageNotFoundComponent
],
imports: [
BrowserModule,
ReactiveFormsModule,
FormsModule,
HttpModule,
HttpClientModule
HttpClientModule,
AppRoutingModule
],
providers: [ServerService, dataModelBuilder],
providers: [ServerService, dataModelBuilder, AuthGuard],
bootstrap: [AppComponent]
})
export class AppModule {

View File

@ -20,3 +20,5 @@
</form>
<p>Form value: {{ form.value | json }}</p>
<a href="#" onclick="signOut();">Sign out</a>

View File

@ -8,6 +8,7 @@ import { ServerService } from '../../app/services/server.service';
import { dataModelBuilder } from '../../app/services/dataModelBuilder.service';
import { DataModel } from '../entities/DataModel';
import { GroupBase } from './dynamic-form-group/group-base';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
selector: 'dynamic-form',
@ -24,9 +25,8 @@ export class DynamicFormComponent implements OnInit {
constructor(private qcs: FieldControlService, private serverService: ServerService, private dataModelService: dataModelBuilder) {
constructor(private qcs: FieldControlService, private serverService: ServerService, private dataModelService: dataModelBuilder, private router: Router, private route: ActivatedRoute) {
this.form = this.qcs.toFormGroup(new Array(), new Array());
}

View File

@ -57,7 +57,6 @@
</div>
</div>
<!-- <div [formGroup]="form" class="form-group" [ngSwitch]="field.controlType">
<div *ngIf= "field.rules; else elseBlock ">
<div *ngIf="field.rules.length > 0; else elseBlock">

View File

@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {debugger;
if (localStorage.getItem('currentUser')) {
// logged in so return true
return true;
}
// not logged in so redirect to login page with the return url
this.router.navigate(['/login-page'], { queryParams: { returnUrl: state.url }});
return false;
}
}

View File

@ -0,0 +1,17 @@
<html lang="en">
<head>
</head>
<body>
<!-- <div class="g-signin2" data-onsuccess="onSignIn"></div> -->
<div> <google-signin [clientId]="myClientId" (googleSignInSuccess)="onGoogleSignInSuccess($event)"></google-signin></div>
<!-- <a href="#" onclick="signOut();">Sign out</a> -->
</body>
</html>

View File

@ -0,0 +1,40 @@
import { Component, OnInit } from '@angular/core';
import {GoogleSignInSuccess} from 'angular-google-signin';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
selector: 'login-page',
templateUrl: './login-page.html',
providers: []
})
export class LoginComponent implements OnInit{
returnUrl: string;
constructor(
private route: ActivatedRoute,
private router: Router){
}
ngOnInit() {
// reset login status
//this.authenticationService.logout();
// get return url from route parameters or default to '/'
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
}
private myClientId: string = '524432312250-vhgidft856v8qftsc81kls4c74v87d8o.apps.googleusercontent.com';
onGoogleSignInSuccess(event: GoogleSignInSuccess) { debugger;
let googleUser: gapi.auth2.GoogleUser = event.googleUser;
let id: string = googleUser.getId();
let profile: gapi.auth2.BasicProfile = googleUser.getBasicProfile();
console.log('ID: ' +
profile
.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
localStorage.setItem('currentUser', JSON.stringify(googleUser));
this.router.navigateByUrl('dynamic-form.component');
}
}

View File

@ -0,0 +1,6 @@
import { Component } from '@angular/core';
@Component({
template: '<h2>Page not found</h2>'
})
export class PageNotFoundComponent {}

View File

@ -23,7 +23,7 @@ export class dataModelBuilder {
this.dataModel = new DataModel();
this.fields = this.buildFields(data.dataset.profile.viewstyle.definition.root.fields.field);
this.dataModel.groups = this.getGroups(data.dataset.profile.viewstyle.definition.root.fieldGroups.fieldGroup, this.fields);debugger;
this.dataModel.groups = this.getGroups(data.dataset.profile.viewstyle.definition.root.fieldGroups.fieldGroup, this.fields);
this.dataModel.semanticAttr = new Array(new Attribute);
//this.dataModel.semanticAttr = data.dataset.profile.definition.root.fields.field;
this.dataModel.semanticAttr = this.getFieldsAttributes(data.dataset.profile.definition.root.fields.field, this.fields) ;

View File

@ -1,5 +1,7 @@
<!doctype html>
<html lang="en">
<script src="https://apis.google.com/js/platform.js" ></script>
<meta name="google-signin-client_id" content="524432312250-vhgidft856v8qftsc81kls4c74v87d8o.apps.googleusercontent.com">
<head>
<meta charset="utf-8">
<title>Digital Management Plans - Manager</title>
@ -13,12 +15,23 @@
</head>
<body>
<script>
  function signOut() {debugger;
    var auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then(function () {
      console.log('User signed out.');
localStorage.removeItem('currentUser');
    });
  }
</script>
<div class="panel panel-default" style="margin-top: 30px; margin-bottom: 30px; margin-right: 30px; margin-left: 30px;">
<div class="panel-heading">
<h3 class="panel-title" style="text-align: center;">Digital Management Plans Editor</h3>
<!-- <h3 class="panel-title" style="text-align: center;">Digital Management Plans Editor</h3> -->
<h3 class="panel-title" style="text-align: center;">Sing in using gmail</h3>
</div>
<div class="panel-body">
<app-root></app-root>
</div>
</div>