Skip to content

Commit

Permalink
Merge pull request #183 from sparcs-kaist/develop
Browse files Browse the repository at this point in the history
2021/03/06 v1.1.9 update
  • Loading branch information
victory-jooyon authored Mar 6, 2021
2 parents 50031bd + 0dce95d commit 6436367
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 28 deletions.
12 changes: 2 additions & 10 deletions apps/core/management/scripts/portal_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from django.db import transaction
from django.utils import timezone
from django.utils.translation import gettext
from fake_useragent import UserAgent
from tqdm import tqdm

from apps.core.models import Article
Expand Down Expand Up @@ -37,15 +36,8 @@

def _login_kaist_portal():
session = requests.Session()
user_agent = UserAgent()
login_req1 = session.post('https://portalsso.kaist.ac.kr/ssoProcess2.ps', data=LOGIN_INFO_SSO2,
headers={
'User-Agent': user_agent.random,
})
login_req2 = session.post('https://portalsso.kaist.ac.kr/ssoProcess.ps', data=LOGIN_INFO_SSO,
headers={
'User-Agent': user_agent.random,
})
login_req1 = session.post('https://portalsso.kaist.ac.kr/ssoProcess2.ps', data=LOGIN_INFO_SSO2,)
login_req2 = session.post('https://portalsso.kaist.ac.kr/ssoProcess.ps', data=LOGIN_INFO_SSO,)

print(f'sso2: {login_req1.status_code} & sso: {login_req2.status_code}')

Expand Down
62 changes: 62 additions & 0 deletions apps/core/templates/invalid_sso_login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">

<title>Oops!</title>
<style>
html {
height: 100%;
}
</style>
</head>
<body class="h-100">
<div class="d-flex justify-content-center h-100">
<div class="align-self-center">
<div class="text-center mb-4">
<img src="https://i.pinimg.com/originals/d3/a7/38/d3a738413b1b9c65333276c89ed82476.gif" />
</div>
<div class="alert alert-secondary" role="alert">
<h4 class="alert-heading">Oops!</h4>
<p>
<strong>Ara에 로그인 하는 중에 문제가 발생했습니다.</strong>
<br>
아래와 같은 원인에 의해 문제가 발생했을 수 있습니다.
</p>

<ul>
<li>SPARCS SSO 에 facebook 계정으로 로그인 하였음.
<ul>
<li><strong>SPARCS SSO 에서 로그아웃 하신 후에 facebook 대신 KAIST IAM (통합인증)으로 로그인해보세요.</strong></li>
</ul>
</li>
<li>
로그인 과정이 지연되어서 토큰이 만료됨.
<ul>
<li><strong>SPARCS SSO 에서 로그아웃 하신 후에 다시 로그인해보세요.</strong></li>
</ul>
</li>
</ul>
<p>
문제가 반복될 경우 [email protected] 에 아래의 에러 정보를 포함해 문의 부탁드립니다.
<br>
<code>code: {{ code }}, status_code: {{ status_code }}</code>
</p>
<hr>
<p class="mb-0">
<a href="https://sparcssso.kaist.ac.kr/" class="btn btn-link px-0">
SPARCS SSO 으로 이동
</a>
</p>
</div>
</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
</body>
</html>
4 changes: 3 additions & 1 deletion apps/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.urls import path, include

from apps.core.views import HomeView, StatusView, router
from apps.core.views import HomeView, InvalidSsoLoginView, StatusView, router

urlpatterns = [
path('api/', include(router.urls)),
path('api/home/', view=HomeView.as_view(), name='HomeView'),
path('api/status/', view=StatusView.as_view(), name='StatusView'),

path('api/invalid_sso_login/', InvalidSsoLoginView.as_view(), name='InvalidSsoLoginView'),
]
1 change: 1 addition & 0 deletions apps/core/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .home import *
from .status import *
from .router import *
from .invalid_sso_login import InvalidSsoLoginView
20 changes: 20 additions & 0 deletions apps/core/views/invalid_sso_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.views.generic import TemplateView


class InvalidSsoLoginView(TemplateView):
template_name = 'invalid_sso_login.html'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

# TODO: code 와 status_code 에 따라 다른 해결 방법을 제시할 수 있으면 좋겠습니다.
# INVALID_METHOD, INVALID_CODE, TOKEN_SERVICE_MISMATCH,
# TOKEN_EXPIRED, INVALID_SERVICE, INALID_TIMESTAMP, INVALID_SIGN
# 등의 code 가 있을 수 있습니다.
# https://github.com/sparcs-kaist/sparcssso/blob/master/apps/api/views/v2.py
context.update({
'code': self.request.GET.get('code', ''),
'status_code': self.request.GET.get('status_code', ''),
})

