Skip to content

Commit 3cf3d48

Browse files
author
zhongyh16
committed
add OPEN_REGISTRY to control whether allow user to register a new
account.
1 parent 5426124 commit 3cf3d48

File tree

10 files changed

+107
-17
lines changed

10 files changed

+107
-17
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ Pay attention to the following settings:
8888
- PUBLIC_IP : publick ip of this machine. If DISTRIBUTED_GATEWAY is True,
8989
users' gateways can be setup on this machine. Users can visit this
9090
machine by the public ip. default: IP of NETWORK_DEVICE.
91+
- USER_IP : the ip of user server. default : localhost
92+
- MASTER_IPS : tell the web server the ips of all the cluster master.
93+
- OPEN_REGISTRY : whether allow user to register a new account.
9194

9295
## Start ##
9396

conf/docklet.conf.template

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
# CONTAINER_MEMORY: memory quota of container, count in MB, default is 1000
6464
# CONTAINER_MEMORY=1000
6565

66-
# DISKPOOL_SIZE: lvm group size, count in MB, default is 5000
66+
# DISKPOOL_SIZE: lvm group size, count in MB, default is 10000
6767
# Only valid with STORAGE=file
68-
# DISKPOOL_SIZE=5000
68+
# DISKPOOL_SIZE=10000
6969

7070
# ETCD: etcd address, default is localhost:2379
7171
# For a muti hosts environment, the administrator should configure how
@@ -172,3 +172,7 @@
172172
# or to request master from users server. Please set the
173173
# same value on each machine. Please don't use the default value.
174174
# AUTH_KEY="docklet"
175+
176+
# OPEN_REGISTRY: whether allow user to register new account or not.
177+
# default:False
178+
# OPEN_REGISTRY:False

src/env.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def getenv(key):
1616
elif key == "CONTAINER_MEMORY":
1717
return int(os.environ.get("CONTAINER_MEMORY", 1000))
1818
elif key == "DISKPOOL_SIZE":
19-
return int(os.environ.get("DISKPOOL_SIZE", 5000))
19+
return int(os.environ.get("DISKPOOL_SIZE", 10000))
2020
elif key == "ETCD":
2121
return os.environ.get("ETCD", "localhost:2379")
2222
elif key == "NETWORK_DEVICE":
@@ -71,5 +71,7 @@ def getenv(key):
7171
return int(os.environ.get("USER_PORT",9100))
7272
elif key =="AUTH_KEY":
7373
return os.environ.get("AUTH_KEY","docklet")
74+
elif key =="OPEN_REGISTRY":
75+
return os.environ.get("OPEN_REGISTRY","False")
7476
else:
7577
return os.environ.get(key,"")

src/userManager.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -849,11 +849,12 @@ def register(self, *args, **kwargs):
849849
if (user_check != None and user_check.status != "init"):
850850
#for the activating form
851851
return {"success":'false', "reason": "Unauthorized action"}
852+
newuser = kwargs['user']
852853
if (user_check != None and (user_check.status == "init")):
853854
db.session.delete(user_check)
854855
db.session.commit()
855-
newuser = kwargs['user']
856-
newuser.password = hashlib.sha512(newuser.password.encode('utf-8')).hexdigest()
856+
else:
857+
newuser.password = hashlib.sha512(newuser.password.encode('utf-8')).hexdigest()
857858
db.session.add(newuser)
858859
db.session.commit()
859860

user/user.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ def register():
119119
return json.dumps({'success':'false'})
120120
newuser = G_usermgr.newuser()
121121
newuser.username = request.form.get('username')
122-
newuser.password = request.form.get('password')
123-
newuser.e_mail = request.form.get('email')
124-
newuser.student_number = request.form.get('studentnumber')
125-
newuser.department = request.form.get('department')
126-
newuser.nickname = request.form.get('truename')
127-
newuser.truename = request.form.get('truename')
128-
newuser.description = request.form.get('description')
122+
newuser.password = request.form.get('password','')
123+
newuser.e_mail = request.form.get('email','')
124+
newuser.student_number = request.form.get('studentnumber','')
125+
newuser.department = request.form.get('department','')
126+
newuser.nickname = request.form.get('truename','')
127+
newuser.truename = request.form.get('truename','')
128+
newuser.description = request.form.get('description','')
129129
newuser.status = "init"
130130
newuser.auth_method = "local"
131131
result = G_usermgr.register(user = newuser)
@@ -141,6 +141,7 @@ def register():
141141
newuser = G_usermgr.newuser()
142142
newuser.username = cur_user.username
143143
newuser.nickname = cur_user.truename
144+
newuser.password = cur_user.password
144145
newuser.status = 'applying'
145146
newuser.user_group = cur_user.user_group
146147
newuser.auth_method = cur_user.auth_method

