Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session10 assignment - 21_윤현지 #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions 21_윤현지/session10/account/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from .models import User

admin.site.register(User)

# Register your models here.
6 changes: 6 additions & 0 deletions 21_윤현지/session10/account/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'account'
46 changes: 46 additions & 0 deletions 21_윤현지/session10/account/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 3.2.5 on 2021-07-09 10:41

import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('nickname', models.CharField(max_length=50)),
('university', models.CharField(max_length=50)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions 21_윤현지/session10/account/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.db import models
from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
nickname = models.CharField(max_length=50)
university = models.CharField(max_length=50)
# Create your models here.
4 changes: 4 additions & 0 deletions 21_윤현지/session10/account/static/css/home.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.header {
display: flex;
border-bottom: 2px solid skyblue;
}
42 changes: 42 additions & 0 deletions 21_윤현지/session10/account/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta mane="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/base.css' %}">
<link rel="stylesheet" href="{% block link %}{% endblock %}">
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<div class="header">
<a href="{% url 'home' %}">
<button>홈</button>
</a>
{% if user.is_authenticated %}
<p><strong>{{ user.username }}님 환영합니다 !</strong></p>
<a href = "{% url 'logout' %}">
<button>로그아웃</button>
</a>
<a href = "{% url 'mypage' %}">
<button>내 정보</button>
</a>
<a href="{% url 'create' %}">
<button>글쓰기</button>
</a>

{% else %}
<p><strong>로그인이 필요합니다.</strong></p>
<a href="{% url 'login' %}">
<button>로그인</button>
</a>
<a href="{% url 'signup' %}">
<button>회원가입</button>
</a>
{% endif %}
</div>
{% block content %}
{% endblock %}
</body>
</html>
12 changes: 12 additions & 0 deletions 21_윤현지/session10/account/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}login{% endblock %}
{% block content %}
<form method="POST" action="{% url 'login' %}">
{% csrf_token %}
<input type="text" name="username" placeholder="아이디를 입력하세요."><br>
<input type="password" name="password" placeholder="비밀번호를 입력하세요."><br>
<button>로그인</button>
<p>{{ error }}</p>
</form>
{% endblock %}
12 changes: 12 additions & 0 deletions 21_윤현지/session10/account/templates/mypage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}mypage{% endblock %}
{% block content %}
<h2>내 정보</h2>
<span>아이디: </span>
<span>{{user.username}}</span><br>
<span>별명: </span>
<span>{{user.nickname}}</span><br>
<span>대학교: </span>
<span>{{user.university}}</span>
{% endblock %}
14 changes: 14 additions & 0 deletions 21_윤현지/session10/account/templates/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}signup{% endblock %}
{% block content %}
<form method="POST" action="{% url 'signup' %}">
{% csrf_token %}
<input type="text" name="username" placeholder="아이디를 입력하세요."><br>
<input type="text" name="nickname" placeholder="별명을 입력하세요."><br>
<input type="text" name="university" placeholder="재학 중인 대학교를 입력하세요."><br>
<input type="password" name="password" placeholder="비밀번호를 입력하세요."><br>
<input type="password" name="password2" placeholder="비밀번호를 한 번 더 입력하세요."><br>
<button>회원가입</button>
</form>
{% endblock %}
3 changes: 3 additions & 0 deletions 21_윤현지/session10/account/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
9 changes: 9 additions & 0 deletions 21_윤현지/session10/account/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path
from . import views

urlpatterns = [
path('signup', views.user_signup, name="signup"),
path('login', views.user_login, name="login"),
path('logout', views.user_logout, name="logout"),
path('mypage', views.mypage, name="mypage"),
]
60 changes: 60 additions & 0 deletions 21_윤현지/session10/account/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout

from .models import User
from django.contrib import auth

# Create your views here.

#def home(request):
# return render(request, 'home.html')

def user_signup(request):

if request.method == "POST":

if request.POST["password"] == request.POST["password"]:
user = User.objects.create_user(

username = request.POST["username"],
password = request.POST["password"],

nickname = request.POST["nickname"],
university = request.POST["university"],
)

user.save()
auth.login(request, user)
return redirect('home')

else :
return render(request, 'signup.html')

else :
return render(request, 'signup.html')

def user_login(request):

if request.method == "POST":
username = request.POST["username"]
password = request.POST["password"]

user = authenticate(username = username, password = password)

if user is not None :

login(request, user)
return redirect('home')

else :
return render(request, 'login.html', {'error' : '아이디와 비밀번호가 맞지 않습니다.'})

else :
return render(request, 'login.html')

def user_logout(request) :
logout(request)
return redirect('home')

def mypage(request) :
return render(request, 'mypage.html')
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions 21_윤현지/session10/board/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Board
# Register your models here.

admin.site.register(Board)
6 changes: 6 additions & 0 deletions 21_윤현지/session10/board/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BoardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'board'
27 changes: 27 additions & 0 deletions 21_윤현지/session10/board/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.5 on 2021-07-16 09:35

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Board',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('body', models.TextField()),
('pub_date', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
22 changes: 22 additions & 0 deletions 21_윤현지/session10/board/migrations/0002_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.5 on 2021-07-16 14:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('board', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Comment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('author', models.CharField(max_length=50)),
('date', models.DateTimeField()),
('content', models.CharField(max_length=200)),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions 21_윤현지/session10/board/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.db import models
from django.utils import timezone

# Create your models here.
class Board(models.Model) :
title = models.CharField(max_length=100)
body = models.TextField()
pub_date = models.DateTimeField()
author = models.ForeignKey('account.User', on_delete=models.CASCADE)

def __str__(self) :
return self.title

class Comment(models.Model):
author = models.CharField(max_length=50)
date = models.DateTimeField()
content = models.CharField(max_length=200)

def __str__(self):
return self.title
4 changes: 4 additions & 0 deletions 21_윤현지/session10/board/static/css/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.header {
display: flex;
border-bottom: 2px soild skyblue;
}
42 changes: 42 additions & 0 deletions 21_윤현지/session10/board/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta mane="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/base.css' %}">
<link rel="stylesheet" href="{% block link %}{% endblock %}">
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<div class="header">
<a href="{% url 'home' %}">
<button>홈</button>
</a>
{% if user.is_authenticated %}
<p><strong>{{ user.username }}님 환영합니다 !</strong></p>
<a href = "{% url 'logout' %}">
<button>로그아웃</button>
</a>
<a href = "{% url 'mypage' %}">
<button>내 정보</button>
</a>
<a href="{% url 'create' %}">
<button>글쓰기</button>
</a>

{% else %}
<p><strong>로그인이 필요합니다.</strong></p>
<a href="{% url 'login' %}">
<button>로그인</button>
</a>
<a href="{% url 'signup' %}">
<button>회원가입</button>
</a>
{% endif %}
</div>
{% block content %}
{% endblock %}
</body>
</html>
Loading