ewhk9887/korean_code_reviews_from_github huggingface dataset:
@@ -0,0 +1,12 @@
+from django.db import models
+
+class User(models.Model):
+
+    email   = models.EmailField(max_length=50, unique=True)
+    name    = models.CharField(max_length=50, unique=True)
+    phone   = models.CharField(max_length=50, unique=True)
+    password= models.CharField(max_length=500) 
+
+    class Meta:
+        db_table='users'
+

리뷰: - email 은 가독성을 위해, 그리고 추후 장고 Form 이 제공하는 validator 를 사용할 수도 있을 것을 감안해서 EmailField 로 선언해주세요!
- 그리고 email 은 고유값이죠? 이럴때 추가해줄 수 있는 옵션이 있습니다! 찾아서 추가해주세요~
@@ -0,0 +1,12 @@
+from django.db import models
+
+class User(models.Model):
+
+    email   = models.EmailField(max_length=50, unique=True)
+    name    = models.CharField(max_length=50, unique=True)
+    phone   = models.CharField(max_length=50, unique=True)
+    password= models.CharField(max_length=500) 
+
+    class Meta:
+        db_table='users'
+

리뷰: 보통 데이터베이스 컬럼명은 줄여쓰지않고 최대한 명확하게 풀어서 선언해줍니다. 여기는 password 로 풀어주세요~
그리고 이제 비밀번호 암호화 과정을 진행하는만큼 최대 글자수를 조금 더 넉넉하게 잡아주시는게 좋습니다!
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder     import JSONDecodeError
+
+from django.db.models import Q
+from django.views     import View
+from django.http      import JsonResponse
+
+from .models          import User
+from my_settings      import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+    def post(self, request):
+        try:
+            data    = json.loads(request.body)
+            name    = data['name']
+            email   = data['email']
+            phone   = data['phone']
+            password= data['password']
+
+            if '.' not in email or '@' not in email:
+                return JsonResponse({'message':'error_email_form'}, status=401)            
+
+            if len(password)<8: 
+                return JsonResponse({'message':'error_password_form'}, status=401)            
+
+            if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+                return JsonResponse({'message':'id_exist'}, status = 401)           
+               
+            hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+            decoded_password= hashed_password.decode('utf-8')
+            
+            User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+            return JsonResponse({'message':'success_signup'}, status = 201)
+
+        except KeyError:
+                return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+        
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)        
+        
+
+class SignInView(View):
+    def post(self, request):
+        try:    
+            data    = json.loads(request.body)
+            id      = data['id']
+            password= data['password']
+            user  = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+            if user is not id:
+                return JsonResponse({'message':'error_id_matching'}, status=401)
+
+            if user is id:
+                decoded_password = user.password
+                encoded_password = password.encode('utf-8')
+                bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+                token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+                return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+            
+            return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+        except User.MultipleObjectsReturned:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+        except User.DoesNotExist:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)            
+
+        except KeyError:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)            
+
+
+

리뷰: - exists 메소드 너무 잘 활용하셨네요!! 👍
- 여기서 exists 의 결과를 따로 변수에 저장해줄것 없이 아래 if 문에 바로 적용해주신다면 불필요한 변수 선언을 없앨 수 있겠죠?!
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder     import JSONDecodeError
+
+from django.db.models import Q
+from django.views     import View
+from django.http      import JsonResponse
+
+from .models          import User
+from my_settings      import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+    def post(self, request):
+        try:
+            data    = json.loads(request.body)
+            name    = data['name']
+            email   = data['email']
+            phone   = data['phone']
+            password= data['password']
+
+            if '.' not in email or '@' not in email:
+                return JsonResponse({'message':'error_email_form'}, status=401)            
+
+            if len(password)<8: 
+                return JsonResponse({'message':'error_password_form'}, status=401)            
+
+            if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+                return JsonResponse({'message':'id_exist'}, status = 401)           
+               
+            hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+            decoded_password= hashed_password.decode('utf-8')
+            
+            User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+            return JsonResponse({'message':'success_signup'}, status = 201)
+
+        except KeyError:
+                return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+        
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)        
+        
+
+class SignInView(View):
+    def post(self, request):
+        try:    
+            data    = json.loads(request.body)
+            id      = data['id']
+            password= data['password']
+            user  = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+            if user is not id:
+                return JsonResponse({'message':'error_id_matching'}, status=401)
+
+            if user is id:
+                decoded_password = user.password
+                encoded_password = password.encode('utf-8')
+                bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+                token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+                return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+            
+            return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+        except User.MultipleObjectsReturned:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+        except User.DoesNotExist:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)            
+
+        except KeyError:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)            
+
+
+

