FIXBUG
修复登录bug 因为用户可以用用户名登录,而选择educoder时,如果用用户名登录,就必须在用户名和密码都正确时 获取到的email保证为email,而不是用户名
This commit is contained in:
parent
12cc68a128
commit
564f0900c8
|
@ -120,7 +120,7 @@ WSGI_APPLICATION = 'Codepedia2.wsgi.application'
|
|||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'codepedia_1',
|
||||
'NAME': 'codepedia',
|
||||
'USER': 'root',
|
||||
'PASSWORD': 'codepedia123',
|
||||
'HOST': '127.0.0.1'
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.0.6 on 2018-08-25 18:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('operations', '0015_auto_20180821_1142'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='annotation',
|
||||
name='modify_user_id',
|
||||
field=models.CharField(max_length=255, null=True, verbose_name='本次标注的修改者的ID'),
|
||||
),
|
||||
]
|
|
@ -66,6 +66,7 @@ class Annotation(models.Model):
|
|||
create_time = models.DateTimeField(auto_now_add=True)
|
||||
update_time = models.DateTimeField(auto_now=True)
|
||||
commit_id = models.CharField(max_length=255)
|
||||
modify_user_id = models.CharField(max_length=255,verbose_name='本次标注的修改者的ID',null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = 'Annotation'
|
||||
|
|
|
@ -46,8 +46,10 @@ def get_educoder_group_userlist_by_educoder_userid(userid,file_id):
|
|||
|
||||
def get_group_users(user_id,file_id):
|
||||
educoder_userid = User.objects.get(id=user_id).educoder_userid
|
||||
# print(educoder_userid)
|
||||
# 调用educoder的接口,返回对应的username list
|
||||
educoder_userids = get_educoder_group_userlist_by_educoder_userid(educoder_userid,file_id)
|
||||
print(educoder_userids)
|
||||
users = User.objects.filter(educoder_userid__in=educoder_userids)
|
||||
return users
|
||||
|
||||
|
@ -89,11 +91,14 @@ class ShowAnnotationView(View):
|
|||
users = get_group_users(user_id,file_id)
|
||||
# user_ids = []
|
||||
# 然后调用
|
||||
print(users)
|
||||
commit_id = self.get_current_commitid_by_fileid(file_id)
|
||||
if users is None:
|
||||
# print(Annotation.objects.filter(file_id=file_id, linenum=line_num,is_latest=1,commit_id=commit_id))
|
||||
if len(users)==0:
|
||||
annotations = Annotation.objects.filter(file_id=file_id, linenum=line_num,user_id=user_id,is_latest=1,commit_id=commit_id)
|
||||
else:
|
||||
annotations = Annotation.objects.filter(file_id=file_id, linenum=line_num,user__in=users,is_latest=1,commit_id=commit_id)
|
||||
print(annotations)
|
||||
return annotations
|
||||
|
||||
|
||||
|
@ -403,8 +408,9 @@ class ModifyAnnotationView(View):
|
|||
content = request.POST.get('content', '')
|
||||
file_id = int(request.POST.get('file_id', ''))
|
||||
linenum = int(request.POST.get('line_num', ''))
|
||||
anno_id = int(request.POST.get('anno_id', ''))
|
||||
# 查询到之前的注释,根据file_id,line_num,user_id;
|
||||
annotation = Annotation.objects.get(file_id=file_id, linenum=linenum, user_id=request.user.id,is_latest=1)
|
||||
annotation = Annotation.objects.get(file_id=file_id, linenum=linenum, id=anno_id,is_latest=1)
|
||||
# 然后插入一条新的记录,anno_id其他的都一样,除了content以及is_latest
|
||||
new_annotation = Annotation()
|
||||
new_annotation.file_id = file_id
|
||||
|
@ -413,6 +419,7 @@ class ModifyAnnotationView(View):
|
|||
new_annotation.project_id = annotation.project_id
|
||||
new_annotation.user = annotation.user
|
||||
new_annotation.anno_id = annotation.anno_id
|
||||
new_annotation.modify_user_id = request.user.id
|
||||
new_annotation.is_latest = 1
|
||||
|
||||
project_name = File.objects.get(id=file_id).project.name
|
||||
|
|
|
@ -222,6 +222,7 @@ class LoginView(View):
|
|||
return render(request, 'users/login.html', {'msg': '用户名或密码错误!'})
|
||||
|
||||
def login_educoder(self,email,pass_word,request):
|
||||
|
||||
private_token = "hriEn3UwXfJs3PmyXnSG"
|
||||
user_params = {'username': email, 'password': pass_word,"private_token":private_token}
|
||||
login_url = 'https://www.educoder.net/api/v1/sources/login'
|
||||
|
@ -230,18 +231,21 @@ class LoginView(View):
|
|||
print(response)
|
||||
status = response['status']
|
||||
if status == 1:
|
||||
# 因为用户可能是邮箱也可能是用户名登录,所以先获取到educoder用户的用户名
|
||||
# 调用接口获取用户的email
|
||||
educoder_userid = response['user_id']
|
||||
print(educoder_userid)
|
||||
userinfo_url = "http://www.educoder.net/api/v1/sources/"+str(educoder_userid)+"/get_user_info?private_token="+private_token
|
||||
response = requests.get(userinfo_url)
|
||||
response = json.loads(response.text)
|
||||
|
||||
email = response['email']
|
||||
|
||||
exist_records = User.objects.filter(email=email).first()
|
||||
if not exist_records:
|
||||
educoder_userid = response['user_id']
|
||||
# educoder_userid = "15583"
|
||||
userinfo_url = "http://www.educoder.net/api/v1/sources/"+str(educoder_userid)+"/get_user_info?private_token="+private_token
|
||||
response = requests.get(userinfo_url)
|
||||
response = json.loads(response.text)
|
||||
|
||||
user = User()
|
||||
user.username = response['username']
|
||||
|
||||
|
||||
while User.objects.filter(username=user.username).first():
|
||||
user.username += str(random.randint(0,10))
|
||||
|
||||
|
@ -270,7 +274,12 @@ class LoginView(View):
|
|||
return render(request, 'users/login.html', {'msg': '用户名或密码错误!'})
|
||||
|
||||
def login_default(self,email,pass_word,request):
|
||||
exist_records = User.objects.filter(email=email).first()
|
||||
import re
|
||||
if re.match(r'[0-9a-zA-Z_]{0,19}@163.com',email):
|
||||
exist_records = User.objects.filter(email=email).first()
|
||||
else:
|
||||
exist_records = User.objects.filter(username=email).first()
|
||||
|
||||
if exist_records:
|
||||
|
||||
user = exist_records
|
||||
|
|
|
@ -1581,4 +1581,7 @@ color: #FFF !important;
|
|||
}
|
||||
.filePathInfomarbootom{
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.anno_textarea{
|
||||
}
|
|
@ -55,6 +55,9 @@ function show_annotation(file_id, line_num) {
|
|||
|
||||
function close_modify_anno(){
|
||||
$(".modify_anno_div").remove();
|
||||
$("#modify_anno_textarea").attr("readonly","readonly")
|
||||
|
||||
|
||||
ev = window.event;
|
||||
if(ev==undefined){
|
||||
ev=arguments.callee.caller.arguments[0]||window.event;
|
||||
|
@ -63,11 +66,13 @@ function close_modify_anno(){
|
|||
}
|
||||
|
||||
//注入html代码
|
||||
function inject_modifyAnno_html(item,file_id,linenum) {
|
||||
$(".modify_anno_div").remove();
|
||||
function inject_modifyAnno_html(item,file_id,linenum,anno_id) {
|
||||
$(".modify_anno_div").remove();
|
||||
$("#modify_anno_textarea").removeAttr("readonly");
|
||||
$("#modify_anno_textarea").focus()
|
||||
|
||||
html_str = '<div class="modify_anno_div" style="display:block">'+
|
||||
'<textarea id="modify_anno_textarea" class="put-text" placeholder="输入注释或者问题"> </textarea>'+
|
||||
'<a href="javascript:void(0)" onclick="modify_anno('+file_id+','+linenum+')" class="submit fr">提交</a>'+
|
||||
'<a href="javascript:void(0)" onclick="modify_anno('+file_id+','+linenum+','+anno_id+')" class="submit fr">提交</a>'+
|
||||
'<a href="javascript:void(0)" onclick="close_modify_anno()">取消</a>'+
|
||||
'</div>';
|
||||
$(item).after(html_str)
|
||||
|
@ -79,7 +84,7 @@ function inject_modifyAnno_html(item,file_id,linenum) {
|
|||
}
|
||||
|
||||
// FIXME
|
||||
function modify_anno(file_id,line_num){
|
||||
function modify_anno(file_id,line_num,anno_id){
|
||||
// 获取修改后的内容
|
||||
var content=$("#modify_anno_textarea").val();
|
||||
if (content == null || content == undefined || content.trim() == '') {
|
||||
|
@ -90,7 +95,7 @@ function modify_anno(file_id,line_num){
|
|||
cache: false,
|
||||
type: "POST",
|
||||
url: '/operations/modify_anno/',
|
||||
data: { 'file_id': file_id, 'line_num': line_num,'content':content },
|
||||
data: { 'file_id': file_id, 'line_num': line_num,'anno_id':anno_id,'content':content },
|
||||
dataType: 'json',
|
||||
async: true,
|
||||
beforeSend: function (xhr, settings) {
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
</div>
|
||||
<div class="fl commentparthalf">
|
||||
<div class="parthalf_con clearfix">
|
||||
<span class="fl break_word color-grey-des colorblack inlineBlock wi216" >{{ self_anno.content }}</span>
|
||||
<textarea id="modify_anno_textarea" class="fl break_word color-grey-des colorblack inlineBlock wi216" style="border:none" readonly>{{ self_anno.content }}</textarea>
|
||||
{% if allow_modify %}
|
||||
<a class="modify-anno" href="javascript:void(0)" onclick="inject_modifyAnno_html(this,{{self_anno.file_id}},{{self_anno.linenum}})">修改</a>
|
||||
<a class="modify-anno" href="javascript:void(0)" onclick="inject_modifyAnno_html(this,{{self_anno.file_id}},{{self_anno.linenum}},{{self_anno.id}})">修改</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue