<reponame>yuniithings/yuniithings.com<filename>adminApp/admin/viewpackages/login.py
from django import forms
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.template import Context
from django.template.loader import get_template
from admin.models import TblAdmin

def loginView(request):
    context = {}
    return render(request, 'login/login_view.html', context)

def loginAction(request):
    form = LoginForm()
    code = '1000'
    msg = ''

    # 요청 method 확인
    if request.method != 'POST':
        code = '-1'
        msg = '잘못된 요청입니다.'

    # 데이터 유효성검사
    if code != '-1':
        admin_id = request.POST['admin_id']
        admin_pwd = request.POST['admin_pwd']

        queryset = TblAdmin.objects.raw('''SELECT
            admin_idx
            FROM tbl_admin
            WHERE 
            admin_id = FN_ENC(%s)
            AND admin_pwd = <PASSWORD> ,<PASSWORD>)
        ''', [admin_id, admin_pwd])

        if not queryset:
            request.session['admin_idx'] = queryset[0].admin_idx
            code = '1000'
            msg = '로그인되었습니다.'
        else:
            code = '-1'
            msg = '아이디와 비밀번호를 확인해주세요.'
    else:
        code = '-1'
        msg = '잘못된 요청입니다(2.'

    # jsno으로 보낼 object
    context = {
        'code': code,
        'code_msg': msg
    }

    return JsonResponse(context, json_dumps_params={'ensure_ascii': True})


class LoginForm(forms.ModelForm):

    class Meta:
        model = TblAdmin
        fields = (
            'admin_id',
            'admin_pwd'
        )

from django import forms
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.template import Context
from django.template.loader import get_template
from admin.models import TblAdmin

def loginView(request):
    context = {}
    return render(request, 'login/login_view.html', context)

def loginAction(request):
    form = LoginForm()
    code = '1000'
    msg = ''

    # 요청 method 확인
    if request.method != 'POST':
        code = '-1'
        msg = '잘못된 요청입니다.'

    # 데이터 유효성검사
    if code != '-1':
        admin_id = request.POST['admin_id']
        admin_pwd = request.POST['admin_pwd']

        queryset = TblAdmin.objects.raw('''SELECT
            admin_idx
            FROM tbl_admin
            WHERE 
            admin_id = FN_ENC(%s)
            AND admin_pwd = <PASSWORD> ,<PASSWORD>)
        ''', [admin_id, admin_pwd])

        if not queryset:
            request.session['admin_idx'] = queryset[0].admin_idx
            code = '1000'
            msg = '로그인되었습니다.'
        else:
            code = '-1'
            msg = '아이디와 비밀번호를 확인해주세요.'
    else:
        code = '-1'
        msg = '잘못된 요청입니다(2.'

    # jsno으로 보낼 object
    context = {
        'code': code,
        'code_msg': msg
    }

    return JsonResponse(context, json_dumps_params={'ensure_ascii': True})


class LoginForm(forms.ModelForm):

    class Meta:
        model = TblAdmin
        fields = (
            'admin_id',
            'admin_pwd'
        )
# 요청 method 확인 # 데이터 유효성검사 SELECT             admin_idx             FROM tbl_admin             WHERE              admin_id = FN_ENC(%s)             AND admin_pwd = <PASSWORD> ,<PASSWORD>) # jsno으로 보낼 object