web/templates/login.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@
4141
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
4242
</div>
4343
<div class="row">
44-
4544
<div class="col-xs-12">
4645
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
4746
</div>
4847
</div>
4948
</form>
49+
{% if open_registry == "True" %}
50+
<br/>
51+
<div class="row">
52+
<div class="col-xs-12">
53+
<a href="/register/"><button class="btn btn-primary btn-block btn-flat">Register</button></a>
54+
</div>
55+
</div>
56+
{% endif %}
5057

5158
<div class="social-auth-links text-center">
5259
<!--p>- OR -</p>

web/templates/register.html

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>Docklet | Login</title>
7+
<!-- Tell the browser to be responsive to screen width -->
8+
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
9+
<!-- Bootstrap 3.3.5 -->
10+
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
11+
<!-- Font Awesome -->
12+
<link href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
13+
<!-- Ionicons -->
14+
<link href="//cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet">
15+
<!-- Theme style -->
16+
<link rel="stylesheet" href="/static/dist/css/AdminLTE.min.css">
17+
18+
<link rel="shortcut icon" href="/static/img/favicon.ico">
19+
20+
21+
</head>
22+
<body class="hold-transition login-page">
23+
<div class="login-box">
24+
<div class="login-logo">
25+
<img src="/static/img/logo.png" class="logo-name" height="50%" width="50%">
26+
<!--a href="/"><b>Docklet</b></a-->
27+
</div>
28+
<!-- /.login-logo -->
29+
<div class="login-box-body">
30+
<p class="login-box-msg">An easy and quick way to launch your DISTRIBUTED applications!</p>
31+
<form class="m-t" role="form" action="" id="activateForm" method="POST">
32+
<div class="form-group">
33+
<input type="text" class="form-control" placeholder="username" required="" name="username">
34+
</div>
35+
<div class="form-group">
36+
<input type="text" class="form-control" placeholder="password" required="" name="password">
37+
</div>
38+
<div class="form-group">
39+
<input type="text" class="form-control" placeholder="repeat password" required="" name="password2">
40+
</div>
41+
<div class="form-group">
42+
<input type="email" class="form-control" placeholder="E-mail" required="" name="email">
43+
</div>
44+
<div class="form-group">
45+
<textarea class="form-control" name="description" form="activateForm" id="mDescription">
46+
</textarea>
47+
</div>
48+
<div class="row">
49+
<div class="col-xs-12">
50+
<button type="submit" class="btn btn-primary btn-block btn-flat">Register</button>
51+
</div>
52+
</div>
53+
<!--p class="text-muted text-center"><small>Do not have an account?</small></p-->
54+
<!--a class="btn btn-sm btn-white btn-block" href="register.html">Create an account</a-->
55+
</form>
56+
</div>
57+
<!-- /.login-box-body -->
58+
</div>
59+
<!-- /.login-box -->
60+
61+
<!-- jQuery 2.2.1 -->
62+
<script src="//cdn.bootcss.com/jquery/2.2.1/jquery.min.js"></script>
63+
<!-- Bootstrap 3.3.5 -->
64+
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
65+
66+
</body>
67+
</html>

web/web.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def home():
6969

7070
@app.route("/login/", methods=['GET', 'POST'])
7171
def login():
72+
loginView.open_registry = env.getenv("OPEN_REGISTRY")
7273
return loginView.as_view()
7374

7475
@app.route(external_login_url, methods=['GET'])
@@ -91,7 +92,7 @@ def logout():
9192
return logoutView.as_view()
9293

9394
@app.route("/register/", methods=['GET', 'POST'])
94-
@administration_required
95+
#@administration_required
9596
#now forbidden,only used by SEI & PKU Staffs and students.
9697
#can be used by admin for testing
9798
def register():

web/webViews/authenticate/login.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get(self):
4747
else:
4848
link = ''
4949
url = ''
50-
return render_template(self.template_path, link = link, url = url)
50+
return render_template(self.template_path, link = link, url = url, open_registry=self.open_registry)
5151

5252
@classmethod
5353
def post(self):

web/webViews/authenticate/register.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from webViews.view import normalView
22
from webViews.dockletrequest import dockletRequest
3-
from flask import redirect, request, abort
3+
from flask import redirect, request, abort, render_template
44

55
class registerView(normalView):
66
template_path = 'register.html'
@@ -11,4 +11,8 @@ def post(self):
1111
if (request.form.get('username') == None or request.form.get('password') == None or request.form.get('password') != request.form.get('password2') or request.form.get('email') == None or request.form.get('description') == None):
1212
abort(500)
1313
result = dockletRequest.unauthorizedpost('/register/', form)
14-
return self.render('waitingRegister.html')
14+
return redirect("/login/")
15+
16+
@classmethod
17+
def get(self):
18+
return render_template(self.template_path)

0 commit comments

Comments
 (0)