Skip to content

Commit

Permalink
Merge branch 'feature/05-BE-SignUp' of https://github.com/HowTrash/Ho…
Browse files Browse the repository at this point in the history
…wTrash-back into feature/05-BE-SignUp
  • Loading branch information
Ryokuman committed Jul 14, 2022
2 parents 17e31be + d1b85fb commit 2260823
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 13 deletions.
59 changes: 57 additions & 2 deletions backend/Untitled.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,31 @@
"name": "#%%\n"
}
},
"outputs": [],
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (models.py, line 8)",
"output_type": "error",
"traceback": [
"Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n",
" File \u001b[1;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/IPython/core/interactiveshell.py:3398\u001b[0m in \u001b[1;35mrun_code\u001b[0m\n exec(code_obj, self.user_global_ns, self.user_ns)\n",
" Input \u001b[1;32mIn [1]\u001b[0m in \u001b[1;35m<cell line: 6>\u001b[0m\n django.setup()\n",
" File \u001b[1;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/__init__.py:24\u001b[0m in \u001b[1;35msetup\u001b[0m\n apps.populate(settings.INSTALLED_APPS)\n",
" File \u001b[1;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/apps/registry.py:116\u001b[0m in \u001b[1;35mpopulate\u001b[0m\n app_config.import_models()\n",
" File \u001b[1;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/apps/config.py:304\u001b[0m in \u001b[1;35mimport_models\u001b[0m\n self.models_module = import_module(models_module_name)\n",
" File \u001b[1;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py:126\u001b[0m in \u001b[1;35mimport_module\u001b[0m\n return _bootstrap._gcd_import(name[level:], package, level)\n",
" File \u001b[1;32m<frozen importlib._bootstrap>:1050\u001b[0m in \u001b[1;35m_gcd_import\u001b[0m\n",
" File \u001b[1;32m<frozen importlib._bootstrap>:1027\u001b[0m in \u001b[1;35m_find_and_load\u001b[0m\n",
" File \u001b[1;32m<frozen importlib._bootstrap>:1006\u001b[0m in \u001b[1;35m_find_and_load_unlocked\u001b[0m\n",
" File \u001b[1;32m<frozen importlib._bootstrap>:688\u001b[0m in \u001b[1;35m_load_unlocked\u001b[0m\n",
" File \u001b[1;32m<frozen importlib._bootstrap_external>:879\u001b[0m in \u001b[1;35mexec_module\u001b[0m\n",
" File \u001b[1;32m<frozen importlib._bootstrap_external>:1017\u001b[0m in \u001b[1;35mget_code\u001b[0m\n",
" File \u001b[1;32m<frozen importlib._bootstrap_external>:947\u001b[0m in \u001b[1;35msource_to_code\u001b[0m\n",
"\u001b[0;36m File \u001b[0;32m<frozen importlib._bootstrap>:241\u001b[0;36m in \u001b[0;35m_call_with_frames_removed\u001b[0;36m\u001b[0m\n",
"\u001b[0;36m File \u001b[0;32m~/Desktop/dev/1.inProgress/HowTrash/backend/rebikeuser/models.py:8\u001b[0;36m\u001b[0m\n\u001b[0;31m <<<<<<< HEAD\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"import os\n",
"os.environ['DJANGO_SETTINGS_MODULE'] = \"backend.settings\"\n",
Expand Down Expand Up @@ -77,9 +101,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "8e4ef4cd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hello\n",
"myname\n"
]
}
],
"source": [
"def user_hash_pw():\n",
" pw = 'hello'\n",
" salt = \"myname\"\n",
" result = {}\n",
" return pw, salt\n",
"\n",
"def returning_param(a , b):\n",
" print(a)\n",
" print(b)\n",
" \n",
"hash_pw, salt = user_hash_pw()\n",
"print(hash_pw)\n",
"print(salt)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ae0f0c11",
"metadata": {},
"outputs": [],
"source": []
}
Expand Down
3 changes: 2 additions & 1 deletion backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

urlpatterns = [
path('admin/', admin.site.urls),
path('user/', include('rebikeuser.urls')),
path('users/', include('rebikeuser.urls')),
path('trashs/', include('rebiketrash.urls')),
]
7 changes: 7 additions & 0 deletions backend/rebiketrash/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path
from . import views


urlpatterns = [

]
8 changes: 8 additions & 0 deletions backend/rebikeuser/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from .models import User


@admin.register(User)
class UserAdmin(admin.ModelAdmin):
list_display = ['id', 'user_name', 'user_alias', 'user_pw', 'user_email','user_salt']
search_fields = ['id']
12 changes: 12 additions & 0 deletions backend/rebikeuser/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User


class UserForm(UserCreationForm):
email = forms.EmailField(label="이메일")
nickname = forms.CharField(max_length=20)

class Meta:
model = User
fields = ( "username", "password", "email", "nickname" )
4 changes: 2 additions & 2 deletions backend/rebikeuser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class User(models.Model):
id = models.AutoField(primary_key=True)
user_name = models.CharField(unique=True, max_length=20)
user_alias = models.CharField(unique=True, max_length=20)
user_pw = models.BinaryField(max_length=60)
user_salt = models.BinaryField(max_length=29)
user_email = models.CharField(unique=True, max_length=50)
user_pw = models.CharField(max_length=60)
user_salt = models.BinaryField(max_length=29)

def __str__(self):
return self.user_name
Expand Down
17 changes: 17 additions & 0 deletions backend/rebikeuser/templates/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
회원가입 페이지
<br>

<form action="" method="POST">
{% csrf_token %}
<input name='user_name' type="text">
<input name='user_alias' type="text">
<input name="user_email", type="text">
<input name='user_pw' type="password">
<input name="user_salt", type="binary">


<input type="submit" value="회원가입">



</form>
5 changes: 3 additions & 2 deletions backend/rebikeuser/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.urls import path
from . import views


urlpatterns = [
path('login/', views.user_login),
path('temp/', views.temp),
]
path('signup/', views.user_signup),
]
15 changes: 15 additions & 0 deletions backend/rebikeuser/userUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
from .models import User


def user_hash_pw(pw):
pw = pw.encode('utf-8')
salt = bcrypt.gensalt()
hash_pw = bcrypt.hashpw(pw, salt)
return hash_pw, salt


def user_createModel(user_id, email, pw, alias):
hash_pw, salt = user_hash_pw(pw)
user = User.objects.create_user(user_id, email, hash_pw)
user.user_alias = alias
user.user_salt = salt
user.save()


def user_findByName(name):
qs = User.objects.all()
result = qs.filter(user_name=name)
Expand Down
18 changes: 13 additions & 5 deletions backend/rebikeuser/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.http import HttpResponse, JsonResponse
from django.core import serializers
from django.views.decorators.csrf import csrf_exempt

from .serializers import UserSerializer
from .userUtil import user_findByName, user_compPW
from .userUtil import user_findByName, user_compPW, user_createModel


def user_login(request):
Expand All @@ -26,6 +26,14 @@ def user_login(request):
return JsonResponse(data)


def temp(request):
test = {'hello': 'hello'}
return JsonResponse(test, safe=False)
@csrf_exempt
def user_signup(request):
if request.method == 'POST':
user_id = request.POST.get['id']
alias = request.POST['alias']
email = request.POST['email']
pw = request.POST['user_pw']

user_createModel(user_id, email, pw, alias)
return HttpResponse(True)
return HttpResponse('it is not post')
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ services:
# ports:
# - 3000:3000
# volumes:
# - ./frontend:/app
# - ./frontend:/app

0 comments on commit 2260823

Please sign in to comment.