home.ts 3.51 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
import { AppSettings } from '../app.settings';
15
@Component({
16 17
    selector: 'home',
    template: `
18
  <div>
19 20
	   <form [formGroup]="formGroup" method = "POST" action="http://eepal.dev/drupal/oauth/login" #form>
            <input type="hidden" name="X-oauth-enabled" value="true">
21 22 23 24 25 26 27 28 29 30
            <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>
                </div>
            </div>
Open Source Developer's avatar
commit  
Open Source Developer committed
31
            <div class="row">
32 33

            <div *ngIf="!authToken" class="col-md-7 col-md-offset-5">
34 35
                <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
36 37
                </button>
            </div>
38 39 40 41 42 43 44 45 46 47 48 49 50 51
            </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>
52
     </form>
53 54 55
  </div>
  `
})
56 57 58 59 60 61 62 63 64 65 66 67 68
export default class Home implements OnInit {
    public formGroup: FormGroup;
    private authToken: string;
    private authRole: string;
    private loginInfo$: Observable<ILoginInfo>;
    constructor(private fb: FormBuilder,
        private _ata: LoginInfoActions,
        private _ngRedux: NgRedux<IAppState>,
        private activatedRoute: ActivatedRoute
        ) {
            this.authToken = '';
            this.authRole = '';
        this.formGroup = this.fb.group({
Open Source Developer's avatar
commit  
Open Source Developer committed
69
            Username: [],
70 71 72
            Paswd: []
        });
    };
Open Source Developer's avatar
commit  
Open Source Developer committed
73

74
    ngOnInit() {
75 76 77 78 79 80 81 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;
                    return loginInfoToken;
                }, {});
            }
            return state.loginInfo;
        });

        // subscribe to router event
87
        this.activatedRoute.queryParams.subscribe((params: Params) => {
88 89 90 91 92
            this.authToken = params['auth_token'];
            this.authRole = params['auth_role'];
            if (this.authToken && this.authRole)
            this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole });
    //        console.log(this.authToken);
93

94 95
        });
    }
96 97


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

99
    checkvalidation() {
Open Source Developer's avatar
commit  
Open Source Developer committed
100

101
    }
102
}