home.ts 3.98 KB
Newer Older
1 2 3
import {Router, ActivatedRoute, Params} from '@angular/router';
import {OnInit, Component} from '@angular/core';
import { LoginInfoActions } from '../actions/logininfo.actions';
4 5 6 7
import { ILoginInfo } from '../store/logininfo/logininfo.types';
import { NgRedux, select } from 'ng2-redux';
import { Observable } from 'rxjs/Rx';
import { IAppState } from '../store/store';
Open Source Developer's avatar
Open Source Developer committed
8
import { HelperDataService } from '../services/helper-data-service';
Open Source Developer's avatar
commit  
Open Source Developer committed
9 10 11 12 13 14
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray
} from '@angular/forms';
15
import { AppSettings } from '../app.settings';
16
@Component({
17 18
    selector: 'home',
    template: `
19
  <div>
Open Source Developer's avatar
changes  
Open Source Developer committed
20
	   <form [formGroup]="formGroup" method = "POST" action="http://localhost/angular/eepal-front/drupal/oauth/login" #form>
21
<!--            <input type="hidden" name="X-oauth-enabled" value="true"> -->
22 23 24 25 26 27 28 29
            <div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index">
                <div class="row">
                    <div class="col-md-6">
                        {{loginInfoToken$.auth_token}}
                    </div>
                    <div class="col-md-6">
                        {{loginInfoToken$.auth_role}}
                    </div>
30
                    
31 32
                </div>
            </div>
Open Source Developer's avatar
commit  
Open Source Developer committed
33
            <div class="row">
34 35

            <div *ngIf="!authToken" class="col-md-7 col-md-offset-5">
36 37
                <button type="submit" class="btn-primary btn-lg pull-center" (click)="form.submit()">
                Είσοδος μέσω TaxisNet<span class="glyphicon glyphicon-menu-right"></span>
Open Source Developer's avatar
commit  
Open Source Developer committed
38 39
                </button>
            </div>
40 41 42 43 44 45 46 47 48 49 50 51 52 53
            </div>
            <div class="row">
            <div *ngIf="authToken" class="col-md-7 col-md-offset-5">
                <h3>Καλώς ήρθατε</h3>
            </div>
            </div>
            <div class="row">
            <div *ngIf="authToken" class="col-md-7 col-md-offset-5">
                <input type="hidden" name="dologout" value="true">
                <button type="submit" class="btn-primary btn-lg pull-center" (click)="form.submit()">
                Αποσύνδεση<span class="glyphicon glyphicon-menu-right"></span>
                </button>
            </div>
            </div>
54
     </form>
55 56 57
  </div>
  `
})
58 59 60 61
export default class Home implements OnInit {
    public formGroup: FormGroup;
    private authToken: string;
    private authRole: string;
Open Source Developer's avatar
Open Source Developer committed
62
    private name :any;
63
    private xcsrftoken :any;
64 65 66 67
    private loginInfo$: Observable<ILoginInfo>;
    constructor(private fb: FormBuilder,
        private _ata: LoginInfoActions,
        private _ngRedux: NgRedux<IAppState>,
Open Source Developer's avatar
Open Source Developer committed
68 69
        private activatedRoute: ActivatedRoute,
        private _hds: HelperDataService, 
70 71 72
        ) {
            this.authToken = '';
            this.authRole = '';
Open Source Developer's avatar
Open Source Developer committed
73
            this.name ='';
74
        this.formGroup = this.fb.group({
Open Source Developer's avatar
commit  
Open Source Developer committed
75
            Username: [],
76 77 78
            Paswd: []
        });
    };
Open Source Developer's avatar
commit  
Open Source Developer committed
79

80
    ngOnInit() {
81 82 83 84 85
        this.loginInfo$ = this._ngRedux.select(state => {
            if (state.loginInfo.size > 0) {
                state.loginInfo.reduce(({}, loginInfoToken) => {
                    this.authToken = loginInfoToken.auth_token;
                    this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
86
                    this.name = loginInfoToken.cu_name;
87
                    this.xcsrftoken = loginInfoToken.xcsrftoken;
88 89 90 91 92
                    return loginInfoToken;
                }, {});
            }
            return state.loginInfo;
        });
Open Source Developer's avatar
Open Source Developer committed
93
        
94
       
95
        // subscribe to router event
96
        this.activatedRoute.queryParams.subscribe((params: Params) => {
97 98
            this.authToken = params['auth_token'];
            this.authRole = params['auth_role'];
Open Source Developer's avatar
Open Source Developer committed
99
            
100

101 102 103 104 105
            if (this.authToken && this.authRole)
                this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole});
          
          //  this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole, cu_name:this.name });
     
106 107
        });
    }
108 109


Open Source Developer's avatar
commit  
Open Source Developer committed
110

111
    checkvalidation() {
Open Source Developer's avatar
commit  
Open Source Developer committed
112

113
    }
114
}