feat: 直接登陆

parent 02a2d7f1
...@@ -104,7 +104,7 @@ def asset_groups_assets(): ...@@ -104,7 +104,7 @@ def asset_groups_assets():
"comment": "Default asset group", "comment": "Default asset group",
"assets_granted": [ "assets_granted": [
{ {
"id": 2, "id": 1,
"hostname": "192.168.1.6", "hostname": "192.168.1.6",
"ip": "192.168.2.6", "ip": "192.168.2.6",
"port": 22, "port": 22,
......
...@@ -92,9 +92,28 @@ export class CleftbarComponent implements OnInit { ...@@ -92,9 +92,28 @@ export class CleftbarComponent implements OnInit {
.map(res => res.json()) .map(res => res.json())
.subscribe(response => { .subscribe(response => {
this.HostGroups = response; this.HostGroups = response;
this.autologin();
}); });
} }
autologin() {
const id = this._appService.getQueryString('id');
if (id) {
for (let g of this.HostGroups) {
if (g['assets_granted']) {
for (let u of g['assets_granted']) {
if (u.id.toString() === id.toString()) {
this.Connect(u);
return;
}
}
}
}
}
}
Connect(host) { Connect(host) {
// console.log(host); // console.log(host);
let userid: string; let userid: string;
......
...@@ -77,11 +77,11 @@ export class SshComponent implements OnInit { ...@@ -77,11 +77,11 @@ export class SshComponent implements OnInit {
screenKeys: true, screenKeys: true,
}); });
NavList.List.push(new View()); NavList.List.push(new View());
for (let _i = 0; _i < NavList.List.length; _i++) { for (let i = 0; i < NavList.List.length; i++) {
if (id === _i) { if (id === i) {
NavList.List[id].hide = false; NavList.List[id].hide = false;
} else { } else {
NavList.List[_i].hide = true; NavList.List[i].hide = true;
} }
} }
......
...@@ -13,6 +13,7 @@ import {Logger} from 'angular2-logger/core'; ...@@ -13,6 +13,7 @@ import {Logger} from 'angular2-logger/core';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/catch';
import {DataStore, User, Browser} from './globals'; import {DataStore, User, Browser} from './globals';
declare function unescape(s: string): string;
@Injectable() @Injectable()
export class HttpService { export class HttpService {
...@@ -174,6 +175,14 @@ export class AppService implements OnInit { ...@@ -174,6 +175,14 @@ export class AppService implements OnInit {
this._http.post('/api/browser', JSON.stringify(Browser)).map(res => res.json()).subscribe(); this._http.post('/api/browser', JSON.stringify(Browser)).map(res => res.json()).subscribe();
} }
getQueryString(name) {
const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
const r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
// //
// //
......
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