mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 16:33:22 +00:00
Merge branch 'dev' of git.coding.net:virusdefender/qduoj into dev
ok, but i have nothing to say~
This commit is contained in:
commit
8740b43a1d
@ -25,7 +25,6 @@ class UserRegisterSerializer(serializers.Serializer):
|
|||||||
|
|
||||||
|
|
||||||
class UserChangePasswordSerializer(serializers.Serializer):
|
class UserChangePasswordSerializer(serializers.Serializer):
|
||||||
username = serializers.CharField(max_length=30)
|
|
||||||
old_password = serializers.CharField()
|
old_password = serializers.CharField()
|
||||||
new_password = serializers.CharField(max_length=30, min_length=6)
|
new_password = serializers.CharField(max_length=30, min_length=6)
|
||||||
|
|
||||||
|
@ -123,22 +123,13 @@ class UserChangePasswordAPITest(APITestCase):
|
|||||||
user = User.objects.create(username="test")
|
user = User.objects.create(username="test")
|
||||||
user.set_password("aaabbb")
|
user.set_password("aaabbb")
|
||||||
user.save()
|
user.save()
|
||||||
|
self.client.login(username="test",password="aaabbb")
|
||||||
|
|
||||||
def test_error_old_password(self):
|
def test_error_old_password(self):
|
||||||
data = {"username": "test", "old_password": "aaaccc", "new_password": "aaaddd"}
|
data = {"old_password": "aaaccc", "new_password": "aaaddd"}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
self.assertEqual(response.data, {"code": 1, "data": u"密码不正确,请重新修改!"})
|
self.assertEqual(response.data, {"code": 1, "data": u"密码不正确,请重新修改!"})
|
||||||
|
|
||||||
def test_invalid_data_format(self):
|
|
||||||
data = {"old_password": "aaa", "new_password": "aaaddd"}
|
|
||||||
response = self.client.post(self.url, data=data)
|
|
||||||
self.assertEqual(response.data["code"], 1)
|
|
||||||
|
|
||||||
def test_username_does_not_exist(self):
|
|
||||||
data = {"username": "test1", "old_password": "aaabbb", "new_password": "aaaddd"}
|
|
||||||
response = self.client.post(self.url, data=data)
|
|
||||||
self.assertEqual(response.data["code"], 1)
|
|
||||||
|
|
||||||
def test_success_change_password(self):
|
def test_success_change_password(self):
|
||||||
data = {"username": "test", "old_password": "aaabbb", "new_password": "aaaccc"}
|
data = {"username": "test", "old_password": "aaabbb", "new_password": "aaaccc"}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
|
@ -35,7 +35,7 @@ class UserLoginAPIView(APIView):
|
|||||||
else:
|
else:
|
||||||
return serializer_invalid_response(serializer)
|
return serializer_invalid_response(serializer)
|
||||||
|
|
||||||
|
@login_required
|
||||||
def logout(request):
|
def logout(request):
|
||||||
auth.logout(request)
|
auth.logout(request)
|
||||||
return http.HttpResponseRedirect("/")
|
return http.HttpResponseRedirect("/")
|
||||||
@ -69,6 +69,7 @@ class UserRegisterAPIView(APIView):
|
|||||||
|
|
||||||
|
|
||||||
class UserChangePasswordAPIView(APIView):
|
class UserChangePasswordAPIView(APIView):
|
||||||
|
@login_required
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
"""
|
"""
|
||||||
用户修改密码json api接口
|
用户修改密码json api接口
|
||||||
@ -78,7 +79,8 @@ class UserChangePasswordAPIView(APIView):
|
|||||||
serializer = UserChangePasswordSerializer(data=request.data)
|
serializer = UserChangePasswordSerializer(data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
data = serializer.data
|
data = serializer.data
|
||||||
user = auth.authenticate(username=data["username"], password=data["old_password"])
|
username = request.user.username
|
||||||
|
user = auth.authenticate(username=username, password=data["old_password"])
|
||||||
if user:
|
if user:
|
||||||
user.set_password(data["new_password"])
|
user.set_password(data["new_password"])
|
||||||
user.save()
|
user.save()
|
||||||
|
@ -72,6 +72,7 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
|
|||||||
var vm = avalon.define({
|
var vm = avalon.define({
|
||||||
$id: "admin",
|
$id: "admin",
|
||||||
template_url: "template/" + hash + ".html",
|
template_url: "template/" + hash + ".html",
|
||||||
|
username: "",
|
||||||
groupId: -1,
|
groupId: -1,
|
||||||
problemId: -1,
|
problemId: -1,
|
||||||
adminNavList: [],
|
adminNavList: [],
|
||||||
@ -93,6 +94,7 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
|
|||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function(data){
|
success: function(data){
|
||||||
if(!data.code){
|
if(!data.code){
|
||||||
|
vm.username = data.data.username;
|
||||||
if (data.data.admin_type == 2){
|
if (data.data.admin_type == 2){
|
||||||
vm.adminNavList = superAdminNav;
|
vm.adminNavList = superAdminNav;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
|||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
data: JSON.stringify(ajaxData),
|
data: JSON.stringify(ajaxData),
|
||||||
method: "post",
|
method: "post",
|
||||||
contentType: "application/json",
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (!data.code) {
|
if (!data.code) {
|
||||||
bsAlert("添加成功!将转到比赛列表页以便为比赛添加问题(注意比赛当前状态为:隐藏)");
|
bsAlert("添加成功!将转到比赛列表页以便为比赛添加问题(注意比赛当前状态为:隐藏)");
|
||||||
|
@ -2,13 +2,12 @@ require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, c
|
|||||||
|
|
||||||
$('form').validator().on('submit', function (e) {
|
$('form').validator().on('submit', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var username = $("#username").val();
|
|
||||||
var newPassword = $("#new_password ").val();
|
var newPassword = $("#new_password ").val();
|
||||||
var password = $("#password").val();
|
var password = $("#password").val();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
beforeSend: csrfTokenHeader,
|
beforeSend: csrfTokenHeader,
|
||||||
url: "/api/change_password/",
|
url: "/api/change_password/",
|
||||||
data: {username: username, new_password: newPassword, old_password: password},
|
data: {new_password: newPassword, old_password: password},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
method: "post",
|
method: "post",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body ms-controller="admin">
|
||||||
|
|
||||||
<!-- nav begin -->
|
<!-- nav begin -->
|
||||||
<nav class="navbar navbar-masthead navbar-default navbar-static-top">
|
<nav class="navbar navbar-masthead navbar-default navbar-static-top">
|
||||||
@ -39,13 +39,13 @@
|
|||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
|
||||||
aria-expanded="false">
|
aria-expanded="false">
|
||||||
李扬
|
{{ username }}
|
||||||
<span class="caret"></span></a>
|
<span class="caret"></span></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="#">我的提交</a></li>
|
<li><a href="/submissions/">我的提交</a></li>
|
||||||
<li><a href="#">我的资料</a></li>
|
<li><a href="#">我的资料</a></li>
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
<li><a href="#">退出</a></li>
|
<li><a href="/logout/">退出</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -62,7 +62,7 @@
|
|||||||
<![endif]-->
|
<![endif]-->
|
||||||
<!-- browser happy end -->
|
<!-- browser happy end -->
|
||||||
|
|
||||||
<div class="container main" ms-controller="admin">
|
<div class="container main">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- admin left begin-->
|
<!-- admin left begin-->
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
|
@ -5,11 +5,6 @@
|
|||||||
<h2 class="text-center">修改密码</h2>
|
<h2 class="text-center">修改密码</h2>
|
||||||
|
|
||||||
<form id="change_password-form">
|
<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="用户名" data-error="请填写用户名" maxlength="30" autofocus required>
|
|
||||||
<div class="help-block with-errors"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password">旧密码</label>
|
<label for="password">旧密码</label>
|
||||||
<input type="password" class="form-control input-lg" id="password" name="password" placeholder="密码" data-error="请填写旧密码" maxlength="30" required>
|
<input type="password" class="form-control input-lg" id="password" name="password" placeholder="密码" data-error="请填写旧密码" maxlength="30" required>
|
||||||
|
@ -7,28 +7,28 @@
|
|||||||
<form id="register-form">
|
<form id="register-form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="username">用户名</label>
|
<label for="username">用户名</label>
|
||||||
<input type="text" class="form-control input-lg" id="username" name="username" placeholder="用户名" data-error="请输入用户名" required autofocus>
|
<input type="text" class="form-control input-lg" id="username" name="username" placeholder="用户名" data-error="请填写用户名" required autofocus>
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="real_name">真实姓名</label>
|
<label for="real_name">真实姓名</label>
|
||||||
<input type="text" class="form-control input-lg" id="real_name" name="real_name" placeholder="真实姓名" data-error="请输入姓名" required>
|
<input type="text" class="form-control input-lg" id="real_name" name="real_name" placeholder="真实姓名" data-error="请填写姓名" required>
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="email">邮箱地址</label>
|
<label for="email">邮箱地址</label>
|
||||||
<input type="email" class="form-control input-lg" id="email" name="email" placeholder="邮箱地址" data-error="请填写邮箱" required>
|
<input type="email" class="form-control input-lg" id="email" name="email" placeholder="邮箱地址" data-error="请填写正确的邮箱地址" required>
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password">密码</label>
|
<label for="password">密码</label>
|
||||||
<input type="password" class="form-control input-lg" id="password" name="password" placeholder="密码" data-minlength="6" data-minlength-error="密码不得少于6位" required>
|
<input type="password" class="form-control input-lg" id="password" name="password" data-error="请填写密码" placeholder="密码" data-minlength="6" data-minlength-error="密码不得少于6位" required>
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="confirm_password">确认密码</label>
|
<label for="confirm_password">确认密码</label>
|
||||||
<input type="password" class="form-control input-lg" id="confirm_password" name="confirm_password"
|
<input type="password" class="form-control input-lg" id="confirm_password" name="confirm_password"
|
||||||
placeholder="确认密码" data-match="#password" data-match-error="两个密码不一致" required>
|
placeholder="确认密码" data-match="#password" data-match-error="两个密码不一致" data-error="请填写确认密码" required>
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
Loading…
Reference in New Issue
Block a user