Skip to content

Commit

Permalink
ADD: 240523 session upload
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghyen committed Jun 2, 2024
1 parent cfe25e5 commit 10f3f8e
Show file tree
Hide file tree
Showing 49 changed files with 460 additions and 0 deletions.
1 change: 1 addition & 0 deletions session_240523/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
django_coplate_env
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions session_240523/coplate/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.contrib import admin

from django.contrib.auth.admin import UserAdmin
from .models import User


class CustomUserAdmin(UserAdmin):
fieldsets = (
(None, {'fields': ('username', 'password')}),
('Personal info', {'fields': ('first_name', 'last_name', 'email')}),
('Permissions', {
'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions'),
}),
('Important dates', {'fields': ('last_login', 'date_joined')}),
('Custom fields', {'fields': ('nickname',)}), # Add your custom field here
)

admin.site.register(User, CustomUserAdmin)
6 changes: 6 additions & 0 deletions session_240523/coplate/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CoplateConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'coplate'
12 changes: 12 additions & 0 deletions session_240523/coplate/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django import forms
from .models import User

class SignupForm(forms.ModelForm):
class Meta:
model = User
fields = ["nickname"]

def signup(self, request, user):
user.nickname = self.cleaned_data['nickname']
user.save()

44 changes: 44 additions & 0 deletions session_240523/coplate/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 4.2 on 2024-05-25 12:37

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')),
('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()),
],
),
]
18 changes: 18 additions & 0 deletions session_240523/coplate/migrations/0002_user_nickname.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2 on 2024-05-25 13:32

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
migrations.AddField(
model_name='user',
name='nickname',
field=models.CharField(max_length=15, null=True, unique=True),
),
]
19 changes: 19 additions & 0 deletions session_240523/coplate/migrations/0003_alter_user_nickname.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2 on 2024-05-25 13:59

import coplate.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('coplate', '0002_user_nickname'),
]

operations = [
migrations.AlterField(
model_name='user',
name='nickname',
field=models.CharField(error_messages={'unique': '이미 사용중인 닉네임입니다.'}, max_length=15, null=True, unique=True, validators=[coplate.validators.validate_no_special_characters]),
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions session_240523/coplate/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
from .validators import validate_no_special_characters

class User(AbstractUser):
nickname = models.CharField(
max_length=15,
unique=True,
null = True,
validators = [validate_no_special_characters],
error_messages={'unique': '이미 사용 중인 닉네임입니다.'},
)
def __str__(self):
return self.email

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
이메일 인증이 완료되었습니다.
{% if user.is_authenticated %}
<a href="{% url 'index' %}">홈으로 이동</a>
{% else %}
<a href="{% url 'account_login' %}"></a>
{% endif %}
19 changes: 19 additions & 0 deletions session_240523/coplate/templates/coplate/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

<navbar>
{% if user.is_authenticated %}
<a href="{% url 'account_logout' %}">로그아웃</a>
{% else %}
<a href="{% url 'account_login' %}">로그인</a>
<a href="{% url 'account_signup' %}">회원가입</a>
{% endif %}
</navbar>

<h1>홈페이지</h1>

{% if user.is_authenticated %}
<p>{{ user }}님의 닉네임은 {{ user.nickname}}입니다.</p>
<p><a href="{% url 'account_charge_password' %}">비밀번호 변경</a></p>
{% else %}
<p>로그아웃된 상태입니다.</p>
{% endif %}

3 changes: 3 additions & 0 deletions session_240523/coplate/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.
7 changes: 7 additions & 0 deletions session_240523/coplate/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 = [
path('', views.index, name='index'),
]
50 changes: 50 additions & 0 deletions session_240523/coplate/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import string
from django.core.exceptions import ValidationError


def contains_special_character(value):
for char in value:
if char in string.punctuation:
return True
return False


def contains_uppercase_letter(value):
for char in value:
if char in string.ascii_uppercase:
return True
return False


def contains_lowercase_letter(value):
for char in value:
if char in string.ascii_lowercase:
return True
return False


def contains_number(value):
for char in value:
if char in string.digits:
return True
return False


class CustomPasswordValidator:
def validate(self, password, user=None):
if (
len(password) < 8 or
not contains_uppercase_letter(password) or
not contains_lowercase_letter(password) or
not contains_number(password) or
not contains_special_character(password)
):
raise ValidationError("8자 이상의 영문 대/소문자, 숫자, 특수문자 조합이어야 합니다.")

def get_help_text(self):
return "8자 이상의 영문 대/소문자, 숫자, 특수문자 조합을 입력해 주세요."


def validate_no_special_characters(value):
if contains_special_character(value):
raise ValidationError("특수문자를 포함할 수 없습니다.")
11 changes: 11 additions & 0 deletions session_240523/coplate/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.shortcuts import render
from django.urls import reverse
from allauth.account.views import PasswordChangeView


def index(request):
return render(request, 'coplate/index.html')

class CustomPasswordChangeView(PasswordChangeView):
def get_success_url(self):
return reverse("index")
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 16 additions & 0 deletions session_240523/coplate_project/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for coplate_project project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'coplate_project.settings')

application = get_asgi_application()
Loading

0 comments on commit 10f3f8e

Please sign in to comment.