Project

General

Profile

« Previous | Next » 

Revision 61435

removed openAIREUser cookie usage

View differences:

authentication.service.ts
19 19

  
20 20
  private _storage: Storage = sessionStorage;
21 21

  
22
  private cookie: string = null;
23

  
22 24
  isLoggedIn: boolean = false;
23 25

  
24 26
  public loginWithState() {
......
37 39
  }
38 40

  
39 41
  public logout() {
40
    deleteCookie('openAIREUser');
41 42
    deleteCookie('AccessToken');
42 43
    sessionStorage.clear();
43 44
    this.isLoggedIn = false;
......
50 51
  }
51 52

  
52 53
  public tryLogin() {
53
    if ( getCookie('openAIREUser') && (getCookie('openAIREUser') !== '') ) {
54
      console.log(`I got the cookie!`);
55
      console.log(`in tryLogin -> document.cookie is: ${document.cookie.toString()}`);
54
    this.cookie = getCookie('AccessToken');
55
    if (this.cookie && this.cookie !== '') {
56
      // console.log(`I got the cookie!`);
57
      // console.log(`in tryLogin -> document.cookie is: ${document.cookie.toString()}`);
56 58
      /* SETTING INTERVAL TO REFRESH SESSION TIMEOUT COUNTDOWN */
57 59
      setInterval(() => {
58 60
        this.http.get(this.apiUrl + '/user/login', { withCredentials: true }).subscribe(
59 61
          userInfo => {
60
            console.log('User is still logged in');
61
            console.log(userInfo);
62
            // console.log('User is still logged in');
63
            // console.log(userInfo);
62 64
            this.isLoggedIn = true;
63 65
          },
64 66
          () => {
65 67
            this.logout();
66 68
          },
67 69
          () => {
68
            if ( !getCookie('openAIREUser') || (getCookie('openAIREUser') === '') ) {
70
            this.cookie = getCookie('AccessToken');
71
            if ( !this.cookie || this.cookie === '') {
69 72
              this.logout();
70 73
            }
71 74
          }
......
75 78

  
76 79
      }, 1000 * 60 * 5);
77 80
      if (!this.getIsUserLoggedIn()) {
78
        console.log(`session.name wasn't found --> logging in via repo-service!`);
81
        // console.log(`session.name wasn't found --> logging in via repo-service!`);
79 82
        this.http.get(this.apiUrl + '/user/login', { withCredentials: true }).subscribe(
80 83
          userInfo => {
81
            console.log(userInfo);
84
            // console.log(userInfo);
82 85
            sessionStorage.setItem('name', userInfo['name']);
83 86
            sessionStorage.setItem('email', userInfo['email'].trim());
84 87
            sessionStorage.setItem('role', userInfo['role']);
85 88
            this.isLoggedIn = true;
86
            console.log(`the current user is: ${sessionStorage.getItem('name')},
87
                         ${sessionStorage.getItem('email')}, ${sessionStorage.getItem('role')}`);
89
            // console.log(`the current user is: ${sessionStorage.getItem('name')},
90
            //              ${sessionStorage.getItem('email')}, ${sessionStorage.getItem('role')}`);
88 91
          },
89 92
          error => {
90 93
            sessionStorage.clear();
91 94
            console.log('Error!');
92 95
            console.log(error);
93
            deleteCookie('openAIREUser');
94 96
            deleteCookie('AccessToken');
97
            deleteCookie('AccessToken');
95 98
            this.isLoggedIn = false;
96 99
            this.router.navigate(['/home']);
97 100
          },
......
101 104
              sessionStorage.removeItem('state.location');
102 105
              console.log(`tried to login - returning to state: ${state}`);
103 106
              if ( !this.getIsUserLoggedIn() ) {
104
                console.log('user hasn\'t logged in yet -- going to home');
107
                // console.log('user hasn\'t logged in yet -- going to home');
105 108
                this.router.navigate(['/home']);
106 109
              } else {
107 110
                this.router.navigate([state]);
......
111 114
        );
112 115
      } else {
113 116
        this.isLoggedIn = true;
114
        console.log(`the current user is: ${sessionStorage.getItem('name')},
115
                     ${sessionStorage.getItem('email')}, ${sessionStorage.getItem('role')}`);
117
        // console.log(`the current user is: ${sessionStorage.getItem('name')},
118
        //              ${sessionStorage.getItem('email')}, ${sessionStorage.getItem('role')}`);
116 119
        if (this.redirectUrl) {
117 120
          const url = this.redirectUrl;
118 121
          this.redirectUrl = null;
119 122
          this.router.navigate([url]);
120
          console.log('route is', url);
123
          // console.log('route is', url);
121 124
        }
122 125
      }
123 126
    }
124 127
  }
125 128

  
126 129
  public getIsUserLoggedIn() {
127
    this.isLoggedIn = (getCookie('openAIREUser') && (getCookie('openAIREUser') !== '') && (sessionStorage.getItem('email') !== null ) );
128
    return this.isLoggedIn;
130
    // todo: probably not all of them are needed
131
    return this.isLoggedIn && this.cookie && this.cookie !== '' && sessionStorage.getItem('email') !== null;
129 132
  }
130 133

  
131 134
  public getUserName() {

Also available in: Unified diff