diff --git a/backend/Untitled.ipynb b/backend/Untitled.ipynb index b8bcc38..195ae5f 100644 --- a/backend/Untitled.ipynb +++ b/backend/Untitled.ipynb @@ -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\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:1050\u001b[0m in \u001b[1;35m_gcd_import\u001b[0m\n", + " File \u001b[1;32m:1027\u001b[0m in \u001b[1;35m_find_and_load\u001b[0m\n", + " File \u001b[1;32m:1006\u001b[0m in \u001b[1;35m_find_and_load_unlocked\u001b[0m\n", + " File \u001b[1;32m:688\u001b[0m in \u001b[1;35m_load_unlocked\u001b[0m\n", + " File \u001b[1;32m:879\u001b[0m in \u001b[1;35mexec_module\u001b[0m\n", + " File \u001b[1;32m:1017\u001b[0m in \u001b[1;35mget_code\u001b[0m\n", + " File \u001b[1;32m:947\u001b[0m in \u001b[1;35msource_to_code\u001b[0m\n", + "\u001b[0;36m File \u001b[0;32m: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", @@ -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": [] } diff --git a/backend/backend/urls.py b/backend/backend/urls.py index 996b207..fb8e3b7 100644 --- a/backend/backend/urls.py +++ b/backend/backend/urls.py @@ -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')), ] diff --git a/backend/rebiketrash/urls.py b/backend/rebiketrash/urls.py index e69de29..79b2c23 100644 --- a/backend/rebiketrash/urls.py +++ b/backend/rebiketrash/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from . import views + + +urlpatterns = [ + +] diff --git a/backend/rebikeuser/admin.py b/backend/rebikeuser/admin.py new file mode 100644 index 0000000..1c6dd89 --- /dev/null +++ b/backend/rebikeuser/admin.py @@ -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'] diff --git a/backend/rebikeuser/forms.py b/backend/rebikeuser/forms.py new file mode 100644 index 0000000..84d8d10 --- /dev/null +++ b/backend/rebikeuser/forms.py @@ -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" ) diff --git a/backend/rebikeuser/models.py b/backend/rebikeuser/models.py index d6d3a60..8334957 100644 --- a/backend/rebikeuser/models.py +++ b/backend/rebikeuser/models.py @@ -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 diff --git a/backend/rebikeuser/templates/signup.html b/backend/rebikeuser/templates/signup.html new file mode 100644 index 0000000..bc64038 --- /dev/null +++ b/backend/rebikeuser/templates/signup.html @@ -0,0 +1,17 @@ +회원가입 페이지 +
+ +
+ {% csrf_token %} + + + + + + + + + + + +
\ No newline at end of file diff --git a/backend/rebikeuser/urls.py b/backend/rebikeuser/urls.py index d720e89..34d79bf 100644 --- a/backend/rebikeuser/urls.py +++ b/backend/rebikeuser/urls.py @@ -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), +] \ No newline at end of file diff --git a/backend/rebikeuser/userUtil.py b/backend/rebikeuser/userUtil.py index f02c438..b692712 100644 --- a/backend/rebikeuser/userUtil.py +++ b/backend/rebikeuser/userUtil.py @@ -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) diff --git a/backend/rebikeuser/views.py b/backend/rebikeuser/views.py index 9463586..6556ac0 100644 --- a/backend/rebikeuser/views.py +++ b/backend/rebikeuser/views.py @@ -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): @@ -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') \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 49329df..4d76a8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,4 +14,4 @@ services: # ports: # - 3000:3000 # volumes: -# - ./frontend:/app \ No newline at end of file +# - ./frontend:/app