Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit a3ba12de authored by Abdul Mughni Wibisono's avatar Abdul Mughni Wibisono
Browse files

Merge branch 'mughni' into 'main'

Make customer registration

See merge request !24
parents 61cb7372 1c1518aa
No related branches found
No related tags found
1 merge request!24Make customer registration
from django import forms
class customer_form(forms.Form):
email = forms.CharField(label = '', max_length=50, widget = forms.EmailInput(attrs={'class': 'form-control Font-Size-20',
'id': 'email', 'placeholder': "Email"}))
password = forms.CharField(label = '', max_length=20, widget = forms.PasswordInput(attrs={'class': 'form-control Font-Size-20',
'id': 'password', 'placeholder': "Password"}))
phoneNum = forms.CharField(label = '', max_length=20, widget = forms.NumberInput(attrs={'class': 'form-control Font-Size-20',
'id': 'phonenum', 'placeholder': "Phone Number"}))
fname = forms.CharField(label = '', max_length=15, widget = forms.TextInput(attrs={'class': 'form-control Font-Size-20',
'id': 'fname', 'placeholder': "First Name"}))
name = forms.CharField(label = '', max_length=15, widget = forms.TextInput(attrs={'class': 'form-control Font-Size-20',
'id': 'name', 'placeholder': "Last Name"}))
nik = forms.CharField(label = '', max_length=20, widget = forms.TextInput(attrs={'class': 'form-control Font-Size-20',
'id': 'nik', 'placeholder': "NIK"}))
bankname = forms.CharField(label = '', max_length=20, widget = forms.TextInput(attrs={'class': 'form-control Font-Size-20',
'id': 'bankname', 'placeholder': "Bank Name"}))
accountno = forms.CharField(label = '', max_length=20, widget = forms.TextInput(attrs={'class': 'form-control Font-Size-20',
'id': 'accountno', 'placeholder': "Account Number"}))
restopay = forms.CharField(label = '', max_length=25, widget = forms.TextInput(attrs={'class': 'form-control Font-Size-20',
'id': 'restopay', 'placeholder': "RestoPay"}))
birthDate = forms.CharField(label = '', max_length=25, widget = forms.DateInput(attrs={'class': 'form-control Font-Size-20',
'id': 'birthdate', 'placeholder': "Birth Date"}))
sex = forms.CharField(label = '', max_length=1, widget = forms.TextInput(attrs={'class': 'form-control Font-Size-20',
'id': 'sex', 'placeholder': "Sex"}))
......@@ -7,7 +7,24 @@
<title>SIREST</title>
</head>
<body>
<div>
<form method="POST" class="Login-Form" autocomplete="off">
<div class="card text-center" style="margin: 225px 500px auto 500px">
<div class="card-header">
User Registration
</div>
<div class="card-body">
{% csrf_token %}
{{ form.as_p}}
</div>
<div class="card-footer text-muted">
<div class="text-center">
<button type="submit" value="Submit" class="btn btn-dark Login">Register</button>
</div>
</div>
</div>
</form>
<!-- <div>
<label>Email: </label>
<input type="text">
<label>Password: </label>
......@@ -22,18 +39,14 @@
<input type="text">
<label>Account number: </label>
<input type="text">
<label>NIK: </label>
<input type="text">
<label>Date of birth: </label>
<input type="date">
<label for="gender">Gender:</label>
<select name="gender">
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<button type="submit">Register</button>
<button type="submit">Register</button> -->
</body>
</html>
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.db import connection
from multiprocessing import context
from .forms import *
def homepage(request):
return render(request, 'homepage.html')
......@@ -15,8 +18,62 @@ def register(request):
def register_admin(request):
return render(request, 'register_admin.html')
def insert_user_registration(email, password, phonenum, fname, name):
return """
INSERT INTO SIREST.USER_ACC(email, password, phonenum, fname, name)
VALUES ('{}', '{}', '{}', '{}', '{}')
""".format(email, password, phonenum, fname, name)
def insert_customer_registration(email, birthdate, sex):
return """
INSERT INTO SIREST.CUSTOMER(email, birthdate, sex)
VALUES ('{}', '{}', '{}')
"""
def insert_transaction_actor_registration(email, nik, bankname, accountno, restopay):
return """
INSERT INTO SIREST.TRANSACTION_ACTOR(email, nik, bankname, accountno, restopay)
VALUES ('{}', '{}', '{}', '{}', '{}')
"""
def register_customer(request):
return render(request, 'register_customer.html')
try:
form = customer_form(request.POST or None)
if request.method == "POST" and form.is_valid():
cursor = connection.cursor()
cursor.execute(insert_user_registration(request.POST['email'], request.POST['password'], request.POST['phonenum'], request.POST['fname'], request.POST['name']))
cursor.execute(insert_transaction_actor_registration(request.POST['email'], request.POST['nik'], request.POST['bankname'], request.POST['accountno'], request.POST['restopay']))
cursor.execute(insert_customer_registration(request.POST['email'], request.POST['birthdate'], request.POST['sex']))
if connection:
connection.commit()
cursor.close()
connection.close()
request.session['email'] = request.POST['email']
request.session['password'] = request.POST['password']
request.session['phonenum'] = request.POST['phonenum']
request.session['fname'] = request.POST['fname']
request.session['name'] = request.POST['name']
request.session['nik'] = request.POST['nik']
request.session['bankname'] = request.POST['bankname']
request.session['accountno'] = request.POST['accountno']
request.session['restopay'] = request.POST['restopay']
request.session['birthdate'] = request.POST['birthdate']
request.session['sex'] = request.POST['sex']
request.session['role'] = "Customer"
return redirect("/home")
context = {'form' : form, 'fail_message' : ""}
return render(request, 'sirest/register_customer.html', context)
except Exception as e:
return redirect('/')
def register_restaurant(request):
return render(request, 'register_restaurant.html')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment