fix: single page reload bug

parent 64047868
...@@ -5,7 +5,6 @@ import {DataStore, User} from '../../globals'; ...@@ -5,7 +5,6 @@ import {DataStore, User} from '../../globals';
import {DomSanitizer} from '@angular/platform-browser'; import {DomSanitizer} from '@angular/platform-browser';
import {environment} from '../../../environments/environment'; import {environment} from '../../../environments/environment';
import {NavList} from '../../ControlPage/control/control.component'; import {NavList} from '../../ControlPage/control/control.component';
import {logger} from 'codelyzer/util/logger';
@Component({ @Component({
selector: 'app-element-guacamole', selector: 'app-element-guacamole',
...@@ -19,6 +18,8 @@ export class ElementGuacamoleComponent implements OnInit { ...@@ -19,6 +18,8 @@ export class ElementGuacamoleComponent implements OnInit {
@Input() index: number; @Input() index: number;
target: string; target: string;
@ViewChild('rdp') el: ElementRef; @ViewChild('rdp') el: ElementRef;
authToken: string;
base: string;
constructor(private sanitizer: DomSanitizer, constructor(private sanitizer: DomSanitizer,
private _http: HttpService, private _http: HttpService,
...@@ -30,34 +31,45 @@ export class ElementGuacamoleComponent implements OnInit { ...@@ -30,34 +31,45 @@ export class ElementGuacamoleComponent implements OnInit {
ngOnInit() { ngOnInit() {
// /guacamole/api/tokens will redirect to http://guacamole/api/tokens // /guacamole/api/tokens will redirect to http://guacamole/api/tokens
if (this.token) { if (this.token) {
this.userid = this._localStorage.get('user'); this.userid = this._localStorage.get('user-' + this.token);
if (this.userid) { this.authToken = this._localStorage.get('authToken-' + this.token);
this._http.get_guacamole_token(this.userid, this.token).subscribe( this.base = this._localStorage.get('base-' + this.token);
data => {
DataStore.guacamole_token = data['authToken'];
this._http.guacamole_token_add_asset(this.token, data['authToken']).subscribe( if (!this.userid) {
data2 => {
this._logger.debug(data);
if (data2['result']) {
window.location.reload();
}
this.target = document.location.origin + '/guacamole/#/client/' + data2['result'] +
'?asset_token=jumpserver&token=' + data['authToken'];
},
error2 => {
this._logger.error(error2);
}
);
});
} else {
this._http.get_user_id_from_token(this.token) this._http.get_user_id_from_token(this.token)
.subscribe( .subscribe(
data => { data => {
this._localStorage.set('user', data['user']); this._localStorage.set('user-' + this.token, data['user']);
window.location.reload();
} }
); );
}
if (!this.authToken) {
this._http.get_guacamole_token(this.userid, this.token).subscribe(
data => {
if (data['authToken']) {
this._localStorage.set('authToken-' + this.token, data['authToken']);
this.authToken = data['authToken'];
}
}
);
}
if (!this.base) {
this._http.guacamole_token_add_asset(this.token, this.authToken).subscribe(
data => {
if (data['result']) {
this._localStorage.set('base-' + this.token, data['result']);
this.base = data['result'];
}
});
}
if (this.authToken && this.base) {
this.target = document.location.origin + '/guacamole/#/client/' + this.base +
'?asset_token=jumpserver&token=' + this.authToken;
} else {
window.location.reload();
} }
} else { } else {
const base = window.btoa(this.host.id + '\0' + 'c' + '\0' + 'jumpserver'); const base = window.btoa(this.host.id + '\0' + 'c' + '\0' + 'jumpserver');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment