home.ts 3.91 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';
9
import { CookieService } from 'ngx-cookie';
10
import { STUDENT_ROLE } from '../constants';
Open Source Developer's avatar
commit    
Open Source Developer committed
11
12
13
14
15
16
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray
} from '@angular/forms';
17

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

26
27
28
<!--            <div class="text-center bg-warning" style="padding: 2em;"><p>
            <strong>Ανακοίνωση:</strong> τη Δευτέρα <strong>26/6/2017</strong>
            το σύστημα θα είναι διαθέσιμο<br/> <strong>μετά τις 13:00</strong> λόγω εργασιών συντήρησης.</p></div> -->
Open Source Developer's avatar
news    
Open Source Developer committed
29

30
31
            <div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
            <div class="row" style="min-height: 300px; margin-top: 100px;">
32

33
34
            <div *ngIf="!authToken" class="col-md-8 offset-md-4">
                <button type="submit" class="btn-primary btn-lg" (click)="form.submit()">
35
                Είσοδος μέσω TaxisNet
Open Source Developer's avatar
commit    
Open Source Developer committed
36
37
                </button>
            </div>
38
            </div>
39

40
     </form>
41
42
43
  </div>
  `
})
Open Source Developer's avatar
Open Source Developer committed
44

45
46
47
48
export default class Home implements OnInit {
    public formGroup: FormGroup;
    private authToken: string;
    private authRole: string;
49
50
    private name: any;
    private xcsrftoken: any;
51
    private loginInfo$: Observable<ILoginInfo>;
52
    private apiEndPoint = API_ENDPOINT;
53
    private apiEndPointParams = API_ENDPOINT_PARAMS;
54

55
56
57
    constructor(private fb: FormBuilder,
        private _ata: LoginInfoActions,
        private _ngRedux: NgRedux<IAppState>,
58
        private activatedRoute: ActivatedRoute,
59
        private _hds: HelperDataService,
60
61
        private router: Router,
        private _cookieService:CookieService
62
63
64
65
    ) {
        this.authToken = '';
        this.authRole = '';
        this.name = '';
66
67
68
        this.formGroup = this.fb.group({
        });
    };
Open Source Developer's avatar
commit    
Open Source Developer committed
69

70
    ngOnInit() {
71

72
73
74
75
76
        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;
77
78
79
80
81
82
83
                    if (this.authToken && this.authToken.length > 0 && this.authRole && this.authRole === STUDENT_ROLE) {
                        if (loginInfoToken.lock_application === 1)
                            this.router.navigate(['/info']);
                        else {
                            this.router.navigate(['/parent-form']);
                        }
                    }
84
85
86
                    return loginInfoToken;
                }, {});
            }
87

88
89
90
91
            return state.loginInfo;
        });

        // subscribe to router event
92
        this.activatedRoute.queryParams.subscribe((params: Params) => {
93
94
95
96
            if (params) {
                this.authToken = params['auth_token'];
                this.authRole = params['auth_role'];
            }
97

98
            if (this.authToken && this.authRole)
99
                this._ata.getloginInfo({ auth_token: this.authToken, auth_role: this.authRole });
100

101
        });
102
103
104
105
    }

    getCookie(key: string){
        return this._cookieService.get(key);
106
    }
107
108
109
110
111

    removeCookie(key: string){
        return this._cookieService.remove(key);
    }

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

114
    }
115
}