diff --git a/backend/Untitled.ipynb b/backend/Untitled.ipynb deleted file mode 100644 index 4545520..0000000 --- a/backend/Untitled.ipynb +++ /dev/null @@ -1,121 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "0d104680", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "import os\n", - "os.environ['DJANGO_SETTINGS_MODULE'] = \"backend.settings\"\n", - "os.environ[\"DJANGO_ALLOW_ASYNC_UNSAFE\"] = \"true\"\n", - "\n", - "import django\n", - "django.setup()" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "b48ed5fa", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [ - "from rebikeuser.models import User" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "4c259257", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - ", , ]>" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "qs = User.objects.all()\n", - "qs" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "1ae3deb3", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'1234'" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "qs[1].user_pw" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "efd36010", - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.2" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file 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 index 13667d2..1c6dd89 100644 --- a/backend/rebikeuser/admin.py +++ b/backend/rebikeuser/admin.py @@ -4,5 +4,5 @@ @admin.register(User) class UserAdmin(admin.ModelAdmin): - list_display = ['id', 'user_name', 'user_alias', 'user_pw', 'user_email'] + 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 53b0a7d..8334957 100644 --- a/backend/rebikeuser/models.py +++ b/backend/rebikeuser/models.py @@ -5,8 +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.CharField(max_length=64) 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 76441c8..ea2de93 100644 --- a/backend/rebikeuser/urls.py +++ b/backend/rebikeuser/urls.py @@ -2,6 +2,7 @@ from . import views -urlpatterns =[ - path('login/', views.on_login) -] \ No newline at end of file +urlpatterns = [ + path('login/', views.on_login, name='login'), + path('signup/', views.signup, name='signup'), +] diff --git a/backend/rebikeuser/views.py b/backend/rebikeuser/views.py index 2988630..67eddb8 100644 --- a/backend/rebikeuser/views.py +++ b/backend/rebikeuser/views.py @@ -1,6 +1,11 @@ from django.http import HttpResponse -from .models import User +from django.utils.datastructures import MultiValueDictKeyError +from django.views.decorators.csrf import csrf_exempt +from .models import User +from .forms import UserForm +from django.contrib.auth import authenticate, login +from django.shortcuts import render, redirect def on_login(request): qs = User.objects.all() @@ -8,3 +13,55 @@ def on_login(request): if username: qs = qs.filter(user_name=username) return HttpResponse(qs) + +# @csrf_exempt +# def signup(request): +# # POST +# if request.method == 'POST': +# # password와 confirm에 입력된 값이 같다면 +# form = UserForm(request.POST) +# if form: +# form.save() +# +# #form에서 하나씩 추출 +# username=form.cleaned_data.get('username') +# raw_password = form.cleaned_data.get('password') +# email=form.cleaned_data.get('email') +# nickname=form.cleaned_data.get('nickname') +# +# #DB저장 +# User.objects.create( +# user_name=username, +# user_alias=nickname, +# user_pw=raw_password, +# user_email=email, +# ) +# +# # 인증 -> 로그인 -> 리디렉션 +# user = authenticate(username=username, password=raw_password) # 사용자 인증 +# login(request, user) +# return redirect('/') +# +# # GET ( "가입 된 회원입니다. ") +# return render(request, 'signup.html') +# # 장고 뷰는 httpresponse가 있어야함 +@csrf_exempt +def signup(request): + + if request.method=='POST': + try: + user_name=request.POST.get['user_name'] + user_alias=request.POST['user_alias'] + user_email=request.POST['user_email'] + user_pw=request.POST['user_pw'] + user_salt=request.POST['user_salt'] + except MultiValueDictKeyError: + user_name=False + + user = User.objects.create_user(user_name,user_email, user_pw) + user.user_alias=user_alias + user.user_salt=user_salt + user.save() + + return redirect('/') + return render(request, "signup.html") diff --git a/backend/requirements.txt b/backend/requirements.txt index 0fae788..aced782 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -5,4 +5,3 @@ PyMySQL==1.0.2 mysql-connector-python==8.0.23 setuptools==58.1.0 mysqlclient==2.1.1 - diff --git a/docker-compose.yml b/docker-compose.yml index 49329df..c28a22e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,10 +8,10 @@ services: - 8080:8080 volumes: - ./backend:/app -# frontend: -# build: ./frontend -# command: ["npm", "start"] -# ports: -# - 3000:3000 -# volumes: -# - ./frontend:/app \ No newline at end of file + frontend: + build: ./frontend + command: ["npm", "start"] + ports: + - 3000:3000 + volumes: + - ./frontend:/app diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..4a661d3 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "reBike-back", + "lockfileVersion": 2, + "requires": true, + "packages": {} +}