home.ts 4.03 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 16

import { API_ENDPOINT } from '../app.settings';
17
@Component({
18 19
    selector: 'home',
    template: `
20
  <div>
Open Source Developer's avatar
Open Source Developer committed
21
       <form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/oauth/login" #form>
22
<!--            <input type="hidden" name="X-oauth-enabled" value="true"> -->
23 24 25

            <div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
<!--                <div class="row">
26 27 28 29 30 31 32
                    <div class="col-md-6">
                        {{loginInfoToken$.auth_token}}
                    </div>
                    <div class="col-md-6">
                        {{loginInfoToken$.auth_role}}
                    </div>
                </div>
33 34
            </div> -->
            <div class="row" style="min-height: 300px; margin-top: 100px;">
35

36 37
            <div *ngIf="!authToken" class="col-md-8 offset-md-4">
                <button type="submit" class="btn-primary btn-lg" (click)="form.submit()">
38
                Είσοδος μέσω TaxisNet<span class="glyphicon glyphicon-menu-right"></span>
Open Source Developer's avatar
commit  
Open Source Developer committed
39 40
                </button>
            </div>
41
            </div>
42
            <!--
43 44 45 46 47 48 49 50 51 52 53 54 55
            <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>
56
            -->
57
     </form>
58 59 60
  </div>
  `
})
Open Source Developer's avatar
Open Source Developer committed
61

62 63 64 65
export default class Home implements OnInit {
    public formGroup: FormGroup;
    private authToken: string;
    private authRole: string;
Open Source Developer's avatar
Open Source Developer committed
66
    private name :any;
67
    private xcsrftoken :any;
68
    private loginInfo$: Observable<ILoginInfo>;
69 70
    private apiEndPoint = API_ENDPOINT;

71 72 73
    constructor(private fb: FormBuilder,
        private _ata: LoginInfoActions,
        private _ngRedux: NgRedux<IAppState>,
Open Source Developer's avatar
Open Source Developer committed
74 75
        private activatedRoute: ActivatedRoute,
        private _hds: HelperDataService, 
76
        private router: Router
77 78 79
        ) {
            this.authToken = '';
            this.authRole = '';
Open Source Developer's avatar
Open Source Developer committed
80
            this.name ='';
81
        this.formGroup = this.fb.group({
82 83
//            Username: [],
//            Paswd: []
84 85
        });
    };
Open Source Developer's avatar
commit  
Open Source Developer committed
86

87
    ngOnInit() {
Open Source Developer's avatar
Open Source Developer committed
88
               this.loginInfo$ = this._ngRedux.select(state => {
89 90 91 92
            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
93 94
                     if (this.authToken && this.authToken.length > 0)
                        this.router.navigate(['/epal-class-select']);
95 96 97
                    return loginInfoToken;
                }, {});
            }
98

99 100
            return state.loginInfo;
        });
101
       
102
        // subscribe to router event
103
        this.activatedRoute.queryParams.subscribe((params: Params) => {
104 105 106 107
            if (params) {
                this.authToken = params['auth_token'];
                this.authRole = params['auth_role'];
            }
Open Source Developer's avatar
Open Source Developer committed
108
         
109 110 111
            if (this.authToken && this.authRole)
                this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole});
     
112 113
        });
    }
114 115


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

117
    checkvalidation() {
Open Source Developer's avatar
commit  
Open Source Developer committed
118

119
    }
120
}