2024. 2. 29. 15:01

2024. 2. 28. 15:35

1. 인증 담당 앱 생성

 

python manage.py startapp xauth

 

2. INSTALLED_APPS 에 xauth 등록

 

INSTALLED_APPS = [

    'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'xauth'

]

 

3. xauth.models.py 에서 AbstractUser를 상속받아 XUser 생성

class XUser(AbstractUser):

  nation = models.CharField(max_length=50)

  USERNAME_FIELD = "email"

 

4. settings.py 에 AUTH_USER_MODEL 등록

AUTH_USER_MODEL = 'xauth.XUser'

5. xauth.admin.py 에서 Admin 에 XUser 등록

admin.site.register(XUser)

 

6. DB 테이블 생성

python manage.py makemigrations

 

python manage.py migrate

 

7. urls.py 에 auth 경로 작성

from django.contrib import admin

from django.urls import path, include


urlpatterns = [

    path('admin/', admin.site.urls),

    path('auth/', include('xauth.urls'))

]

 

8. xauth.urls.py 작성

urlpatterns = [

  path('login/', views.loginx, name="loginx"),

  path('logout/', views.logoutx, name="logoutx"),

  path('signup/', views.signupx, name="signupx")

]

 

9. 회원가입 코드 생성

def signupx(request):

  if request.method == "POST":

    username = request.POST['username']

    password = request.POST['password']

    email = request.POST['email']

    nation = request.POST['nation']


    user = User.objects.create_user(username, email, password)

    user.nation= nation

    user.save()

    return redirect('users:login')

10. login 코드 생성

def loginx(request):

  if request.method == "POST":

    post = request.POST

    email = post['email']

    password = post['password']

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

    if user is not None: # login success

      res = login(request, user)

      print(f'res : {res}')

      print('auth success~!')

    else:

      print('auth failed~!')

 

11. logout 코드 생성

def logoutx(request):

  logout(request)

  return redirect('users:login')

12. 버그 수정

XUser 에서 email로 로그인을 하기 위해

 

USERNAME_FIELD 를 설정하면 버그 발생한다

 

AbstractUser 에서 변경해야 함

 

1. email 항목 unique 추가

email = models.EmailField(_("email address"), unique=True, blank=True)

 

2. REQUIRED_FILEDS 에서 email 삭제

#REQUIRED_FIELDS = ["email"]

 

3. createsuperuser 실행할 때 버그 수정

 

AbstractUser 클래스에서

REQUIRED_FIELDS = ["username"]

항목 추가

 

12. 로그인 로그아웃 테스트

2024. 2. 28. 15:00

settings.py 에서

 

LANGUAGE_CODE = 'ko-kr'

 

TIME_ZONE = ''Asia/Seoul"

 

로 변경

2024. 2. 28. 09:20

users_user 테이블의 username이 유일하지 않다

즉 중복 입력했다 이런 뜻이다

 

 

2024. 2. 27. 12:44

1. 우분투 업데이트 및 업그레이드
 - sudo apt update
 - sudo apt upgrade
2. nginx 설치
 - sudo apt install nginx
3. mariadb server 설치
 - sudo apt install mariadb-server
4. DB 보안 설정을 위한 mysql_secure_installation 설치
 - sudo mysql_secure_installation
5. MariaDB root 계정 비밀번호 설정
 - set password for ‘root’@'localhost'=password('new_pass');
 - flush privileges;

6. 외부 접속 IP 허용 주소 변경
 - sudo /etc/mysql/mariadb.conf.d/50-server.cnf
 - bind-address : * 으로 변경
 - netstat -ltnp → 0.0.0.0:3306 확인
7. 포트 3306 방화벽 해제
 - sudo firewall-cmd --permanant --zone=public --add-port=3306/tcp
8. 외부 IP 접속 허용
 - mysql > GRANT ALL PRIVILEGES ON *.* too root@'%' identified by ‘password’;
9. 외부에서 DB 접속 확인
 IP :
 ID: root
 password : password


10. 외부 접속 권한 설정

DB 접속

grant all privileges on *.* to 'root'@'%' identified by 'new password';

flush privileges;

2024. 2. 22. 10:33

cd /etc/mysql/mariadb/conf.d

 

vi 50-server.cnf

 

10060 : 방화벽 차단 에러

 

10061 : mysql.conf.d bind_address=* 

 

IP 접근 에러

 

netstat -lntp

2024. 2. 22. 10:07

 

wheel 을 동작하다가 pkg-config 를 못찾겠어서 나온 버그

 

pkg-config 를 설치해주면 된다

 

pip install pkg-config

 

에러 메세지는 길더라도 차분히 읽어봐야 한다

2024. 2. 21. 17:13

MariaDB 10.5 이상의 버전은 mysql의 user 테이블이 

 

뷰테이블이라서 아래와 같이 하면 된다

 

> set password for 'root'@'localhost'=password('비밀번호')

 

변경사항 반영

 

> flush privileges;

2024. 2. 21. 09:51

현재 시간 확인

 

date

 

한국시간 설정

 

sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime

2024. 2. 21. 09:15

WSL2 설치

컴퓨터 연구/Linux 2024. 2. 21. 09:15

wsl --intstall

 

리부팅

 

wsl --set-default-version 2

 

wsl --version

2024. 2. 20. 15:00

sudo mysql_secure_installation

2024. 2. 20. 13:31

내가 진짜 그지도 아니고 단돈 몇 만원 벌어보겠다고

 

이 깔끔한 블로그에 광고를 붙여본 것에 대해 

 

반성한다

 

순수한 지식을 얻어가고

 

기쁨을 얻는 것에 만족하자

2024. 2. 20. 13:28

ValueError: unsupported format character ';' (0x3b) at index 216

 

이렇게 나오면 파이썬에서 % 가 escape 문자이기 때문에 수정해야 한다

 

width: 100%; 

 

대신에

 

width: 100%%;

 

이렇게 써야 나온다

2024. 2. 20. 11:15

python manage.py migrate 

 

장고 프로젝트에 미리 정의된 내역대로 데이터베이스 테이블 생성

 

python manage.py createsuperuser

 

슈퍼 유저 계정 생성

2024. 2. 20. 11:10

settings.py 를 참조하면 몇 개 없지만

 

/django/conf/global_settings.py 를 보면

 

690 개가 기본적으로 생성되어 있다

 

이것들과 이름이 같아야 재정의를 

 

올바르게 할 수 있다