swsnu / swppfall2018

22 stars 21 forks source link

[HW3] signup에서 createUser method 관련 질문입니다. #126

Open ghost opened 5 years ago

ghost commented 5 years ago

주어진 hw3 코드의 signin 부분에서는 create_user method는 다음과 같이 두개의 인자만을 사용하고 있습니다.

create_user(username, password)

hw3의 사용 예시를 python manage.py shell에서 사용해보면 다음과 같은 결과가 나옵니다.

>>> User.objects.create_user("testaccount", "testpassword")
<User: testaccount>
>>> User.objects.all().first().username
'testaccount'
>>> User.objects.all().first().password
'!50oCxZrufvytTcHzxxCrRrspm20lI61du3iyEOk3'
>>> User.objects.all().first().email
'testpassword'
>>> from django.contrib.auth import authenticate
>>> user = authenticate(username="testaccount", password="testpassword")
>>> user is None
True

password는 의도했던 바와 다르게 email에 저장되었기 때문에 authenticate 함수를 이용해서 유저를 찾을 수 없었습니다. django document를 참고하면 create_user는 3개의 인자(username, email, password)를 받습니다. 이를 참고해 작성해 보니, 다음과 같은 결과를 얻을 수 있었습니다

>>> User.objects.create_user("testaccount2", "test@test.com", "testpassword")
<User: testaccount2>
>>> user2 = authenticate(username="testaccount2", password="testpassword")
>>> user2 is None
False

user_create에 email정보가 필요한 것 같은데, 이를 어떻게 처리해야할지 궁금합니다.

sanha commented 5 years ago

README에 있는 코드처럼 User.objects.create_user(username="testaccount", password="testpassword") 로 생성하시면 정상적으로 작동할 것 같네요. create_user의 함수 구현을 보시면 email 의 default value는 None입니다. 따라서, 위와같이 각 값이 어느 인자에 대한 값인지를 명시해주시면 됩니다.