Merge pull request #254 from zhongyehong/master

add OPEN_REGISTRY to control whether allow user to register a new
This commit is contained in:
zhong yehong 2017-06-05 15:32:37 +08:00 committed by GitHub
commit e998ca6205
10 changed files with 107 additions and 17 deletions

View File

@ -88,6 +88,9 @@ Pay attention to the following settings:
- PUBLIC_IP : publick ip of this machine. If DISTRIBUTED_GATEWAY is True,
users' gateways can be setup on this machine. Users can visit this
machine by the public ip. default: IP of NETWORK_DEVICE.
- USER_IP : the ip of user server. default : localhost
- MASTER_IPS : tell the web server the ips of all the cluster master.
- OPEN_REGISTRY : whether allow user to register a new account.
## Start ##

View File

@ -63,9 +63,9 @@
# CONTAINER_MEMORY: memory quota of container, count in MB, default is 1000
# CONTAINER_MEMORY=1000
# DISKPOOL_SIZE: lvm group size, count in MB, default is 5000
# DISKPOOL_SIZE: lvm group size, count in MB, default is 10000
# Only valid with STORAGE=file
# DISKPOOL_SIZE=5000
# DISKPOOL_SIZE=10000
# ETCD: etcd address, default is localhost:2379
# For a muti hosts environment, the administrator should configure how
@ -172,3 +172,7 @@
# or to request master from users server. Please set the
# same value on each machine. Please don't use the default value.
# AUTH_KEY="docklet"
# OPEN_REGISTRY: whether allow user to register new account or not.
# default:False
# OPEN_REGISTRY:False

View File

@ -16,7 +16,7 @@ def getenv(key):
elif key == "CONTAINER_MEMORY":
return int(os.environ.get("CONTAINER_MEMORY", 1000))
elif key == "DISKPOOL_SIZE":
return int(os.environ.get("DISKPOOL_SIZE", 5000))
return int(os.environ.get("DISKPOOL_SIZE", 10000))
elif key == "ETCD":
return os.environ.get("ETCD", "localhost:2379")
elif key == "NETWORK_DEVICE":
@ -71,5 +71,7 @@ def getenv(key):
return int(os.environ.get("USER_PORT",9100))
elif key =="AUTH_KEY":
return os.environ.get("AUTH_KEY","docklet")
elif key =="OPEN_REGISTRY":
return os.environ.get("OPEN_REGISTRY","False")
else:
return os.environ.get(key,"")

View File

@ -849,11 +849,12 @@ class userManager:
if (user_check != None and user_check.status != "init"):
#for the activating form
return {"success":'false', "reason": "Unauthorized action"}
newuser = kwargs['user']
if (user_check != None and (user_check.status == "init")):
db.session.delete(user_check)
db.session.commit()
newuser = kwargs['user']
newuser.password = hashlib.sha512(newuser.password.encode('utf-8')).hexdigest()
else:
newuser.password = hashlib.sha512(newuser.password.encode('utf-8')).hexdigest()
db.session.add(newuser)
db.session.commit()

View File

@ -119,13 +119,13 @@ def register():
return json.dumps({'success':'false'})
newuser = G_usermgr.newuser()
newuser.username = request.form.get('username')
newuser.password = request.form.get('password')
newuser.e_mail = request.form.get('email')
newuser.student_number = request.form.get('studentnumber')
newuser.department = request.form.get('department')
newuser.nickname = request.form.get('truename')
newuser.truename = request.form.get('truename')
newuser.description = request.form.get('description')
newuser.password = request.form.get('password','')
newuser.e_mail = request.form.get('email','')
newuser.student_number = request.form.get('studentnumber','')
newuser.department = request.form.get('department','')
newuser.nickname = request.form.get('truename','')
newuser.truename = request.form.get('truename','')
newuser.description = request.form.get('description','')
newuser.status = "init"
newuser.auth_method = "local"
result = G_usermgr.register(user = newuser)
@ -141,6 +141,7 @@ def register():
newuser = G_usermgr.newuser()
newuser.username = cur_user.username
newuser.nickname = cur_user.truename
newuser.password = cur_user.password
newuser.status = 'applying'
newuser.user_group = cur_user.user_group
newuser.auth_method = cur_user.auth_method

View File

@ -41,12 +41,19 @@
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-12">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
</div>
</form>
{% if open_registry == "True" %}
<br/>
<div class="row">
<div class="col-xs-12">
<a href="/register/"><button class="btn btn-primary btn-block btn-flat">Register</button></a>
</div>
</div>
{% endif %}
<div class="social-auth-links text-center">
<!--p>- OR -</p>

View File

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Docklet | Login</title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.5 -->
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Ionicons -->
<link href="//cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet">
<!-- Theme style -->
<link rel="stylesheet" href="/static/dist/css/AdminLTE.min.css">
<link rel="shortcut icon" href="/static/img/favicon.ico">
</head>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<img src="/static/img/logo.png" class="logo-name" height="50%" width="50%">
<!--a href="/"><b>Docklet</b></a-->
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">An easy and quick way to launch your DISTRIBUTED applications!</p>
<form class="m-t" role="form" action="" id="activateForm" method="POST">
<div class="form-group">
<input type="text" class="form-control" placeholder="username" required="" name="username">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="password" required="" name="password">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="repeat password" required="" name="password2">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="E-mail" required="" name="email">
</div>
<div class="form-group">
<textarea class="form-control" name="description" form="activateForm" id="mDescription">
</textarea>
</div>
<div class="row">
<div class="col-xs-12">
<button type="submit" class="btn btn-primary btn-block btn-flat">Register</button>
</div>
</div>
<!--p class="text-muted text-center"><small>Do not have an account?</small></p-->
<!--a class="btn btn-sm btn-white btn-block" href="register.html">Create an account</a-->
</form>
</div>
<!-- /.login-box-body -->
</div>
<!-- /.login-box -->
<!-- jQuery 2.2.1 -->
<script src="//cdn.bootcss.com/jquery/2.2.1/jquery.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>

View File

@ -69,6 +69,7 @@ def home():
@app.route("/login/", methods=['GET', 'POST'])
def login():
loginView.open_registry = env.getenv("OPEN_REGISTRY")
return loginView.as_view()
@app.route(external_login_url, methods=['GET'])
@ -91,7 +92,7 @@ def logout():
return logoutView.as_view()
@app.route("/register/", methods=['GET', 'POST'])
@administration_required
#@administration_required
#now forbidden,only used by SEI & PKU Staffs and students.
#can be used by admin for testing
def register():

View File

@ -47,7 +47,7 @@ class loginView(normalView):
else:
link = ''
url = ''
return render_template(self.template_path, link = link, url = url)
return render_template(self.template_path, link = link, url = url, open_registry=self.open_registry)
@classmethod
def post(self):

View File

@ -1,6 +1,6 @@
from webViews.view import normalView
from webViews.dockletrequest import dockletRequest
from flask import redirect, request, abort
from flask import redirect, request, abort, render_template
class registerView(normalView):
template_path = 'register.html'
@ -11,4 +11,8 @@ class registerView(normalView):
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):
abort(500)
result = dockletRequest.unauthorizedpost('/register/', form)
return self.render('waitingRegister.html')
return redirect("/login/")
@classmethod
def get(self):
return render_template(self.template_path)