return context
4 changes: 2 additions & 2 deletions apps/core/views/viewsets/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create(self, request, *args, **kwargs):
if article_id:
parent_id = article_id
article = Article.objects.get(id=parent_id)
title = f"[신고 (게시글)] '{request.user.id}: {request.user.profile}'님께서 Article {parent_id}을 신고하였습니다."
title = f"[신고 (게시글)] '{request.user.id}:: {request.user.profile}'님께서 Article {parent_id}을 신고하였습니다."
message =\
f'''게시글 {parent_id}에 대하여 다음과 같은 신고가 접수되었습니다:
신고자: {request.user.id}:: {request.user.profile}
Expand All @@ -81,7 +81,7 @@ def create(self, request, *args, **kwargs):
parent_id = request.data.get('parent_comment')
comment = Comment.objects.get(id=parent_id)
article = comment.get_parent_article()
title = f"[신고 (댓글)] '{request.user.profile}'님께서 Comment {parent_id}을 신고하였습니다."
title = f"[신고 (댓글)] '{request.user.id}:: {request.user.profile}'님께서 Comment {parent_id}을 신고하였습니다."
message =\
f'''댓글 {parent_id}에 대하여 다음과 같은 신고가 접수되었습니다:
신고자: {request.user.id}:: {request.user.profile}
Expand Down
2 changes: 1 addition & 1 deletion apps/user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UserProfileAdmin(MetaDataModelAdmin):
'uid',
'sid',
'nickname',
'user',
'user__id',
)


Expand Down
18 changes: 18 additions & 0 deletions apps/user/migrations/0015_fix_inactive_due_at_verbose_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1 on 2021-02-25 12:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('user', '0014_userprofile_inactive_due_at'),
]

operations = [
migrations.AlterField(
model_name='userprofile',
name='inactive_due_at',
field=models.DateTimeField(default=None, null=True, verbose_name='활동정지 마감 일시'),
),
]
2 changes: 1 addition & 1 deletion apps/user/models/user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class UserGroup(models.IntegerChoices):
inactive_due_at = models.DateTimeField(
null=True,
default=None,
verbose_name='약관 동의 일시',
verbose_name='활동정지 마감 일시',
)

def __str__(self):
Expand Down
17 changes: 6 additions & 11 deletions apps/user/views/viewsets/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.conf import settings
from django.contrib.auth import get_user_model, login, logout
from django.db import transaction
from django.shortcuts import redirect
from django.shortcuts import redirect, reverse
from django.utils import timezone
from rest_framework import status, response, decorators, permissions

Expand Down Expand Up @@ -99,18 +99,13 @@ def sso_login_callback(self, request, *args, **kwargs):
user_info = self.sso_client.get_user_info(request.GET['code'])

except requests.exceptions.HTTPError as http_error:
if http_error.response.status_code == 400:
message = '잘못된 요청입니다.'
try:
code = json.loads(http_error.response.content)['code']

elif http_error.response.status_code == 403:
message = '권한이 부족합니다.'
except:
code = "json-loads-error"

else:
message = '알 수 없는 에러가 발생했습니다. 잠시 뒤에 다시 시도해주세요.'

return response.Response(
data={'message': message}, status=http_error.response.status_code,
)
return redirect(to=reverse('core:InvalidSsoLoginView') + f'?code={code}&status_code={http_error.response.status_code}')

# Bypass SSO validation
# if not request.GET.get('state'):
Expand Down
3 changes: 2 additions & 1 deletion ara/classes/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class CheckTermsOfServiceMiddleware:
'me',
'user-sso-login',
'user-sso-login-callback',
'userprofile-agree-terms-of-service'
'userprofile-agree-terms-of-service',
'InvalidSsoLoginView',
]

def __init__(self, get_response):
Expand Down
3 changes: 2 additions & 1 deletion ara/classes/sparcssso.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def _post_data(self, url, data):
r.raise_for_status()

except requests.exceptions.HTTPError as http_error:
capture_exception(http_error)
if int(http_error.response.status_code) >= 500:
capture_exception(http_error)

raise http_error

Expand Down

0 comments on commit 6436367

Please sign in to comment.