mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-29 16:41:56 +00:00
Merge branch 'dev' into hohoTT-dev
This commit is contained in:
commit
9d01c9fbe9
@ -25,7 +25,6 @@ class UserRegisterSerializer(serializers.Serializer):
|
||||
|
||||
|
||||
class UserChangePasswordSerializer(serializers.Serializer):
|
||||
username = serializers.CharField(max_length=30)
|
||||
old_password = serializers.CharField()
|
||||
new_password = serializers.CharField(max_length=30, min_length=6)
|
||||
|
||||
|
@ -123,22 +123,13 @@ class UserChangePasswordAPITest(APITestCase):
|
||||
user = User.objects.create(username="test")
|
||||
user.set_password("aaabbb")
|
||||
user.save()
|
||||
self.client.login(username="test",password="aaabbb")
|
||||
|
||||
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)
|
||||
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):
|
||||
data = {"username": "test", "old_password": "aaabbb", "new_password": "aaaccc"}
|
||||
response = self.client.post(self.url, data=data)
|
||||
|
@ -35,7 +35,7 @@ class UserLoginAPIView(APIView):
|
||||
else:
|
||||
return serializer_invalid_response(serializer)
|
||||
|
||||
|
||||
@login_required
|
||||
def logout(request):
|
||||
auth.logout(request)
|
||||
return http.HttpResponseRedirect("/")
|
||||
@ -69,6 +69,7 @@ class UserRegisterAPIView(APIView):
|
||||
|
||||
|
||||
class UserChangePasswordAPIView(APIView):
|
||||
@login_required
|
||||
def post(self, request):
|
||||
"""
|
||||
用户修改密码json api接口
|
||||
@ -78,7 +79,8 @@ class UserChangePasswordAPIView(APIView):
|
||||
serializer = UserChangePasswordSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
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:
|
||||
user.set_password(data["new_password"])
|
||||
user.save()
|
||||
|
@ -72,6 +72,7 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
|
||||
var vm = avalon.define({
|
||||
$id: "admin",
|
||||
template_url: "template/" + hash + ".html",
|
||||
username: "",
|
||||
groupId: -1,
|
||||
problemId: -1,
|
||||
adminNavList: [],
|
||||
@ -93,6 +94,7 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
|
||||
dataType: "json",
|
||||
success: function(data){
|
||||
if(!data.code){
|
||||
vm.username = data.data.username;
|
||||
if (data.data.admin_type == 2){
|
||||
vm.adminNavList = superAdminNav;
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(ajaxData),
|
||||
method: "post",
|
||||
contentType: "application/json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bsAlert("添加成功!将转到比赛列表页以便为比赛添加问题(注意比赛当前状态为:隐藏)");
|
||||
|
@ -2,13 +2,12 @@ require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, c
|
||||
|
||||
$('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},
|
||||
data: {new_password: newPassword, old_password: password},
|
||||
dataType: "json",
|
||||
method: "post",
|
||||
success: function (data) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<body ms-controller="admin">
|
||||
|
||||
<!-- nav begin -->
|
||||
<nav class="navbar navbar-masthead navbar-default navbar-static-top">
|
||||
@ -39,13 +39,13 @@
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
李扬
|
||||
{{ username }}
|
||||
<span class="caret"></span></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#">我的提交</a></li>
|
||||
<li><a href="/submissions/">我的提交</a></li>
|
||||
<li><a href="#">我的资料</a></li>
|
||||
<li role="separator" class="divider"></li>
|
||||
<li><a href="#">退出</a></li>
|
||||
<li><a href="/logout/">退出</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@ -62,7 +62,7 @@
|
||||
<![endif]-->
|
||||
<!-- browser happy end -->
|
||||
|
||||
<div class="container main" ms-controller="admin">
|
||||
<div class="container main">
|
||||
<div class="row">
|
||||
<!-- admin left begin-->
|
||||
<div class="col-md-2">
|
||||
|
@ -5,11 +5,6 @@
|
||||
<h2 class="text-center">修改密码</h2>
|
||||
|
||||
<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">
|
||||
<label for="password">旧密码</label>
|
||||
<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">
|
||||
<div class="form-group">
|
||||
<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>
|
||||
<div class="form-group">
|
||||
<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>
|
||||
<div class="form-group">
|
||||
<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>
|
||||
<div class="form-group">
|
||||
<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>
|
||||
<div class="form-group">
|
||||
<label for="confirm_password">确认密码</label>
|
||||
<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>
|
||||
<div class="form-group">
|
||||
|
Loading…
Reference in New Issue
Block a user