From 90eaadbb1c1efad809879d404d2df7ff50d45153 Mon Sep 17 00:00:00 2001 From: sxw Date: Mon, 3 Aug 2015 16:34:55 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B3=A8=E5=86=8C=E9=A1=B5=E9=9D=A2=E5=92=8C=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84urls=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/urls.py | 1 + template/oj/account/register.html | 42 ++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/oj/urls.py b/oj/urls.py index 260a42a..84b1363 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ url(r'^docs/', include('rest_framework_swagger.urls')), url(r'^admin/$', TemplateView.as_view(template_name="admin/index.html"), name="admin_index_page"), url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"), + url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="login_api"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="user_login_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), diff --git a/template/oj/account/register.html b/template/oj/account/register.html index 71ce692..a93014c 100644 --- a/template/oj/account/register.html +++ b/template/oj/account/register.html @@ -1,10 +1,34 @@ - - - - - - - +{% extends "oj_base.html" %} +{% block body %} +
+
+

用户注册

- - \ No newline at end of file +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+{% endblock %} +{% block js_block %} + +{% endblock %} \ No newline at end of file From 2454db54b0e725dcfd1b1e502c82da66b0727876 Mon Sep 17 00:00:00 2001 From: sxw Date: Mon, 3 Aug 2015 16:37:20 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E5=92=8Ctab=E6=B7=B7=E5=90=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oj/urls.py b/oj/urls.py index 84b1363..b308320 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -10,7 +10,7 @@ urlpatterns = [ url(r'^docs/', include('rest_framework_swagger.urls')), url(r'^admin/$', TemplateView.as_view(template_name="admin/index.html"), name="admin_index_page"), url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"), - url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), + url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="login_api"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="user_login_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), From 3ccb7740f2f671efecc711f35a9d11735d7d6f5d Mon Sep 17 00:00:00 2001 From: sxw Date: Tue, 4 Aug 2015 14:55:38 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E7=9A=84=E9=A1=B5=E9=9D=A2=E5=92=8C?= =?UTF-8?q?js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oj/urls.py | 1 + .../src/js/app/oj/account/change_password.js | 89 +++++++++++++++++++ static/src/js/config.js | 1 + .../lib/formValidation/validator/confirm.js | 34 +++++++ template/oj/account/change_password.html | 42 +++++++-- 5 files changed, 158 insertions(+), 9 deletions(-) create mode 100644 static/src/js/app/oj/account/change_password.js create mode 100644 static/src/js/lib/formValidation/validator/confirm.js diff --git a/oj/urls.py b/oj/urls.py index b308320..f9d4cbf 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -11,6 +11,7 @@ urlpatterns = [ url(r'^admin/$', TemplateView.as_view(template_name="admin/index.html"), name="admin_index_page"), url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"), url(r'^register/$', TemplateView.as_view(template_name="oj/account/register.html"), name="user_register_page"), + url(r'^change_password/$', TemplateView.as_view(template_name="oj/account/change_password.html"), name="user_change_password_page"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="login_api"), url(r'^api/login/$', UserLoginAPIView.as_view(), name="user_login_api"), url(r'^problem/(?P\d+)/$', "problem.views.problem_page", name="problem_page"), diff --git a/static/src/js/app/oj/account/change_password.js b/static/src/js/app/oj/account/change_password.js new file mode 100644 index 0000000..035e0d3 --- /dev/null +++ b/static/src/js/app/oj/account/change_password.js @@ -0,0 +1,89 @@ + +require(["jquery", "bs_alert", "validation"], function($, bs_alert){ + + + $("#change_password-form").formValidation({ + framework: "bootstrap", + fields: { + username: { + validators: { + notEmpty: { + message: "请填写用户名" + } + } + }, + password: { + validators: { + notEmpty: { + message: "请填写旧密码" + } + } + }, + new_password: { + validators: { + notEmpty: { + message: "请填写新密码" + }, + stringLength: { + min: 6, + max: 30, + message: '密码长度必须在6到30位之间' + }, + confirm: { + firstPassword: $("#new_password"), + secondPassword: $("#confirm_password"), + message: "两次输入的密码必须一致" + } + }, + onSuccess: function(e, data) { + + if (!data.fv.isValidField('confirm_password')) { + data.fv.revalidateField('confirm_password'); + } + } + + }, + confirm_password: { + validators: { + notEmpty: { + message: "请填写确认密码" + }, + confirm: { + firstPassword: $("#new_password"), + secondPassword: $("#confirm_password"), + message: "两次输入的密码必须一致" + } + }, + onSuccess: function(e, data) { + + if (!data.fv.isValidField('new_password')) { + data.fv.revalidateField('new_password'); + } + } + } + } + } + ).on('success.form.fv', function(e) { + e.preventDefault(); + var username = $("#username").val(); + var new_password = $("#new_password ").val(); + var password = $("#password").val(); + $.ajax({ + url: "/api/change_password/", + data: {username: username, new_password: new_password , old_password : password}, + dataType: "json", + method: "post", + success: function (data) { + + if(!data.code){ + window.location.href="/login/"; + } + else{ + bs_alert(data.data); + } + } + + }) + }); + +}); \ No newline at end of file diff --git a/static/src/js/config.js b/static/src/js/config.js index dc17a5a..fbeaa3a 100644 --- a/static/src/js/config.js +++ b/static/src/js/config.js @@ -25,6 +25,7 @@ var require = { "validator/date": "lib/formValidation/validator/date", "validator/integer": "lib/formValidation/validator/integer", "validator/between": "lib/formValidation/validator/between", + 'validator/confirm':"lib/formValidation/validator/confirm", //富文本编辑器 不要直接使用,而是使用上面的editor simditor: "lib/simditor/simditor", diff --git a/static/src/js/lib/formValidation/validator/confirm.js b/static/src/js/lib/formValidation/validator/confirm.js new file mode 100644 index 0000000..5d491ee --- /dev/null +++ b/static/src/js/lib/formValidation/validator/confirm.js @@ -0,0 +1,34 @@ +/** + * confirm validator + */ + +(function(root, factory) { + + "use strict"; + + // AMD module is defined + if (typeof define === "function" && define.amd) { + define("validator/confirm", ["jquery", "base"], factory); + } else { + // planted over the root! + factory(root.jQuery, root.FormValidation); + } + +}(this, function ($, FormValidation) { + FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { + 'en_US': { + confirm: { + 'default': 'Please input the same value' + } + } + }); + + FormValidation.Validator.confirm = { + + validate: function(validator, $field, options) { + if (options.firstPassword.val() == options.secondPassword.val() ||options.secondPassword.val()== '') + return true; + return false; + } + }; +})); diff --git a/template/oj/account/change_password.html b/template/oj/account/change_password.html index 71ce692..65de447 100644 --- a/template/oj/account/change_password.html +++ b/template/oj/account/change_password.html @@ -1,10 +1,34 @@ - - - - - - - +{% extends "oj_base.html" %} +{% block body %} +
+
+

修改密码

- - \ No newline at end of file +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+{% endblock %} +{% block js_block %} + +{% endblock %} \ No newline at end of file From 58a664af1b0852b95517c11cf85d8a04bc1e6770 Mon Sep 17 00:00:00 2001 From: sxw Date: Tue, 4 Aug 2015 14:56:17 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=B3=A8?= =?UTF-8?q?=E5=86=8Cjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/oj/account/register.js | 94 ++++++++++++++++++++++++ static/src/js/utils/validation.js | 5 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 static/src/js/app/oj/account/register.js diff --git a/static/src/js/app/oj/account/register.js b/static/src/js/app/oj/account/register.js new file mode 100644 index 0000000..0241698 --- /dev/null +++ b/static/src/js/app/oj/account/register.js @@ -0,0 +1,94 @@ +require(["jquery", "bs_alert", "validation"], function($, bs_alert){ + + $("#register-form") + .formValidation({ + framework: "bootstrap", + fields: { + username: { + validators: { + notEmpty: { + message: "请填写用户名" + }, + stringLength: { + min: 3, + max: 30, + message: '用户名长度必须在3到30位之间' + } + } + }, + password: { + validators: { + notEmpty: { + message: "请填写密码" + }, + stringLength: { + min: 6, + max: 30, + message: '密码长度必须在6到30位之间' + }, + confirm: { + firstPassword: $("#password"), + secondPassword: $("#confirm_password"), + message: "两次输入的密码必须一致" + } + }, + onSuccess: function(e, data) { + + if (!data.fv.isValidField('confirm_password')) { + data.fv.revalidateField('confirm_password'); + } + } + }, + real_name: { + validators: { + notEmpty: { + message: "请填写真实姓名" + } + }, + + }, + confirm_password: { + validators: { + notEmpty: { + message: "请填写确认密码" + }, + confirm: { + firstPassword: $("#password"), + secondPassword: $("#confirm_password"), + message: "两次输入的密码必须一致" + } + + }, + + onSuccess: function(e, data) { + + if (!data.fv.isValidField('password')) { + data.fv.revalidateField('password'); + } + } + } + } + } + ).on('success.form.fv', function(e) { + e.preventDefault(); + var username = $("#username").val(); + var real_name = $("#real_name").val(); + var password = $("#password").val(); + $.ajax({ + url: "/api/register/", + data: {username: username, real_name: real_name, password: password}, + dataType: "json", + method: "post", + success: function (data) { + if(!data.code){ + window.location.href="/login/"; + } + else{ + bs_alert(data.data); + } + } + + }) + }); + +}); \ No newline at end of file diff --git a/static/src/js/utils/validation.js b/static/src/js/utils/validation.js index ab3c2e7..b79bd81 100644 --- a/static/src/js/utils/validation.js +++ b/static/src/js/utils/validation.js @@ -7,5 +7,8 @@ define("validation", 'validator/stringLength', 'validator/date', 'validator/integer', - 'validator/between'], function () { + 'validator/between', + 'validator/confirm'], + function () { + }); \ No newline at end of file