home.ts 4.13 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>
Open Source Developer's avatar
Open Source Developer committed
30 31 32
                    <div>
                        {{loginInfoToken$.cu_name}}
                    </div>
33 34
                </div>
            </div>
Open Source Developer's avatar
commit  
Open Source Developer committed
35
            <div class="row">
36 37

            <div *ngIf="!authToken" class="col-md-7 col-md-offset-5">
38 39
                <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
40 41
                </button>
            </div>
42 43 44 45 46 47 48 49 50 51 52 53 54 55
            </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>
56
     </form>
57 58 59
  </div>
  `
})
60 61 62 63
export default class Home implements OnInit {
    public formGroup: FormGroup;
    private authToken: string;
    private authRole: string;
Open Source Developer's avatar
Open Source Developer committed
64
    private name :any;
65 66 67 68
    private loginInfo$: Observable<ILoginInfo>;
    constructor(private fb: FormBuilder,
        private _ata: LoginInfoActions,
        private _ngRedux: NgRedux<IAppState>,
Open Source Developer's avatar
Open Source Developer committed
69 70
        private activatedRoute: ActivatedRoute,
        private _hds: HelperDataService, 
71 72 73
        ) {
            this.authToken = '';
            this.authRole = '';
Open Source Developer's avatar
Open Source Developer committed
74
            this.name ='';
75
        this.formGroup = this.fb.group({
Open Source Developer's avatar
commit  
Open Source Developer committed
76
            Username: [],
77 78 79
            Paswd: []
        });
    };
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;
Open Source Developer's avatar
Open Source Developer committed
87
                    this.name = loginInfoToken.cu_name;
88 89 90 91 92
                    return loginInfoToken;
                }, {});
            }
            return state.loginInfo;
        });
Open Source Developer's avatar
Open Source Developer committed
93 94 95 96 97 98 99 100
        
        this._hds.getCurrentUser(this.authToken).then(cu_name =>{ return this._ngRedux.dispatch({
                type: "aaaaaa",
                payload: {
                    cu_name
                }
            });
        });
101
        // subscribe to router event
102
        this.activatedRoute.queryParams.subscribe((params: Params) => {
103 104
            this.authToken = params['auth_token'];
            this.authRole = params['auth_role'];
Open Source Developer's avatar
Open Source Developer committed
105
            
106
            if (this.authToken && this.authRole)
Open Source Developer's avatar
Open Source Developer committed
107 108
            this._ata.saveLoginInfo({ auth_token: this.authToken, auth_role: this.authRole, cu_name:this.name });
           // console.log(this.authToken,"token");
109

110 111
        });
    }
112 113


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

115
    checkvalidation() {
Open Source Developer's avatar
commit  
Open Source Developer committed
116

117
    }
118
}