fix: update

parent 46d94cdb
...@@ -277,6 +277,7 @@ export class AppService implements OnInit { ...@@ -277,6 +277,7 @@ export class AppService implements OnInit {
} }
User.logined = data['logined']; User.logined = data['logined'];
this._logger.debug(User); this._logger.debug(User);
this._localStorage.set('user', data['id']);
}, },
err => { err => {
// this._logger.error(err); // this._logger.error(err);
......
import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core'; import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {CookieService} from 'ngx-cookie-service'; import {CookieService} from 'ngx-cookie-service';
import {HttpService, LogService} from '../../app.service'; import {HttpService, LocalStorageService, LogService} from '../../app.service';
import {DataStore, User} from '../../globals'; 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';
...@@ -22,63 +22,26 @@ export class ElementGuacamoleComponent implements OnInit { ...@@ -22,63 +22,26 @@ export class ElementGuacamoleComponent implements OnInit {
constructor(private sanitizer: DomSanitizer, constructor(private sanitizer: DomSanitizer,
private _http: HttpService, private _http: HttpService,
private _cookie: CookieService, private _cookie: CookieService,
private _logger: LogService) { private _logger: LogService,
private _localStorage: LocalStorageService) {
} }
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) {
if (User.id) { this.userid = this._localStorage.get('user');
this._http.get_user_profile() this._http.get_guacamole_token(this.userid).subscribe(
.subscribe( data => {
data => { DataStore.guacamole_token = data['authToken'];
User.id = data['id']; this._http.guacamole_token_add_asset(this.token).subscribe(
User.name = data['name']; _ => {
User.username = data['username']; this.target = document.location.origin + '/guacamole/#/client/' + data['result'] + '?token=' + DataStore.guacamole_token;
User.email = data['email'];
User.is_active = data['is_active'];
User.is_superuser = data['is_superuser'];
User.role = data['role'];
// User.groups = data['groups'];
User.wechat = data['wechat'];
User.comment = data['comment'];
User.date_expired = data['date_expired'];
if (data['phone']) {
User.phone = data['phone'].toString();
}
User.logined = data['logined'];
this._http.get_guacamole_token(User.id).subscribe(
data2 => {
DataStore.guacamole_token = data2['authToken'];
this._http.guacamole_token_add_asset(this.token).subscribe(
_ => {
this.target = document.location.origin + '/guacamole/#/client/' + data['result'] + '?token=' + DataStore.guacamole_token;
},
error2 => {
this._logger.error(error2);
}
);
});
},
err => {
User.logined = false;
window.location.href = document.location.origin + '/users/login?next=' + document.location.pathname;
}, },
error2 => {
this._logger.error(error2);
}
); );
} else { });
this._http.get_guacamole_token(User.id).subscribe(
data => {
DataStore.guacamole_token = data['authToken'];
this._http.guacamole_token_add_asset(this.token).subscribe(
_ => {
this.target = document.location.origin + '/guacamole/#/client/' + data['result'] + '?token=' + DataStore.guacamole_token;
},
error2 => {
this._logger.error(error2);
}
);
});
}
} else { } else {
const base = window.btoa(this.host.id + '\0' + 'c' + '\0' + 'jumpserver'); const base = window.btoa(this.host.id + '\0' + 'c' + '\0' + 'jumpserver');
if (environment.production) { if (environment.production) {
......
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