Revision 59464
Added by Konstantina Galouni over 3 years ago
userMini.component.ts | ||
---|---|---|
1 | 1 |
import {Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core'; |
2 |
import {ActivatedRoute, Router} from '@angular/router'; |
|
2 |
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
|
|
3 | 3 |
import {Location} from '@angular/common'; |
4 | 4 |
import {User, Session} from './utils/helper.class'; |
5 | 5 |
import {RouterHelper} from '../utils/routerHelper.class'; |
... | ... | |
176 | 176 |
@Input() logInUrl; |
177 | 177 |
@Input() logOutUrl; |
178 | 178 |
@Input() cookieDomain; |
179 |
@Input() fixRedirectUrl: string; |
|
179 | 180 |
@Input() redirectUrl: string; |
180 | 181 |
@Input() dark: boolean = false; |
181 | 182 |
search: string = ''; |
182 | 183 |
sub: any; |
183 | 184 |
|
184 |
constructor(private router: Router, private route: ActivatedRoute, private location: Location) { |
|
185 |
constructor(private router: Router, private route: ActivatedRoute) { |
|
186 |
this.router.events.forEach(event => { |
|
187 |
if(event instanceof NavigationStart) { |
|
188 |
this.initialize(event.url); |
|
189 |
} |
|
190 |
}); |
|
185 | 191 |
} |
186 | 192 |
|
187 | 193 |
ngOnInit() { |
188 |
|
|
189 | 194 |
if (typeof document !== 'undefined') { |
190 | 195 |
this.server = false; |
191 | 196 |
} |
192 |
this.initialize(); |
|
193 | 197 |
this.sub = this.route.queryParams.subscribe(params => { |
194 | 198 |
this.initialize(); |
195 | 199 |
}); |
196 |
|
|
197 |
|
|
198 | 200 |
} |
199 | 201 |
|
200 | 202 |
ngOnChanges(changes: SimpleChanges): void { |
... | ... | |
209 | 211 |
} |
210 | 212 |
} |
211 | 213 |
|
212 |
initialize() { |
|
213 |
if (!this.redirectUrl && typeof location !== 'undefined') { |
|
214 |
this.redirectUrl = location.pathname; |
|
215 |
this.search = location.search; |
|
214 |
initialize(url: string = null) { |
|
215 |
if (typeof location !== 'undefined') { |
|
216 |
if(url) { |
|
217 |
let parts = StringUtils.split(url, ['?']); |
|
218 |
this.redirectUrl = properties.baseLink + parts[0]; |
|
219 |
if(parts.length == 2) { |
|
220 |
this.search = parts[1]; |
|
221 |
} else { |
|
222 |
this.search = null; |
|
223 |
} |
|
224 |
} else { |
|
225 |
this.redirectUrl = location.pathname; |
|
226 |
this.search = location.search; |
|
227 |
} |
|
216 | 228 |
} |
217 | 229 |
if (this.user) { |
218 | 230 |
this.loggedIn = true; |
... | ... | |
230 | 242 |
logOut() { |
231 | 243 |
if (this.user) { |
232 | 244 |
Session.removeUser(); |
233 |
window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href); |
|
234 |
|
|
245 |
// New method |
|
246 |
if(properties.logoutUrl.includes('openid_logout')) { |
|
247 |
Session.setReloadUrl(location.protocol + "//" + location.host, this.redirectUrl, this.search); |
|
248 |
window.location.href = this.logOutUrl; |
|
249 |
} else { |
|
250 |
window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href); |
|
251 |
} |
|
235 | 252 |
} |
236 | 253 |
this.loggedIn = false; |
237 | 254 |
this.isAuthorized = false; |
... | ... | |
239 | 256 |
} |
240 | 257 |
|
241 | 258 |
logIn() { |
242 |
Session.setReloadUrl(location.protocol + "//" + location.host, this.redirectUrl, this.search); |
|
259 |
Session.setReloadUrl(location.protocol + "//" + location.host, |
|
260 |
this.fixRedirectUrl?(properties.baseLink + this.fixRedirectUrl):this.redirectUrl, this.search); |
|
243 | 261 |
window.location.href = this.logInUrl; |
244 | 262 |
} |
245 | 263 |
|
Also available in: Unified diff
[use-UoaAdminToolsLibrary | Library]: Merge trunk into branch.