From 3ccb7740f2f671efecc711f35a9d11735d7d6f5d Mon Sep 17 00:00:00 2001 From: sxw Date: Tue, 4 Aug 2015 14:55:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E7=9A=84=E9=A1=B5=E9=9D=A2=E5=92=8Cjs?= 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