Accept Merge Request #9 : (sxw-dev -> dev)

Merge Request: 增加了修改密码的页面和js
Created By: @esp
Accepted By: @esp
URL: https://coding.net/u/virusdefender/p/qduoj/git/merge/9
This commit is contained in:
esp 2015-08-04 15:02:10 +08:00
commit e75cd60741
7 changed files with 288 additions and 19 deletions

View File

@ -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);
}
}
})
});
});

View File

@ -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);
}
}
})
});
});

View File

@ -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",

View File

@ -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;
}
};
}));

View File

@ -7,5 +7,8 @@ define("validation",
'validator/stringLength',
'validator/date',
'validator/integer',
'validator/between'], function () {
'validator/between',
'validator/confirm'],
function () {
});

View File

@ -1,10 +1,34 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
{% extends "oj_base.html" %}
{% block body %}
<div class="container">
<div class="col-md-6 col-md-offset-3">
<h2 class="text-center">修改密码</h2>
</body>
</html>
<form id="change_password-form">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" class="form-control input-lg" id="username" name="username" placeholder="用户名"
autofocus>
</div>
<div class="form-group">
<label for="password">旧密码</label>
<input type="password" class="form-control input-lg" id="password" name="password" placeholder="密码">
</div>
<div class="form-group">
<label for="new_password">新密码</label>
<input type="password" class="form-control input-lg" id="new_password" name="new_password" placeholder="新密码">
</div>
<div class="form-group">
<label for="confirm_password">确认密码</label>
<input type="password" class="form-control input-lg" id="confirm_password" name="confirm_password" placeholder="确认密码">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">提交</button>
</div>
</form>
</div>
</div>
{% endblock %}
{% block js_block %}
<script src="/static/js/app/oj/account/change_password.js"></script>
{% endblock %}

View File

@ -1,10 +1,34 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
{% extends "oj_base.html" %}
{% block body %}
<div class="container">
<div class="col-md-6 col-md-offset-3">
<h2 class="text-center">用户注册</h2>
</body>
</html>
<form id="register-form">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" class="form-control input-lg" id="username" name="username" placeholder="用户名"
autofocus>
</div>
<div class="form-group">
<label for="real_name">真实姓名</label>
<input type="text" class="form-control input-lg" id="real_name" name="real_name" placeholder="真实姓名">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" class="form-control input-lg" id="password" name="password" placeholder="密码">
</div>
<div class="form-group">
<label for="confirm_password">确认密码</label>
<input type="password" class="form-control input-lg" id="confirm_password" name="confirm_password" placeholder="确认密码">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">提交</button>
</div>
</form>
</div>
</div>
{% endblock %}
{% block js_block %}
<script src="/static/js/app/oj/account/register.js"></script>
{% endblock %}