From 3a99c00d6a595e5247f658effbbd7bb07c33ebc6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E775174143?= <775174143@qq.com>
Date: Mon, 20 Aug 2018 16:18:53 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
static/css/code_show.css | 19 +++++++++++++++++--
static/js/source.js | 7 +++----
templates/projects/filesub/code-reading.html | 4 ++--
3 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/static/css/code_show.css b/static/css/code_show.css
index 315a043..6bf8bc2 100644
--- a/static/css/code_show.css
+++ b/static/css/code_show.css
@@ -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;
}
@@ -1441,7 +1441,7 @@ color: #FFF !important;
.codelinebox{
line-height: 19px;
min-height: 19px;
- margin-bottom: -5px;
+ margin-bottom: -16px;
}
.newmypre{
margin: 0 0 16px 28px;
@@ -1523,4 +1523,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;
}
\ No newline at end of file
diff --git a/static/js/source.js b/static/js/source.js
index 0ed922c..88ebd0b 100644
--- a/static/js/source.js
+++ b/static/js/source.js
@@ -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 ='
'+''+''+'
'+'';
- var html = ''+contenthtml+'
';
+ var html = ''+contenthtml+'
';
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 += ''
+ htmlstr += '
'
htmlstr += '
'
- htmlstr += '
'
diff --git a/templates/projects/filesub/code-reading.html b/templates/projects/filesub/code-reading.html
index 2bfc96f..58af435 100644
--- a/templates/projects/filesub/code-reading.html
+++ b/templates/projects/filesub/code-reading.html
@@ -1,6 +1,6 @@
{% load base_filter %}
-{% 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 @@
-
+
{% endif %}
From 9d35fa3ee1f4a21027a66bbb974c7ee9dd2c79c6 Mon Sep 17 00:00:00 2001
From: wrmswindmill
Date: Tue, 21 Aug 2018 01:08:07 +0800
Subject: [PATCH 2/2] Modify Login And Support Educoder
---
apps/operations/views.py | 17 +-
apps/users/forms.py | 3 +
.../migrations/0004_user_password_tmp.py | 19 +++
.../migrations/0005_auto_20180820_2333.py | 18 ++
apps/users/models.py | 2 +
apps/users/views.py | 159 +++++++++++++-----
templates/users/login.html | 15 +-
7 files changed, 190 insertions(+), 43 deletions(-)
create mode 100644 apps/users/migrations/0004_user_password_tmp.py
create mode 100644 apps/users/migrations/0005_auto_20180820_2333.py
diff --git a/apps/operations/views.py b/apps/operations/views.py
index 4119906..5dac85c 100644
--- a/apps/operations/views.py
+++ b/apps/operations/views.py
@@ -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):
"""
获取某一行代码所有的注释
diff --git a/apps/users/forms.py b/apps/users/forms.py
index 0af0447..d94c221 100644
--- a/apps/users/forms.py
+++ b/apps/users/forms.py
@@ -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)
diff --git a/apps/users/migrations/0004_user_password_tmp.py b/apps/users/migrations/0004_user_password_tmp.py
new file mode 100644
index 0000000..b933ce2
--- /dev/null
+++ b/apps/users/migrations/0004_user_password_tmp.py
@@ -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,
+ ),
+ ]
diff --git a/apps/users/migrations/0005_auto_20180820_2333.py b/apps/users/migrations/0005_auto_20180820_2333.py
new file mode 100644
index 0000000..da55080
--- /dev/null
+++ b/apps/users/migrations/0005_auto_20180820_2333.py
@@ -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',
+ ),
+ ]
diff --git a/apps/users/models.py b/apps/users/models.py
index a2aa1e2..372ec5f 100644
--- a/apps/users/models.py
+++ b/apps/users/models.py
@@ -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:
diff --git a/apps/users/views.py b/apps/users/views.py
index 194a87d..bb16401 100644
--- a/apps/users/views.py
+++ b/apps/users/views.py
@@ -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')
diff --git a/templates/users/login.html b/templates/users/login.html
index b1b4ed6..3c1b838 100755
--- a/templates/users/login.html
+++ b/templates/users/login.html
@@ -24,13 +24,20 @@