Skip to content

Commit a99c772

Browse files
committed
add comment
1 parent 245e2bd commit a99c772

File tree

10 files changed

+120
-116
lines changed

10 files changed

+120
-116
lines changed

DockerM_Web/app/api/response.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def getAllContainerList(saltstack_id):
7777
def containerControl(control_type):
7878
print control_type
7979
user = getUser(session['user_id'])
80-
if control_type == 'start_container':
80+
if control_type == 'start':
8181
saltstack_id = getHostInfoByContainerID(request.form['container_id']).saltstack_id
8282
if (checkHost(saltstack_id)):
8383
pushMsg(control_type, user.username, {"container_id": request.form['container_id']}, getHostInfoByContainerID(request.form['container_id']).saltstack_id).push()
@@ -86,7 +86,7 @@ def containerControl(control_type):
8686
0:12] + u'] 成功!',})
8787
else:
8888
return jsonify({'status': 'error', 'title': '操作发送失败!', 'text': u'失败!' + saltstack_id + u' 主机无法访问!'})
89-
elif control_type == 'stop_container':
89+
elif control_type == 'stop':
9090
saltstack_id = getHostInfoByContainerID(request.form['container_id']).saltstack_id
9191
print saltstack_id
9292
if (checkHost(saltstack_id)):

DockerM_Web/app/auth/errors.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
from flask import render_template
33
from . import dockermAuth
44

5+
56
@dockermAuth.app_errorhandler(404)
67
def page_not_found():
7-
return render_template('errorPage/404.html'), 404
8+
return render_template('errorPage/404.html'), 404
9+
810

911
@dockermAuth.app_errorhandler(500)
1012
def internal_server_error():
11-
return render_template('errorPage/500.html'), 500
13+
return render_template('errorPage/500.html'), 500

DockerM_Web/app/auth/views.py

+34-26
Original file line numberDiff line numberDiff line change
@@ -4,75 +4,83 @@
44
from flask_login import login_user, logout_user, current_user, login_required
55
from . import dockermAuth
66
from .. import lm
7-
from .forms import LoginForm,RegisterForm
7+
from .forms import LoginForm, RegisterForm
88
from ..lib.dbModel import User
9-
from ..lib.dbController import checkUserIsRegister,checkEmailIsRegister,createUser
9+
from ..lib.dbController import checkUserIsRegister, checkEmailIsRegister, createUser
1010
from werkzeug.security import check_password_hash
1111

12+
1213
@dockermAuth.before_request
1314
def before_request():
1415
g.user = current_user
1516

17+
1618
@lm.user_loader
1719
def load_user(id):
1820
user = User.query.filter_by(id=id).first()
1921
return user
2022

21-
@dockermAuth.route('/login', methods=['GET','POST'])
23+
24+
@dockermAuth.route('/login', methods=['GET', 'POST'])
2225
def login():
2326
# 已登陆
2427
print current_user
2528
if g.user is not None and g.user.is_authenticated:
2629
session['_fresh'] = False
2730
return redirect(url_for('dockerm.index'))
28-
if g.user.is_active == True:
31+
if g.user.is_active is True:
2932
print('active is True')
3033
else:
3134
pass
3235
# 提示尚未登陆
3336
# flash('no_login')
34-
loginForm = LoginForm()
35-
registerForm = RegisterForm()
36-
if loginForm.validate_on_submit():
37-
user = User.query.filter_by(username=loginForm.username.data).first()
38-
if ((user is not None) and check_password_hash(user.password,loginForm.password.data)) and user.username == loginForm.username.data:
39-
# remember=loginForm.remember_me.data
40-
login_user(user, remember = True)
37+
loginform = LoginForm()
38+
registerform = RegisterForm()
39+
if loginform.validate_on_submit():
40+
user = User.query.filter_by(username=loginform.username.data).first()
41+
if ((user is not None) and check_password_hash(user.password,
42+
loginform.password.data)):
43+
# remember=loginform.remember_me.data
44+
login_user(user, remember=True)
4145
return redirect(request.args.get("next") or url_for('dockerm.index'))
4246
else:
4347
flash('login_failed')
4448
return render_template('login.html',
45-
loginForm=loginForm,
46-
registerForm=registerForm,
49+
loginform=loginform,
50+
registerform=registerform,
4751
username=session.get('username'),
4852
known=session.get('known', False),
4953
current_time=datetime.utcnow())
5054

51-
@dockermAuth.route('/logout',methods=['GET'])
55+
56+
@dockermAuth.route('/logout', methods=['GET'])
5257
@login_required
5358
def login_out():
5459
logout_user()
5560
flash('logout')
5661
return redirect(url_for('dockermAuth.login'))
5762

58-
@dockermAuth.route('/register',methods=['POST'])
63+
64+
@dockermAuth.route('/register', methods=['POST'])
5965
def register():
60-
registerForm = RegisterForm()
61-
cuir = checkUserIsRegister(username=registerForm.username.data)
62-
ceir = checkEmailIsRegister(registerForm.email.data)
63-
if (cuir and ceir) and (((registerForm.password.validate('Length') and registerForm.username.validate('Length')) and (registerForm.password.validate('Regexp') and registerForm.email.validate('Email')))):
64-
if createUser(registerForm.username.data, password=registerForm.password.data, email=registerForm.email.data,level=1):
65-
flash('register_succeed',u'请登录!')
66+
registerform = RegisterForm()
67+
cuir = checkUserIsRegister(username=registerform.username.data)
68+
ceir = checkEmailIsRegister(registerform.email.data)
69+
if (cuir and ceir) and (((registerform.password.validate('Length') and registerform.username.validate(
70+
'Length')) and (registerform.password.validate('Regexp') and registerform.email.validate('Email')))):
71+
if createUser(registerform.username.data, password=registerform.password.data, email=registerform.email.data,
72+
level=1):
73+
flash('register_succeed', u'请登录!')
6674
return redirect((url_for('dockermAuth.login')))
6775
else:
68-
flash('error',u'未知错误!请联系管理员!')
76+
flash('error', u'未知错误!请联系管理员!')
6977
return redirect((url_for('dockermAuth.login', _anchor='signup')))
7078
else:
71-
msg = registerForm.errors
79+
msg = registerform.errors
7280
if len(msg) > 0:
73-
flash('register_failed',msg[msg.keys()[0]][0])
81+
flash('register_failed', msg[msg.keys()[0]][0])
7482
elif not cuir:
75-
flash('register_failed',u'账号已存在!')
83+
flash('register_failed', u'账号已存在!')
7684
elif not ceir:
7785
flash('register_failed', u'邮箱已存在!')
78-
return redirect((url_for('dockermAuth.login',_anchor='signup')))
86+
return redirect((url_for('dockermAuth.login', _anchor='signup')))

DockerM_Web/app/main/forms.py

-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,3 @@
22
from flask_wtf import FlaskForm
33
from wtforms import StringField, SubmitField, PasswordField, BooleanField
44
from wtforms.validators import DataRequired
5-
6-
7-
class RabbitForm(FlaskForm):
8-
RABBIT_HOST = StringField(validators=[DataRequired(u'请输入 RabbitMQ 主机地址!')])
9-
RABBIT_HOST_USERNAME = StringField(validators=[DataRequired(u'请输入 RabbitMQ 用户名!')])
10-
RABBIT_HOST_PASSWORD = PasswordField(validators=[DataRequired(u'请输入 RabbitMQ 密码!')])
11-
register = SubmitField(u'保存')

DockerM_Web/app/static/js/control.js

+33-31
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
$(document).ready(function(){
2+
23
function getRootPath() {
34
var pathName = window.location.pathname.substring(1);
45
var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
56
return window.location.protocol + '//' + window.location.host + '/'+ webName;
67
}
8+
79
var stack_bar_top = {"dir1": "up", "dir2": "left", "push": "top", "spacing1": 0, "spacing2": 15};
810
$('.startbtn').click(function () {
911
container_id = $(this).attr('value');
1012
container_name = $(this).attr('data-name');
1113
$.ajax({
12-
url: "/control/container/start_container", //请求的url地址
13-
dataType: "json", //返回格式为json
14-
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
15-
data: { "container_id": container_id, "container_name": container_name }, //参数值
16-
type: "POST", //请求方式
14+
url: "/control/container/start_container",
15+
dataType: "json",
16+
async: true,
17+
data: { "container_id": container_id, "container_name": container_name },
18+
type: "POST",
1719
success: function(req) {
1820
createPNotify(req['title'],req['text'],req['status']);
1921
},error: function (req) {
@@ -26,11 +28,11 @@ $(document).ready(function(){
2628
container_id = $(this).attr('value');
2729
container_name = $(this).data('name');
2830
$.ajax({
29-
url: "/control/container/stop_container", //请求的url地址
30-
dataType: "json", //返回格式为json
31-
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
32-
data: { "container_id": container_id, "container_name": container_name }, //参数值
33-
type: "POST", //请求方式
31+
url: "/control/container/stop_container",
32+
dataType: "json",
33+
async: true,
34+
data: { "container_id": container_id, "container_name": container_name },
35+
type: "POST",
3436
success: function(req) {
3537
createPNotify(req['title'],req['text'],req['status']);
3638
},error: function (req) {
@@ -44,11 +46,11 @@ $(document).ready(function(){
4446
shortID = container_id.substring(0,12)
4547
$(this).children('span').text('容器恢复中...');
4648
$.ajax({
47-
url: "/container/control/unpause", //请求的url地址
48-
dataType: "json", //返回格式为json
49-
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
50-
data: { "container_id": container_id }, //参数值
51-
type: "POST", //请求方式
49+
url: "/container/control/unpause",
50+
dataType: "json",
51+
async: true,
52+
data: { "container_id": container_id },
53+
type: "POST",
5254
success: function(req) {
5355
createPNotify(req['title'],req['text'],req['status']);
5456
},error: function (req) {
@@ -62,11 +64,11 @@ $(document).ready(function(){
6264
shortID = container_id.substring(0,12)
6365
$(this).children('span').text('容器暂停中...');
6466
$.ajax({
65-
url: "/container/control/pause", //请求的url地址
66-
dataType: "json", //返回格式为json
67-
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
68-
data: { "container_id": container_id }, //参数值
69-
type: "POST", //请求方式
67+
url: "/container/control/pause",
68+
dataType: "json",
69+
async: true,
70+
data: { "container_id": container_id },
71+
type: "POST",
7072
success: function(req) {
7173
createPNotify(req['title'],req['text'],req['status']);
7274
},error: function (req) {
@@ -80,11 +82,11 @@ $(document).ready(function(){
8082
shortID = container_id.substring(0,12)
8183
$(this).children('span').text('容器删除中...');
8284
$.ajax({
83-
url: "/container/control/delete", //请求的url地址
84-
dataType: "json", //返回格式为json
85-
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
86-
data: { "container_id": container_id }, //参数值
87-
type: "POST", //请求方式
85+
url: "/container/control/delete",
86+
dataType: "json",
87+
async: true,
88+
data: { "container_id": container_id },
89+
type: "POST",
8890
success: function(req) {
8991
createPNotify(req['title'],req['text'],req['status']);
9092
},error: function (req) {
@@ -97,11 +99,11 @@ $(document).ready(function(){
9799
container_id = $(this).attr('value');
98100
container_name = $(this).attr('data-name');
99101
$.ajax({
100-
url: "/control/container/follow", //请求的url地址
101-
dataType: "json", //返回格式为json
102-
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
103-
data: { "container_id": container_id }, //参数值
104-
type: "POST", //请求方式
102+
url: "/control/container/follow",
103+
dataType: "json",
104+
async: true,
105+
data: { "container_id": container_id },
106+
type: "POST",
105107
success: function(req) {
106108
createPNotify(req['title'],req['text'],req['status']);
107109
}
@@ -130,7 +132,7 @@ $(document).ready(function(){
130132
});
131133

132134
$('.refreshbtn').click(function () {
133-
alert('ok');
135+
134136
});
135137

136138
$('#addHost_btn').click(function (){

DockerM_Web/app/templates/containers.html

+10-9
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ <h5 style="padding:15px 0 0 10px;font-weight: bold;">端口映射</h5>
406406
var env_list = new Array();
407407

408408

409-
var host = $('#host_list_select');
410-
var image = $('#image_list_select');
411-
var container = $('#container_list_select');
409+
var host = $("#host_list_select");
410+
var image = $("#image_list_select");
411+
var container = $("#container_list_select");
412412
//获取主机信息,设置主机下拉框
413-
$.getJSON('/api/get/hosts/', function (data) {
413+
$.getJSON("/api/get/hosts/", function (data) {
414414
host.empty();
415415
host.select2({
416416
data: data,
@@ -421,7 +421,7 @@ <h5 style="padding:15px 0 0 10px;font-weight: bold;">端口映射</h5>
421421
return format;
422422
},
423423
templateSelection: function (repo){
424-
$.getJSON('/api/get/images/'+repo.text, function (data) {
424+
$.getJSON("/api/get/images/"+repo.text, function (data) {
425425
image.empty();
426426
image.select2({
427427
data: data,
@@ -444,7 +444,7 @@ <h5 style="padding:15px 0 0 10px;font-weight: bold;">端口映射</h5>
444444
}
445445
});
446446
});
447-
$.getJSON('/api/get/containers/'+repo.text, function (data) {
447+
$.getJSON("/api/get/containers/"+repo.text, function (data) {
448448
container.empty();
449449
container.select2({
450450
data: data,
@@ -595,19 +595,23 @@ <h5 style="padding:15px 0 0 10px;font-weight: bold;">端口映射</h5>
595595
});
596596

597597
$("#add_link").click(function () {
598+
598599
var alias = null;
600+
599601
try {
600602
var container_name = container.select2("data")[0].text;
601603
}
602604
catch(err) {
603605
showError($("#add_link"), $("#link_list"), 'container_isset', '请选择容器!');
604606
return false;
605607
}
608+
606609
if($("#link_container_alias").val() != ""){
607610
alias = $("#link_container_alias").val();
608611
}else{
609612
alias = container_name;
610613
}
614+
611615
if(link_list.length == 0){
612616
$("#link_list").append("<span class='tag'><span data-container-name='"+container_name+"' data-alias='"+alias+"' style='padding-right:8px;'>"+container_name+"<span class='alias'>["+alias+"]</span></span><i class='remove_tag fa fa-close' title='删除链接'></i></span>");
613617
{# $("#link_list").children('.tag').on("click",".remove_tag",function(){#}
@@ -679,9 +683,6 @@ <h5 style="padding:15px 0 0 10px;font-weight: bold;">端口映射</h5>
679683
}
680684
}
681685

682-
683-
$(".remove_tag").click(function(){alert("ok!")});
684-
685686
});
686687
</script>
687688
{% endblock %}

DockerM_Web/app/templates/login.html

+9-9
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@
9696
<section class="login_content">
9797
<form method="post" action="/login" role="form">
9898
<h1 style="margin-bottom: 60px;">登陆 DockerM </h1>
99-
{{ loginForm.csrf_token }}
99+
{{ loginform.csrf_token }}
100100
<div>
101-
{{ loginForm.username(id='username',placeholder='用户名',class='form-control') }}
101+
{{ loginform.username(id='username',placeholder='用户名',class='form-control') }}
102102
</div>
103103
<div>
104-
{{ loginForm.password(id='password',placeholder='密码',class='form-control') }}
104+
{{ loginform.password(id='password',placeholder='密码',class='form-control') }}
105105
</div>
106106
<div style="margin: 0 auto;">
107-
{{ loginForm.login(class='btn btn-default submit') }}
107+
{{ loginform.login(class='btn btn-default submit') }}
108108
</div>
109109
<div>
110110
</div>
@@ -128,18 +128,18 @@ <h1 style="margin-bottom: 60px;">登陆 DockerM </h1>
128128
<section class="login_content">
129129
<form method="post" action="/register" role="form">
130130
<h1>注册</h1>
131-
{{ registerForm.csrf_token }}
131+
{{ registerform.csrf_token }}
132132
<div>
133-
{{ registerForm.username(id='username',placeholder='用户名',class='form-control') }}
133+
{{ registerform.username(id='username',placeholder='用户名',class='form-control') }}
134134
</div>
135135
<div>
136-
{{ registerForm.email(id='email',placeholder='邮箱',class='form-control') }}
136+
{{ registerform.email(id='email',placeholder='邮箱',class='form-control') }}
137137
</div>
138138
<div>
139-
{{ registerForm.password(id='password',placeholder='密码',class='form-control') }}
139+
{{ registerform.password(id='password',placeholder='密码',class='form-control') }}
140140
</div>
141141
<div>
142-
{{ registerForm.register(class='btn btn-default submit') }}
142+
{{ registerform.register(class='btn btn-default submit') }}
143143
</div>
144144

145145
<div class="clearfix"></div>

0 commit comments

Comments
 (0)