diff --git a/account/serializers.py b/account/serializers.py index 358ced7..9a43457 100644 --- a/account/serializers.py +++ b/account/serializers.py @@ -26,7 +26,7 @@ class UserRegisterSerializer(serializers.Serializer): class UserChangePasswordSerializer(serializers.Serializer): username = serializers.CharField(max_length=30) - old_password = serializers.CharField(max_length=30, min_length=6) + old_password = serializers.CharField() new_password = serializers.CharField(max_length=30, min_length=6) diff --git a/judge/judger_controller/celery.py b/judge/judger_controller/celery.py index 6befedf..5b90bdb 100644 --- a/judge/judger_controller/celery.py +++ b/judge/judger_controller/celery.py @@ -3,8 +3,7 @@ from __future__ import absolute_import from celery import Celery from .settings import redis_config -app = Celery("judge", broker="redis://" + - redis_config["host"] + ":" + - str(redis_config["port"]) + - "/" + str(redis_config["db"]), +app = Celery("judge", broker='redis://%s:%s/%s' % (redis_config["host"], redis_config["port"], redis_config["db"]), include=["judge.judger_controller.tasks"]) + +Celery().conf.update(CELERY_ACCEPT_CONTENT = ['json']) \ No newline at end of file diff --git a/judge/judger_controller/settings.py b/judge/judger_controller/settings.py index 7964832..2c69d80 100644 --- a/judge/judger_controller/settings.py +++ b/judge/judger_controller/settings.py @@ -1,6 +1,6 @@ # coding=utf-8 redis_config = { - "host": "121.42.196.141", + "host": "121.42.32.129", "port": 6379, "db": 0 } diff --git a/oj/local_settings.py b/oj/local_settings.py index 7963e7a..2d84f67 100644 --- a/oj/local_settings.py +++ b/oj/local_settings.py @@ -18,7 +18,7 @@ DATABASES = { # 这是web 服务器连接到mongodb 的地址 MONGODB = { - 'HOST': '121.42.196.141', + 'HOST': '121.42.32.129', 'USERNAME': 'root', 'PASSWORD': 'root', 'PORT': 27017 diff --git a/static/src/js/app/oj/account/change_password.js b/static/src/js/app/oj/account/change_password.js index 8129fb1..ba88f5f 100644 --- a/static/src/js/app/oj/account/change_password.js +++ b/static/src/js/app/oj/account/change_password.js @@ -1,68 +1,25 @@ -require(["jquery", "bsAlert", "csrfToken", "formValidation"], function ($, bsAlert, csrfTokenHeader) { - $("#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位之间' - } - }, - onSuccess: function (e, data) { - data.fv.revalidateField('confirm_password'); - } - }, - confirm_password: { - validators: { - notEmpty: { - message: "请填写确认密码" - }, - confirm: { - original: $("#new_password"), - message: "两次输入的密码必须一致" - } - } +require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, csrfTokenHeader) { + + $('form').validator().on('submit', function (e) { + e.preventDefault(); + var username = $("#username").val(); + var newPassword = $("#new_password ").val(); + var password = $("#password").val(); + $.ajax({ + beforeSend: csrfTokenHeader, + url: "/api/change_password/", + data: {username: username, new_password: newPassword, old_password: password}, + dataType: "json", + method: "post", + success: function (data) { + if (!data.code) { + window.location.href = "/login/"; + } + else { + bsAlert(data.data); } } - } - ).on('success.form.fv', function (e) { - e.preventDefault(); - var username = $("#username").val(); - var newPassword = $("#new_password ").val(); - var password = $("#password").val(); - $.ajax({ - beforeSend: csrfTokenHeader, - url: "/api/change_password/", - data: {username: username, new_password: newPassword, old_password: password}, - dataType: "json", - method: "post", - success: function (data) { - if (!data.code) { - window.location.href = "/login/"; - } - else { - bsAlert(data.data); - } - } - }) }); + return false; + }); }); \ No newline at end of file diff --git a/static/src/js/app/oj/account/login.js b/static/src/js/app/oj/account/login.js index ca84975..5ef83b9 100644 --- a/static/src/js/app/oj/account/login.js +++ b/static/src/js/app/oj/account/login.js @@ -1,26 +1,6 @@ -require(["jquery", "bsAlert", "csrfToken", "formValidation"], function ($, bsAlert, csrfTokenHeader) { - $("#login-form") - .formValidation({ - framework: "bootstrap", - fields: { - username: { - validators: { - notEmpty: { - message: "请填写用户名" - } - } - }, - password: { - validators: { - notEmpty: { - message: "请填写密码" - } - } - } - } - } - ).on('success.form.fv', function (e) { - e.preventDefault(); +require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, csrfTokenHeader) { + $('form').validator().on('submit', function (e) { + if (!e.isDefaultPrevented()) { var username = $("#username").val(); var password = $("#password").val(); $.ajax({ @@ -38,6 +18,8 @@ require(["jquery", "bsAlert", "csrfToken", "formValidation"], function ($, bsAle } } - }) - }); + }); + return false; + } + }) }); \ No newline at end of file diff --git a/static/src/js/app/oj/account/register.js b/static/src/js/app/oj/account/register.js index bd00fb8..9537fdb 100644 --- a/static/src/js/app/oj/account/register.js +++ b/static/src/js/app/oj/account/register.js @@ -1,83 +1,12 @@ -require(["jquery", "bsAlert", "csrfToken", "validation"], function ($, bsAlert, csrfTokenHeader) { - $("#register-form") - .formValidation({ - framework: "bootstrap", - fields: { - username: { - validators: { - notEmpty: { - message: "请填写用户名" - }, - stringLength: { - min: 3, - max: 30, - message: '用户名长度必须在3到30位之间' - }, - remote: { - message: "用户名已存在", - url: "/api/username_check/", - field: 'username' - } - } - }, - password: { - validators: { - notEmpty: { - message: "请填写密码" - }, - stringLength: { - min: 6, - max: 30, - message: '密码长度必须在6到30位之间' - } - }, - onSuccess: function (e, data) { - data.fv.revalidateField('confirm_password'); - } - }, - real_name: { - validators: { - notEmpty: { - message: "请填写真实姓名" - } - } - }, - confirm_password: { - validators: { - notEmpty: { - message: "请填写确认密码" - }, - confirm: { - original: $("#password"), - message: "两次输入的密码必须一致" - } - } - }, - email: { - validators: { - notEmpty: { - message: "请填写电子邮箱邮箱地址" - }, - emailAddress: { - message: "请填写有效的邮箱地址" - }, - remote: { - message: "您已经注册过了", - url: "/api/email_check/", - field: 'email' - } - } - } - } - } - ).on('success.form.fv', function (e) { - e.preventDefault(); +require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, csrfTokenHeader) { + $('form').validator().on('submit', function (e) { + if (!e.isDefaultPrevented()) { var username = $("#username").val(); var realName = $("#real_name").val(); var password = $("#password").val(); var email = $("#email").val(); $.ajax({ - beforeSend: csrfHeader, + beforeSend: csrfTokenHeader, url: "/api/register/", data: {username: username, real_name: realName, password: password, email: email}, dataType: "json", @@ -90,6 +19,8 @@ require(["jquery", "bsAlert", "csrfToken", "validation"], function ($, bsAlert, bsAlert(data.data); } } - }) - }); + }); + return false; + } + }) }); \ No newline at end of file diff --git a/static/src/js/app/oj/problem/problem.js b/static/src/js/app/oj/problem/problem.js index 8e107bb..5b23c75 100644 --- a/static/src/js/app/oj/problem/problem.js +++ b/static/src/js/app/oj/problem/problem.js @@ -53,7 +53,14 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirro return html; } + var counter = 0; + function getResult() { + if(counter++ > 10){ + hideLoading(); + bsAlert("抱歉,服务器可能出现了故障,请稍后到我的提交列表中查看"); + return; + } $.ajax({ url: "/api/submission/?submission_id=" + submissionId, method: "get", @@ -85,7 +92,7 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert"], function ($, codeMirro showLoading(); if(!code.trim()){ - bs_alert("请填写代码!"); + bsAlert("请填写代码!"); hideLoading(); return false; } diff --git a/static/src/js/config.js b/static/src/js/config.js index d74fcdd..8b14e0e 100644 --- a/static/src/js/config.js +++ b/static/src/js/config.js @@ -19,6 +19,7 @@ var require = { jqueryUI: "lib/jqueryUI/jquery-ui", bootstrap: "lib/bootstrap/bootstrap", datetimePicker: "lib/datetime_picker/bootstrap-datetimepicker.zh-CN", + validator: "lib/validator/validator", // ------ 下面写的都不要直接用,而是使用上面的封装版本 ------ @@ -55,6 +56,7 @@ var require = { shim: { bootstrap: {deps: ["jquery"]}, _datetimePicker: {dep: ["jquery"]}, - datetimePicker: {deps: ["_datetimePicker"]} + datetimePicker: {deps: ["_datetimePicker"]}, + validator: ["jquery"] } }; \ No newline at end of file diff --git a/static/src/js/lib/validator/validator.js b/static/src/js/lib/validator/validator.js new file mode 100644 index 0000000..687d983 --- /dev/null +++ b/static/src/js/lib/validator/validator.js @@ -0,0 +1,325 @@ +/* ======================================================================== + * Bootstrap (plugin): validator.js v0.9.0 + * ======================================================================== + * The MIT License (MIT) + * + * Copyright (c) 2015 Cina Saffary. + * Made by @1000hz in the style of Bootstrap 3 era @fat + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * ======================================================================== */ + + ++function ($) { + 'use strict'; + + // VALIDATOR CLASS DEFINITION + // ========================== + + var Validator = function (element, options) { + this.$element = $(element) + this.options = options + + options.errors = $.extend({}, Validator.DEFAULTS.errors, options.errors) + + for (var custom in options.custom) { + if (!options.errors[custom]) throw new Error('Missing default error message for custom validator: ' + custom) + } + + $.extend(Validator.VALIDATORS, options.custom) + + this.$element.attr('novalidate', true) // disable automatic native validation + this.toggleSubmit() + + this.$element.on('input.bs.validator change.bs.validator focusout.bs.validator', $.proxy(this.validateInput, this)) + this.$element.on('submit.bs.validator', $.proxy(this.onSubmit, this)) + + this.$element.find('[data-match]').each(function () { + var $this = $(this) + var target = $this.data('match') + + $(target).on('input.bs.validator', function (e) { + $this.val() && $this.trigger('input.bs.validator') + }) + }) + } + + Validator.INPUT_SELECTOR = ':input:not([type="submit"], button):enabled:visible' + + Validator.DEFAULTS = { + delay: 500, + html: false, + disable: true, + custom: {}, + errors: { + match: 'Does not match', + minlength: 'Not long enough' + }, + feedback: { + success: 'glyphicon-ok', + error: 'glyphicon-remove' + } + } + + Validator.VALIDATORS = { + 'native': function ($el) { + var el = $el[0] + return el.checkValidity ? el.checkValidity() : true + }, + 'match': function ($el) { + var target = $el.data('match') + return !$el.val() || $el.val() === $(target).val() + }, + 'minlength': function ($el) { + var minlength = $el.data('minlength') + return !$el.val() || $el.val().length >= minlength + } + } + + Validator.prototype.validateInput = function (e) { + var $el = $(e.target) + var prevErrors = $el.data('bs.validator.errors') + var errors + + if ($el.is('[type="radio"]')) $el = this.$element.find('input[name="' + $el.attr('name') + '"]') + + this.$element.trigger(e = $.Event('validate.bs.validator', {relatedTarget: $el[0]})) + + if (e.isDefaultPrevented()) return + + var self = this + + this.runValidators($el).done(function (errors) { + $el.data('bs.validator.errors', errors) + + errors.length ? self.showErrors($el) : self.clearErrors($el) + + if (!prevErrors || errors.toString() !== prevErrors.toString()) { + e = errors.length + ? $.Event('invalid.bs.validator', {relatedTarget: $el[0], detail: errors}) + : $.Event('valid.bs.validator', {relatedTarget: $el[0], detail: prevErrors}) + + self.$element.trigger(e) + } + + self.toggleSubmit() + + self.$element.trigger($.Event('validated.bs.validator', {relatedTarget: $el[0]})) + }) + } + + + Validator.prototype.runValidators = function ($el) { + var errors = [] + var deferred = $.Deferred() + var options = this.options + + $el.data('bs.validator.deferred') && $el.data('bs.validator.deferred').reject() + $el.data('bs.validator.deferred', deferred) + + function getErrorMessage(key) { + return $el.data(key + '-error') + || $el.data('error') + || key == 'native' && $el[0].validationMessage + || options.errors[key] + } + + $.each(Validator.VALIDATORS, $.proxy(function (key, validator) { + if (($el.data(key) || key == 'native') && !validator.call(this, $el)) { + var error = getErrorMessage(key) + !~errors.indexOf(error) && errors.push(error) + } + }, this)) + + if (!errors.length && $el.val() && $el.data('remote')) { + this.defer($el, function () { + var data = {} + data[$el.attr('name')] = $el.val() + $.get($el.data('remote'), data) + .fail(function (jqXHR, textStatus, error) { errors.push(getErrorMessage('remote') || error) }) + .always(function () { deferred.resolve(errors)}) + }) + } else deferred.resolve(errors) + + return deferred.promise() + } + + Validator.prototype.validate = function () { + var delay = this.options.delay + + this.options.delay = 0 + this.$element.find(Validator.INPUT_SELECTOR).trigger('input.bs.validator') + this.options.delay = delay + + return this + } + + Validator.prototype.showErrors = function ($el) { + var method = this.options.html ? 'html' : 'text' + + this.defer($el, function () { + var $group = $el.closest('.form-group') + var $block = $group.find('.help-block.with-errors') + var $feedback = $group.find('.form-control-feedback') + var errors = $el.data('bs.validator.errors') + + if (!errors.length) return + + errors = $('