Commit 5420ab2e authored by zheng liu's avatar zheng liu

Merged in dev (pull request #83)

fix: single page reload bug
parents 7dcf08de f4c84c3e
...@@ -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.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-' + this.token, data['user']);
}
);
}
if (!this.authToken) {
this._http.get_guacamole_token(this.userid, this.token).subscribe( this._http.get_guacamole_token(this.userid, this.token).subscribe(
data => { data => {
DataStore.guacamole_token = data['authToken']; if (data['authToken']) {
this._http.guacamole_token_add_asset(this.token, data['authToken']).subscribe( this._localStorage.set('authToken-' + this.token, data['authToken']);
data2 => { this.authToken = data['authToken'];
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 { if (!this.base) {
this._http.get_user_id_from_token(this.token) this._http.guacamole_token_add_asset(this.token, this.authToken).subscribe(
.subscribe(
data => { data => {
this._localStorage.set('user', data['user']); if (data['result']) {
window.location.reload(); 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