Commit f28e7506 authored by liuzheng712's avatar liuzheng712

update

parent 900f0899
......@@ -15,68 +15,79 @@ var buff = [];
server.run = function (options) {
// create shell process
// term = pty.fork(
// process.env.SHELL || 'sh',
// [],
// {
// name: require('fs').existsSync('/usr/share/terminfo/x/xterm-256color')
// ? 'xterm-256color'
// : 'xterm',
// cols: 80,
// rows: 24,
// cwd: process.env.HOME
// }
// );
//
// // store term's output into buffer or emit through socket
// term.on('data', function (data) {
// return !socket ? buff.push(data) : socket.emit('data', data);
// });
// console.log('Created shell with pty master/slave pair (master: %d, pid: %d)', term.fd, term.pid);
var app = express();
var server = http.createServer(app);
app.use("/", express.static(__dirname + '/dist/')); // 创建服务端
app.use("/socket.io/", express.static(__dirname + '/api/')); // 创建服务端
// let term.js handle req/res
// app.use(terminal.middleware());
// let server listen on the port
options = options || {};
server.listen(options.port || 8080);
// let socket.io handle sockets
io = io.listen(server, {log: false});
io.sockets.on('connection', function (s) {
// when connect, store the socket
socket = s;
// handme incoming data (client -> server)
socket.on('data', function (data) {
term.write(data);
});
socket.on('resize', function (data) {
term.resize(data[0], data[1]);
console.log(data)
});
// handle connection lost
socket.on('disconnect', function () {
socket = null;
});
// send buffer data to client
while (buff.length) {
socket.emit('data', buff.shift());
}
// create shell process
// term = pty.fork(
// process.env.SHELL || 'sh',
// [],
// {
// name: require('fs').existsSync('/usr/share/terminfo/x/xterm-256color')
// ? 'xterm-256color'
// : 'xterm',
// cols: 80,
// rows: 24,
// cwd: process.env.HOME
// }
// );
//
// // store term's output into buffer or emit through socket
// term.on('data', function (data) {
// return !socket ? buff.push(data) : socket.emit('data', data);
// });
// console.log('Created shell with pty master/slave pair (master: %d, pid: %d)', term.fd, term.pid);
var app = express();
var server = http.createServer(app);
var apis = express.Router();
app.use("/", express.static(__dirname + '/dist/')); // 创建服务端
// app.use("/socket.io/", express.static(__dirname + '/api/')); // 创建服务端
// let term.js handle req/res
// app.use(terminal.middleware());
apis.route('/checklogin')
.post(function (req, res) {
res.json({logined: true, user: {id: 1, username: "liuzheng", name: "liuzheng"}})
})
.get(function (req, res) {
res.json({logined: false, user: {id: 1, username: "liuzheng", name: "liuzheng"}})
});
app.use("/api", apis);
// let server listen on the port
options = options || {};
server.listen(options.port || 3000);
// let socket.io handle sockets
io = io.listen(server, {log: false});
io.sockets.on('connection', function (s) {
// when connect, store the socket
socket = s;
// handme incoming data (client -> server)
socket.on('data', function (data) {
term.write(data);
});
socket.on('resize', function (data) {
term.resize(data[0], data[1]);
console.log(data)
});
// handle connection lost
socket.on('disconnect', function () {
socket = null;
});
// send buffer data to client
while (buff.length) {
socket.emit('data', buff.shift());
}
});
};
server.run({port: 8888});
server.run({port: 3000});
console.log('Please open your browser with http://127.0.0.1:8888');
console.log('Please open your browser with http://127.0.0.1:3000');
......@@ -4,7 +4,7 @@
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
......
{
"/api": {
"target": "http://localhost:3000",
"secure": false
},
"/socket.io/": {
"target": "http://localhost:3000",
"secure": false
}
}
......@@ -40,7 +40,7 @@ export class User {
date_joined: string;
last_login: string;
groups: Array<string>;
logined:boolean;
logined: boolean;
}
export class Group {
id: number;
......@@ -196,6 +196,7 @@ export class AppService {
DataStore.logined = false;
this._router.navigate(['login']);
DataStore.error['login'] = '后端错误,请重试';
return '后端错误,请重试';
},
() => {
if (DataStore.logined) {
......@@ -205,14 +206,16 @@ export class AppService {
this._router.navigate([DataStore.Path['name'], DataStore.Path['res']]);
}
} else {
DataStore.error['login'] = '请检查用户名和密码';
this._router.navigate(['login']);
DataStore.error['login'] = '请检查用户名和密码';
return '请检查用户名和密码';
}
// jQuery('angular2').show();
});
} else {
DataStore.error['login'] = '请检查用户名和密码';
return '请检查用户名和密码';
}
}
......
......@@ -18,6 +18,7 @@ declare let jQuery: any;
export class LoginComponent implements OnInit {
DataStore = DataStore;
loginBotton = 'login to your account';
constructor(private _appService: AppService,
private _logger: Logger,
......@@ -27,8 +28,7 @@ export class LoginComponent implements OnInit {
onSubmit() {
this._logger.log(DataStore);
this._appService.login(this.user);
this._logger.error(this._appService.login(this.user));
}
ngOnInit() {
......
......@@ -11,6 +11,6 @@
(ngEnter)="onSubmit()">
<span class="fa fa-key form-control-feedback"></span>
</div>
<button type="submit">login to your account</button>
<button type="submit">{{loginBotton}}</button>
</form>
</div>
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