fix: single page reload bug

parent 64047868
......@@ -5,7 +5,6 @@ import {DataStore, User} from '../../globals';
import {DomSanitizer} from '@angular/platform-browser';
import {environment} from '../../../environments/environment';
import {NavList} from '../../ControlPage/control/control.component';
import {logger} from 'codelyzer/util/logger';
@Component({
selector: 'app-element-guacamole',
......@@ -19,6 +18,8 @@ export class ElementGuacamoleComponent implements OnInit {
@Input() index: number;
target: string;
@ViewChild('rdp') el: ElementRef;
authToken: string;
base: string;
constructor(private sanitizer: DomSanitizer,
private _http: HttpService,
......@@ -30,34 +31,45 @@ export class ElementGuacamoleComponent implements OnInit {
ngOnInit() {
// /guacamole/api/tokens will redirect to http://guacamole/api/tokens
if (this.token) {
this.userid = this._localStorage.get('user');
if (this.userid) {
this._http.get_guacamole_token(this.userid, this.token).subscribe(
data => {
DataStore.guacamole_token = data['authToken'];
this._http.guacamole_token_add_asset(this.token, data['authToken']).subscribe(
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.userid = this._localStorage.get('user-' + this.token);
this.authToken = this._localStorage.get('authToken-' + this.token);
this.base = this._localStorage.get('base-' + this.token);
if (!this.userid) {
this._http.get_user_id_from_token(this.token)
.subscribe(
data => {
this._localStorage.set('user', data['user']);
window.location.reload();
this._localStorage.set('user-' + this.token, data['user']);
}
);
}
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 {
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