리뷰: or, not, in 활용 너무 좋습니다 호열님!!! 그런데 email 을 list 로 형변환해주신 이유가 있을까요?
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder     import JSONDecodeError
+
+from django.db.models import Q
+from django.views     import View
+from django.http      import JsonResponse
+
+from .models          import User
+from my_settings      import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+    def post(self, request):
+        try:
+            data    = json.loads(request.body)
+            name    = data['name']
+            email   = data['email']
+            phone   = data['phone']
+            password= data['password']
+
+            if '.' not in email or '@' not in email:
+                return JsonResponse({'message':'error_email_form'}, status=401)            
+
+            if len(password)<8: 
+                return JsonResponse({'message':'error_password_form'}, status=401)            
+
+            if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+                return JsonResponse({'message':'id_exist'}, status = 401)           
+               
+            hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+            decoded_password= hashed_password.decode('utf-8')
+            
+            User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+            return JsonResponse({'message':'success_signup'}, status = 201)
+
+        except KeyError:
+                return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+        
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)        
+        
+
+class SignInView(View):
+    def post(self, request):
+        try:    
+            data    = json.loads(request.body)
+            id      = data['id']
+            password= data['password']
+            user  = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+            if user is not id:
+                return JsonResponse({'message':'error_id_matching'}, status=401)
+
+            if user is id:
+                decoded_password = user.password
+                encoded_password = password.encode('utf-8')
+                bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+                token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+                return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+            
+            return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+        except User.MultipleObjectsReturned:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+        except User.DoesNotExist:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)            
+
+        except KeyError:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)            
+
+
+

리뷰: 위에 리뷰 내용 반영해주시면 이 부분에 수정사항이 생기겠죠!?
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder     import JSONDecodeError
+
+from django.db.models import Q
+from django.views     import View
+from django.http      import JsonResponse
+
+from .models          import User
+from my_settings      import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+    def post(self, request):
+        try:
+            data    = json.loads(request.body)
+            name    = data['name']
+            email   = data['email']
+            phone   = data['phone']
+            password= data['password']
+
+            if '.' not in email or '@' not in email:
+                return JsonResponse({'message':'error_email_form'}, status=401)            
+
+            if len(password)<8: 
+                return JsonResponse({'message':'error_password_form'}, status=401)            
+
+            if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+                return JsonResponse({'message':'id_exist'}, status = 401)           
+               
+            hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+            decoded_password= hashed_password.decode('utf-8')
+            
+            User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+            return JsonResponse({'message':'success_signup'}, status = 201)
+
+        except KeyError:
+                return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+        
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)        
+        
+
+class SignInView(View):
+    def post(self, request):
+        try:    
+            data    = json.loads(request.body)
+            id      = data['id']
+            password= data['password']
+            user  = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+            if user is not id:
+                return JsonResponse({'message':'error_id_matching'}, status=401)
+
+            if user is id:
+                decoded_password = user.password
+                encoded_password = password.encode('utf-8')
+                bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+                token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+                return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+            
+            return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+        except User.MultipleObjectsReturned:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+        except User.DoesNotExist:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)            
+
+        except KeyError:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)            
+
+
+

리뷰: `or` 과 `is` 중에 어떤게 우선순위일까요? 조건문에서 operator precedence 에 따라 조건이 완전히 바뀔 수 있기 때문에 잘 파악하고 사용하시는게 좋습니다!
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder     import JSONDecodeError
+
+from django.db.models import Q
+from django.views     import View
+from django.http      import JsonResponse
+
+from .models          import User
+from my_settings      import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+    def post(self, request):
+        try:
+            data    = json.loads(request.body)
+            name    = data['name']
+            email   = data['email']
+            phone   = data['phone']
+            password= data['password']
+
+            if '.' not in email or '@' not in email:
+                return JsonResponse({'message':'error_email_form'}, status=401)            
+
+            if len(password)<8: 
+                return JsonResponse({'message':'error_password_form'}, status=401)            
+
+            if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+                return JsonResponse({'message':'id_exist'}, status = 401)           
+               
+            hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+            decoded_password= hashed_password.decode('utf-8')
+            
+            User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+            return JsonResponse({'message':'success_signup'}, status = 201)
+
+        except KeyError:
+                return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+        
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)        
+        
+
+class SignInView(View):
+    def post(self, request):
+        try:    
+            data    = json.loads(request.body)
+            id      = data['id']
+            password= data['password']
+            user  = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+            if user is not id:
+                return JsonResponse({'message':'error_id_matching'}, status=401)
+
+            if user is id:
+                decoded_password = user.password
+                encoded_password = password.encode('utf-8')
+                bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+                token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+                return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+            
+            return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+        except User.MultipleObjectsReturned:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+        except User.DoesNotExist:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)            
+
+        except KeyError:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)            
+
+
+

