From c1fb72f3935b1c83388491b10dd2820bc1b59899 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Fri, 30 Jan 2015 23:30:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E9=99=86=E9=80=80?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jumpserver/urls.py | 2 ++ jumpserver/views.py | 42 +++++++++++++++++++++++++++++++++++ juser/views.py | 4 ---- templates/base.html | 6 ++--- templates/juser/user_add.html | 8 ++++++- templates/login.html | 17 ++++++++------ templates/nav.html | 4 ++-- templates/nav_bar_header.html | 2 +- templates/nav_li_profile.html | 3 ++- 9 files changed, 69 insertions(+), 19 deletions(-) diff --git a/jumpserver/urls.py b/jumpserver/urls.py index 187362658..6a01353f1 100644 --- a/jumpserver/urls.py +++ b/jumpserver/urls.py @@ -8,6 +8,8 @@ urlpatterns = patterns('', (r'^$', 'jumpserver.views.base'), (r'^skin_config/$', 'jumpserver.views.skin_config'), (r'^base/$', 'jumpserver.views.base'), + (r'^login/$', 'jumpserver.views.login'), + (r'^logout/$', 'jumpserver.views.logout'), (r'^juser/', include('juser.urls')), (r'^jperm/', include('jperm.urls')), url(r'^jasset/', include('jasset.urls')), diff --git a/jumpserver/views.py b/jumpserver/views.py index ef9c9560c..9c50576a3 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -1,7 +1,16 @@ #coding: utf-8 +import hashlib + from django.http import HttpResponse from django.shortcuts import render_to_response +from django.http import HttpResponseRedirect + +from juser.models import User + + +def md5_crypt(string): + return hashlib.new("md5", string).hexdigest() def base(request): @@ -12,3 +21,36 @@ def skin_config(request): return render_to_response('skin_config.html') +def login(request): + """登录界面""" + if request.session.get('username'): + return HttpResponseRedirect('/') + if request.method == 'GET': + return render_to_response('login.html') + else: + username = request.POST.get('username') + password = request.POST.get('password') + user = User.objects.filter(username=username) + if user: + user = user[0] + if md5_crypt(password) == user.password: + request.session['username'] = username + if user.role == 'SU': + request.session['role'] = 2 + elif user.role == 'GA': + request.session['role'] = 1 + else: + request.session['role'] = 0 + return HttpResponseRedirect('/') + else: + error = '密码错误,请重新输入。' + else: + error = '用户不存在。' + return render_to_response('login.html', {'error': error}) + + +def logout(request): + request.session.delete() + return HttpResponseRedirect('/login/') + + diff --git a/juser/views.py b/juser/views.py index c34b3910d..875754003 100644 --- a/juser/views.py +++ b/juser/views.py @@ -33,10 +33,6 @@ if LDAP_ENABLE: LDAP_ROOT_PW = CONF.get('ldap', 'root_pw') -def md5_crypt(string): - return hashlib.new("md5", string).hexdigest() - - def gen_rand_pwd(num): """生成随机密码""" seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" diff --git a/templates/base.html b/templates/base.html index 8eb5d6e1e..95cc04d06 100644 --- a/templates/base.html +++ b/templates/base.html @@ -10,7 +10,7 @@ {% include 'link_css.html' %} - {% include 'script.html' %} + @@ -27,7 +27,7 @@ - +{# #} - + {% include 'script.html' %} diff --git a/templates/juser/user_add.html b/templates/juser/user_add.html index cede4b4d4..68bf3f1a5 100644 --- a/templates/juser/user_add.html +++ b/templates/juser/user_add.html @@ -119,7 +119,7 @@
- +
@@ -191,6 +191,12 @@ $('#userForm').validator({ ok: "", msg: {required: "必须填写"} }, + "email": { + rule: "required", + tip: "Email", + ok: "", + msg: {required: "必须填写"} + }, "role": { rule: "checked", tip: "角色", diff --git a/templates/login.html b/templates/login.html index 263cf07e2..df3b35f2b 100644 --- a/templates/login.html +++ b/templates/login.html @@ -7,7 +7,7 @@ JumpServer | Login - + @@ -22,22 +22,25 @@
-

JumpServer

+

-

Welcome to JumpServer

-
+ {% if error %} +
{{ error }}
+ {% endif %} +

Welcome to JumpServer

+
- +
- +
Forgot password?
-

Inspinia we app framework base on Bootstrap 3 © 2014

+

Copyright Jumpserver.org Organization © 2014-2015

diff --git a/templates/nav.html b/templates/nav.html index 9203ea643..c616bfe3f 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -34,8 +34,8 @@
  • 授权管理
  • diff --git a/templates/nav_bar_header.html b/templates/nav_bar_header.html index 50276b70f..7d4d3bb79 100644 --- a/templates/nav_bar_header.html +++ b/templates/nav_bar_header.html @@ -108,7 +108,7 @@
  • - + Log out
  • diff --git a/templates/nav_li_profile.html b/templates/nav_li_profile.html index c19e00b3f..09811e0c8 100644 --- a/templates/nav_li_profile.html +++ b/templates/nav_li_profile.html @@ -10,10 +10,11 @@
  • Contacts
  • Mailbox
  • -
  • Logout
  • +
  • Logout
  • JS+
    +