views.py
3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from django.views.generic.base import TemplateView
from django.views.generic.edit import CreateView
from django.views import View
from django.urls import reverse_lazy
from django.contrib.auth.forms import UserCreationForm
from django.http import HttpResponseRedirect, HttpResponse
from VulnNotti.forms import *;
from django.shortcuts import redirect, render
from django.db import connection
class HomeView(View):
template_name = 'index.html'
def get(self, request, *args, **kwargs):
# if not request.user.is_authenticated(): # 로그인한 사용자만 가능
# return HttpResponseRedirect(reverse('login'))
#
# query = 'SELECT name, code FROM server WHERE 1=1'
# param_list = []
#
# with connection.cursor() as cursor:
# cursor.execute(query, param_list)
#
# columns = [column[0] for column in cursor.description]
# object_list = []
#
# for row in cursor.fetchall():
# object_list.append(dict(zip(columns, row)))
#
# context = {}
# context['form'] = ServerList_form
# context['object_list'] = object_list
context = {}
context['user_name'] = str(request.user)
return render(self.request, self.template_name, context)
def post(self, request, *args, **kwargs):
name = self.request.POST['name']
email = self.request.POST['email']
phone = self.request.POST['phone']
message = self.request.POST['message']
print(name, email, phone, message)
return render(self.request, self.template_name)
# form = self.form_class(request.POST)
# instance = self.request.POST['instance']
# ipaddr = self.request.POST['ipaddr']
#
# query = "INSERT INTO mysqldb VALUES (%s, %s);"
# param_list = []
# param_list.append(instance, ipaddr)
#
# with connection.cursor() as cursor:
# cursor.execute(query, param_list)
class EditView(TemplateView):
template_name = 'registration/edit.html'
success_url = reverse_lazy('register_done')
def get(self, request, *args, **kwargs):
context = {}
red = 10
context['red'] = red
context['form'] = UserEditForm
return render(self.request, self.template_name, context)
def post(self, request, *args, **kwargs):
repository = self.request.POST['repository']
user = request.user
query = "UPDATE vuln.auth_user SET repository = %s WHERE username = %s"
param_list = []
param_list.append(str(repository))
param_list.append(str(user))
with connection.cursor() as cursor:
cursor.execute(query, param_list)
print(repository, user)
return render(self.request, 'index.html')
class UserCreateView(CreateView):
template_name = 'registration/register.html'
success_url = reverse_lazy('register_done')
form_class = UserCreationForm
class UserCreateDoneTV(TemplateView):
template_name = 'registration/register_done.html'