리뷰: 이제 bcrypt 를 활용하여 비밀번호 암호화 로직 추가해서 저장해주세요!
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder     import JSONDecodeError
+
+from django.db.models import Q
+from django.views     import View
+from django.http      import JsonResponse
+
+from .models          import User
+from my_settings      import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+    def post(self, request):
+        try:
+            data    = json.loads(request.body)
+            name    = data['name']
+            email   = data['email']
+            phone   = data['phone']
+            password= data['password']
+
+            if '.' not in email or '@' not in email:
+                return JsonResponse({'message':'error_email_form'}, status=401)            
+
+            if len(password)<8: 
+                return JsonResponse({'message':'error_password_form'}, status=401)            
+
+            if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+                return JsonResponse({'message':'id_exist'}, status = 401)           
+               
+            hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+            decoded_password= hashed_password.decode('utf-8')
+            
+            User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+            return JsonResponse({'message':'success_signup'}, status = 201)
+
+        except KeyError:
+                return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+        
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)        
+        
+
+class SignInView(View):
+    def post(self, request):
+        try:    
+            data    = json.loads(request.body)
+            id      = data['id']
+            password= data['password']
+            user  = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+            if user is not id:
+                return JsonResponse({'message':'error_id_matching'}, status=401)
+
+            if user is id:
+                decoded_password = user.password
+                encoded_password = password.encode('utf-8')
+                bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+                token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+                return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+            
+            return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+        except User.MultipleObjectsReturned:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+        except User.DoesNotExist:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)            
+
+        except KeyError:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)            
+
+
+

리뷰: CREATED 를 의미하는 201 사용 너무 잘하셨습니다! 😉
@@ -0,0 +1,12 @@
+from django.db import models
+
+class User(models.Model):
+
+    email   = models.EmailField(max_length=50, unique=True)
+    name    = models.CharField(max_length=50, unique=True)
+    phone   = models.CharField(max_length=50, unique=True)
+    password= models.CharField(max_length=500) 
+
+    class Meta:
+        db_table='users'
+

리뷰: 휴대폰 번호도 고유값이니 위처럼 고유값을 뜻하는 옵션을 추가해주셔야 합니다!
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder     import JSONDecodeError
+
+from django.db.models import Q
+from django.views     import View
+from django.http      import JsonResponse
+
+from .models          import User
+from my_settings      import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+    def post(self, request):
+        try:
+            data    = json.loads(request.body)
+            name    = data['name']
+            email   = data['email']
+            phone   = data['phone']
+            password= data['password']
+
+            if '.' not in email or '@' not in email:
+                return JsonResponse({'message':'error_email_form'}, status=401)            
+
+            if len(password)<8: 
+                return JsonResponse({'message':'error_password_form'}, status=401)            
+
+            if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+                return JsonResponse({'message':'id_exist'}, status = 401)           
+               
+            hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+            decoded_password= hashed_password.decode('utf-8')
+            
+            User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+            return JsonResponse({'message':'success_signup'}, status = 201)
+
+        except KeyError:
+                return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+        
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)        
+        
+
+class SignInView(View):
+    def post(self, request):
+        try:    
+            data    = json.loads(request.body)
+            id      = data['id']
+            password= data['password']
+            user  = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+            if user is not id:
+                return JsonResponse({'message':'error_id_matching'}, status=401)
+
+            if user is id:
+                decoded_password = user.password
+                encoded_password = password.encode('utf-8')
+                bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+                token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+                return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+            
+            return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+        except User.MultipleObjectsReturned:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+        except User.DoesNotExist:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=401)            
+
+        except KeyError:
+            return JsonResponse({'message': 'KEY_ERROR'}, status=400)            
+
+        except JSONDecodeError:
+            return JsonResponse({'message': 'JSONDecodeError'}, status=400)            
+
+
+

리뷰: 불필요한 주석 제외하고 올려주세요.