home.ts 3.85 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
commit  
Open Source Developer committed
8 9 10 11 12 13
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray
} from '@angular/forms';
14 15

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

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

35 36
            <div *ngIf="!authToken" class="col-md-8 offset-md-4">
                <button type="submit" class="btn-primary btn-lg" (click)="form.submit()">
37
                Είσοδος μέσω TaxisNet<span class="glyphicon glyphicon-menu-right"></span>
Open Source Developer's avatar
commit  
Open Source Developer committed
38 39
                </button>
            </div>
40
            </div>
41
            <!--
42 43 44 45 46 47 48 49 50 51 52 53 54
            <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>
55
            -->
56
     </form>
57 58 59
  </div>
  `
})
60 61 62 63 64
export default class Home implements OnInit {
    public formGroup: FormGroup;
    private authToken: string;
    private authRole: string;
    private loginInfo$: Observable<ILoginInfo>;
65 66
    private apiEndPoint = API_ENDPOINT;

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

81
    ngOnInit() {
82 83 84 85 86
        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;
87 88
                    if (this.authToken && this.authToken.length > 0)
                        this.router.navigate(['/epal-class-select']);
89 90 91
                    return loginInfoToken;
                }, {});
            }
92

93 94 95 96
            return state.loginInfo;
        });

        // subscribe to router event
97
        this.activatedRoute.queryParams.subscribe((params: Params) => {
98 99 100 101
            if (params) {
                this.authToken = params['auth_token'];
                this.authRole = params['auth_role'];
            }
102 103 104
            if (this.authToken && this.authRole)
            this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole });
    //        console.log(this.authToken);
105

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
    }
Open Source Developer's avatar
commit  
Open Source Developer committed
114
}