Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing-E
/
E_Team_KhuBox
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
김대연
2020-06-14 03:17:02 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2424ee82ca4ce5b6e61e26a21e4f7e653f976700
2424ee82
1 parent
bceb47b4
로그인 리팩토링
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletions
khubox-api/khubox/services/users.py
khubox-api/requirements.txt
khubox-api/khubox/services/users.py
View file @
2424ee8
import
json
import
jwt
import
uuid
from
django.conf
import
settings
from
django.contrib.auth.hashers
import
make_password
,
check_password
from
django.core.exceptions
import
ValidationError
from
django.core.validators
import
validate_email
...
...
@@ -63,7 +65,32 @@ def create(request):
# 로그인
def
login
(
request
):
return
{
'result'
:
True
}
# Load
try
:
received
=
json
.
loads
(
request
.
body
.
decode
(
'utf-8'
))
except
json
.
decoder
.
JSONDecodeError
:
return
{
'result'
:
False
,
'error'
:
'입력이 잘못되었습니다.'
}
# Validate
if
'email'
not
in
received
\
or
'password'
not
in
received
:
return
{
'result'
:
False
,
'error'
:
'입력이 누락되었습니다.'
}
# Select
user
=
User
.
objects
.
filter
(
email
=
received
[
'email'
])
# Not Exists
if
len
(
user
)
!=
1
:
return
{
'result'
:
False
,
'error'
:
'로그인에 실패하였습니다.'
}
# Check
if
check_password
(
received
[
'password'
],
user
[
0
]
.
password
)
is
False
:
return
{
'result'
:
False
,
'error'
:
'로그인에 실패하였습니다.'
}
# Token Generate
token
=
jwt
.
encode
({
'id'
:
user
[
0
]
.
id
},
key
=
settings
.
SECRET_KEY
,
algorithm
=
'HS256'
)
return
{
'result'
:
True
,
'token'
:
token
.
decode
(
'utf-8'
)}
# 회원정보 조회
...
...
khubox-api/requirements.txt
View file @
2424ee8
...
...
@@ -20,6 +20,7 @@ jmespath==0.10.0
pip-tools==5.1.2
placebo==0.9.0
pycparser==2.20
PyJWT==1.7.1
PyMySQL==0.9.3
python-dateutil==2.6.1
python-slugify==4.0.0
...
...
Please
register
or
login
to post a comment