Merge branch 'develop'
This commit is contained in:
commit
c63d7f1cf1
|
@ -62,12 +62,25 @@ class ShowAnnotationView(View):
|
|||
# 怎么获取组id还没有写
|
||||
def get_group_annotation(self,file_id,line_num,user_id):
|
||||
# 首先获取当前组的所有用户id
|
||||
user_ids = []
|
||||
# 根据到当前的id获取到group username list
|
||||
users = self.get_group_userids(user_id)
|
||||
# user_ids = []
|
||||
# 然后调用
|
||||
commit_id = self.get_current_commitid_by_fileid(file_id)
|
||||
annotations = Annotation.objects.filter(file_id=file_id, linenum=line_num,user_id__in=user_ids,is_latest=1,commit_id=commit_id)
|
||||
annotations = Annotation.objects.filter(file_id=file_id, linenum=line_num,user__in=users,is_latest=1,commit_id=commit_id)
|
||||
return annotations
|
||||
|
||||
def get_educoder_group_userlist_by_userid(self,userid):
|
||||
pass
|
||||
|
||||
def get_group_userids(self,user_id):
|
||||
educoder_userid = User.objects.get(id=user_id).educoder_userid
|
||||
# 调用educoder的接口,返回对应的username list
|
||||
usernames = self.get_educoder_group_userlist_by_userid(educoder_userid)
|
||||
users = User.objects.filter(email__in=usernames)
|
||||
return users
|
||||
|
||||
|
||||
def post(self, request):
|
||||
"""
|
||||
获取某一行代码所有的注释
|
||||
|
|
|
@ -7,6 +7,9 @@ from .models import User
|
|||
class LoginForm(forms.Form):
|
||||
email = forms.CharField(required=True)
|
||||
password = forms.CharField(required=True, min_length=5)
|
||||
# types = forms.ChoiceField(initial=1,widget=forms.RadioSelect, choices= (('1', 'default'), ('2', 'educoder'),('3','trustie')))
|
||||
# types= forms.ChoiceField(label=u'登录类型:', choices=((u'1', u'defalut'), (u'2', u'educoder'),(u'3', u'trustie'), ), widget=forms.RadioSelect())
|
||||
|
||||
|
||||
class RegisterForm(forms.Form): # 注册
|
||||
email = forms.EmailField(required=True)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 2.0.6 on 2018-08-20 22:52
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0003_auto_20180731_2115'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='password_tmp',
|
||||
field=models.CharField(default='', max_length=100),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.0.6 on 2018-08-20 23:33
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0004_user_password_tmp'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='user',
|
||||
old_name='password_tmp',
|
||||
new_name='password_codepedia',
|
||||
),
|
||||
]
|
|
@ -51,6 +51,8 @@ class User(AbstractUser):
|
|||
role = models.CharField(max_length=3, choices=ROLE_CHOICE, default='1')
|
||||
create_time = models.DateTimeField(auto_now_add=True)
|
||||
update_time = models.DateTimeField(auto_now=True)
|
||||
password_codepedia = models.CharField(max_length=100)
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -85,6 +85,7 @@ class RegisterView(View):
|
|||
user.email = email
|
||||
user.is_active = True
|
||||
user.password = make_password(pwd1)
|
||||
user.password_codepedia = user.password
|
||||
user.save()
|
||||
|
||||
return render(request,'users/login.html')
|
||||
|
@ -172,54 +173,133 @@ def getCodeByFileIdAndLinenum(file_id,linenum):
|
|||
|
||||
# 用户登录
|
||||
class LoginView(View):
|
||||
def get(self, request):
|
||||
return render(request, 'users/login.html', {})
|
||||
|
||||
def post(self, request):
|
||||
login_form = LoginForm(request.POST)
|
||||
if login_form.is_valid():
|
||||
email = request.POST.get('email', '')
|
||||
pass_word = request.POST.get('password', '')
|
||||
def login_trustie(self,email,pass_word,request):
|
||||
# login
|
||||
user_params = {'username': email, 'password': pass_word}
|
||||
trustie_url = 'https://www.trustie.net/account/codepedia_login'
|
||||
response = requests.get(trustie_url, params=user_params)
|
||||
response = json.loads(response.text)
|
||||
status = response['status']
|
||||
# status == 1表示登录成功
|
||||
if status == 1:
|
||||
user_message = response['user']['user']
|
||||
email = user_message['mail']
|
||||
exist_records = User.objects.filter(email=email).first()
|
||||
|
||||
# 如果没有当前email的数据,那么新建用户
|
||||
if not exist_records:
|
||||
user = User()
|
||||
user.username = email
|
||||
user.password = make_password(pass_word)
|
||||
user.password_codepedia = user.password
|
||||
user.email = email
|
||||
if 'lastname' in user_message:
|
||||
user.nick_name = user_message['lastname']
|
||||
elif 'nickname' in user_message:
|
||||
user.nick_name = user_message['nickname']
|
||||
else:
|
||||
user.nick_name = user_message['firstname']
|
||||
user.is_active = True
|
||||
user.save()
|
||||
user = authenticate(username=email, password=pass_word)
|
||||
# 现在的策略是密码与educoder保持一致
|
||||
else:
|
||||
user = exist_records
|
||||
# 如果使用trustie登陆,那么就要记录之前的密码
|
||||
user.password = make_password(pass_word)
|
||||
user.save()
|
||||
user = authenticate(username=email, password=pass_word)
|
||||
# 否则用当前用户名和密码登录
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
else:
|
||||
return render(request, 'users/login.html', {'msg': '用户名或密码错误!'})
|
||||
else:
|
||||
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 = 'http://www.educoder.net/api/v1/sources/login'
|
||||
response = requests.get(login_url, params=user_params)
|
||||
response = json.loads(response.text)
|
||||
status = response['status']
|
||||
if status == 1:
|
||||
educoder_userid = response['user_id']
|
||||
educoder_userid = "15583"
|
||||
userinfo_url = "http://www.educoder.net/api/v1/sources/"+educoder_userid+"/get_user_info?private_token="+private_token
|
||||
response = requests.get(userinfo_url)
|
||||
response = json.loads(response.text)
|
||||
exist_records = User.objects.filter(email=email).first()
|
||||
if not exist_records:
|
||||
user = User()
|
||||
user.username = response['username']
|
||||
user.password = make_password(pass_word)
|
||||
user.password_codepedia = user.password
|
||||
user.email = response['email']
|
||||
user.is_active = True
|
||||
user.save()
|
||||
user = authenticate(username=email, password=pass_word)
|
||||
# 现在的策略是密码与educoder保持一致
|
||||
else:
|
||||
user = exist_records
|
||||
user.password = make_password(pass_word)
|
||||
user.save()
|
||||
user = authenticate(username=email, password=pass_word)
|
||||
# 否则用当前用户名和密码登录
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
else:
|
||||
return render(request, 'users/login.html', {'msg': '用户名或密码错误!'})
|
||||
else:
|
||||
return render(request, 'users/login.html', {'msg': '用户名或密码错误!'})
|
||||
|
||||
def login_default(self,email,pass_word,request):
|
||||
exist_records = User.objects.filter(email=email).first()
|
||||
if exist_records:
|
||||
|
||||
user = exist_records
|
||||
user.password = user.password_codepedia
|
||||
user.save()
|
||||
|
||||
user = authenticate(email=email, password=pass_word)
|
||||
# 如果本地用户没有获取到,前往trustie获取用户
|
||||
if user is not None:
|
||||
if user.is_active:
|
||||
print(user.is_active)
|
||||
login(request, user)
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
else:
|
||||
return render(request, 'users/login.html', {'msg': '用户未激活!请到邮箱激活后,再登录'})
|
||||
else:
|
||||
user_params = {'username': email, 'password': pass_word}
|
||||
trustie_url = 'https://www.trustie.net/account/codepedia_login'
|
||||
response = requests.get(trustie_url, params=user_params)
|
||||
response = json.loads(response.text)
|
||||
status = response['status']
|
||||
if status == 1:
|
||||
user_message = response['user']['user']
|
||||
email = user_message['mail']
|
||||
exist_records = User.objects.filter(email=email).first()
|
||||
if not exist_records:
|
||||
user = User()
|
||||
user.username = email
|
||||
user.password = make_password(pass_word)
|
||||
user.email = email
|
||||
if 'lastname' in user_message:
|
||||
user.nick_name = user_message['lastname']
|
||||
elif 'nickname' in user_message:
|
||||
user.nick_name = user_message['nickname']
|
||||
else:
|
||||
user.nick_name = user_message['firstname']
|
||||
user.is_active = True
|
||||
user.save()
|
||||
user = authenticate(username=email, password=pass_word)
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
else:
|
||||
return render(request, 'users/login.html', {'msg': '用户名或密码错误!'})
|
||||
else:
|
||||
return render(request, 'users/login.html', {'msg': '用户名或密码错误!'})
|
||||
return render(request, 'users/login.html', {'msg': '用户名或邮箱不存在'})
|
||||
else:
|
||||
return render(request, 'users/login.html', {'msg': '用户名或邮箱不存在'})
|
||||
|
||||
|
||||
def get(self, request):
|
||||
login_form = LoginForm()
|
||||
return render(request, 'users/login.html', locals())
|
||||
|
||||
def post(self, request):
|
||||
login_form = LoginForm(request.POST)
|
||||
# print(login_form)
|
||||
if login_form.is_valid():
|
||||
email = request.POST.get('email', '')
|
||||
pass_word = request.POST.get('password', '')
|
||||
choice = int(request.POST.get('types',''))
|
||||
# 如果本地用户没有获取到,前往trustie获取用户
|
||||
|
||||
# choice=1表示default,是指用codepedia本地的密码登陆
|
||||
# chocie=2表示educoder,是指用educoder的方式登陆
|
||||
# chocie=3表示trustie,是指用trustie的方式登陆
|
||||
if choice == 1:
|
||||
return self.login_default(email,pass_word,request)
|
||||
elif choice == 2:
|
||||
return self.login_educoder(email,pass_word,request)
|
||||
elif choice == 3:
|
||||
return self.login_trustie(email,pass_word,request)
|
||||
else:
|
||||
return render(request, 'users/login.html', {'login_form': login_form})
|
||||
|
||||
|
@ -290,6 +370,7 @@ class ForgetPwdView(View):
|
|||
})
|
||||
else:
|
||||
user.password = pwd1
|
||||
user.password_codepedia = user.password
|
||||
user.save()
|
||||
print(1111)
|
||||
return render(request, 'users/modifypwd_success.html')
|
||||
|
|
|
@ -833,7 +833,7 @@ pre.prettyprint {
|
|||
|
||||
.put-select span.active {
|
||||
color: #05101a;
|
||||
border: 1px solid #05101a;
|
||||
border: 1px solid #989898;
|
||||
text-align: center;
|
||||
margin: 10px 10px 10px 0px;
|
||||
}
|
||||
|
@ -1442,7 +1442,7 @@ color: #FFF !important;
|
|||
.codelinebox{
|
||||
line-height: 19px;
|
||||
min-height: 19px;
|
||||
margin-bottom: -5px;
|
||||
margin-bottom: -16px;
|
||||
}
|
||||
.newmypre{
|
||||
margin: 0 0 16px 28px;
|
||||
|
@ -1524,4 +1524,19 @@ color: #FFF !important;
|
|||
.panel-leffont{
|
||||
fonr-size:24px;
|
||||
color:#C3BDBD;
|
||||
}
|
||||
.newcodeline{
|
||||
min-width: 910px;
|
||||
width: 100%;
|
||||
height: 23px;
|
||||
/* background: #f1efec; */
|
||||
display: flex;
|
||||
}
|
||||
.newcodelinebox{
|
||||
line-height: 25px;
|
||||
min-height: 25px;
|
||||
margin-bottom: 0px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
|
@ -98,7 +98,6 @@ function modify_anno(file_id,line_num){
|
|||
}
|
||||
});
|
||||
$("."+file_id+line_num).text("//"+content)
|
||||
console.log(content);
|
||||
}
|
||||
|
||||
// FIXME
|
||||
|
@ -324,7 +323,7 @@ function submit_annotation(file_id, line_num, content) {
|
|||
//将注释添加到当前行的上一行
|
||||
console.log(data.anno_content)
|
||||
var contenthtml ='<div class="linenum"></div>'+'<div class="sourcecode">'+'<pre class="mypre newaddmypre hljs-comment ' + file_id+line_num + '">'+data.anno_content+'</pre>'+'</div>'+'<div class="linestatus"></div>';
|
||||
var html = '<div class="codeline codelinebox">'+contenthtml+'</div>';
|
||||
var html = '<div class="newcodeline newcodelinebox">'+contenthtml+'</div>';
|
||||
var id=file_id+'_'+"L"+line_num;
|
||||
console.log(html)
|
||||
$("#"+id).before(html);
|
||||
|
@ -694,9 +693,9 @@ function generate_codereading_content(lines,self_annos,fileid,annos_count,issues
|
|||
|
||||
function generate_codereading_anno_line(linenum,self_annos){
|
||||
var htmlstr = ''
|
||||
htmlstr += '<div class="codeline codelinebox">'
|
||||
htmlstr += '<div class="newcodeline newcodelinebox">'
|
||||
htmlstr += '<div class="sourcecode">'
|
||||
htmlstr += '<pre class="mypre mypre newmypre hljs-comment}">'
|
||||
htmlstr += '<pre class="mypre mypre newmypre hljs-comment">'
|
||||
htmlstr += self_annos[linenum]
|
||||
htmlstr += '</pre>'
|
||||
htmlstr += '</div>'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% load base_filter %}
|
||||
<div class="code_file">
|
||||
{% formatText2Line project.name file.path as lines %}
|
||||
{% formatText2Line project.name file.path as lines %}
|
||||
{% for linenum,line in lines.items %}
|
||||
|
||||
{% if linenum in self_annos %}
|
||||
|
@ -14,7 +14,7 @@
|
|||
|
||||
<!-- <div id="linestatus_{{fileid}}_{{ linenum }}" class="linestatus"> -->
|
||||
<div class="linestatus">
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -24,13 +24,20 @@
|
|||
<form id="email_register_form" method="post" action="{% url 'users:login' %}" autocomplete="off">
|
||||
<ul>
|
||||
<li class="new_register_li form-group {% if login_form.errors.email %}errorput{% endif %}">
|
||||
<input type="text" class="new_register_input" id="id_email" name="email" value="{{ login_form.email.value }}" placeholder="请输入您的邮箱地址或用户名">
|
||||
<input type="text" class="new_register_input" id="id_email" name="email" placeholder="请输入您的邮箱地址或用户名">
|
||||
</li>
|
||||
<li class="new_register_li form-group {% if login_form.errors.password %} errorput{% endif %}">
|
||||
<input type="password" class="new_register_input" id="id_password" name="password" value="{{ login_form.password1.value }}" placeholder="请输入6-20位非中文字符密码" />
|
||||
</li>
|
||||
</ul>
|
||||
<div class="error btns" id="jsEmailTips">{% for key,error in login_form.errors.items %}{{ error }}{% endfor %}{{ msg }}</div>
|
||||
|
||||
|
||||
<input type="radio" name="types" value="1" checked />default
|
||||
<input type="radio" name="types" value="2" />educoder
|
||||
<input type="radio" name="types" value="3" />trustie
|
||||
|
||||
|
||||
<div class="error btns" id="jsEmailTips">{% for key,error in login_form.errors.items %}{{ error }}{% endfor %}{{ msg }}</div>
|
||||
<div class="auto-box marb8"></div>
|
||||
<input class="btn btn-green new_login_submit" id="jsEmailRegBtn" type="submit" value="登录" />
|
||||
{% csrf_token %}
|
||||
|
@ -41,4 +48,8 @@
|
|||
{% endblock %}
|
||||
{% block custom_js %}
|
||||
<script src="{% static 'js/users-common.js' %}"></script>
|
||||
<script>
|
||||
alert("参与代码标注比赛的用户,请选择Educoder选项,然后用Educoder的用户名和密码登录")
|
||||
// 如果已有Trustie用户或者Educoder用户,请选择对应的选项,然后用对应账户名密码登陆
|
||||
</script>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue