-
Notifications
You must be signed in to change notification settings - Fork 1
/
register.php
204 lines (191 loc) · 9.52 KB
/
register.php
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
require_once 'includes/functions.php';
require_once 'includes/Connection.php';
require_once('constants/TenantStatus.php');
$connection = ConnectionHelper::getConnection();
if (checkAuth()) {
header("Location: /");
return;
}
function checkUsername($username)
{
$connection = ConnectionHelper::getConnection();
$checkUsername = "select * from user where Username = :username";
$statement = $connection->prepare($checkUsername);
$statement->bindParam('username', $username);
$statement->execute();
$result = $statement->rowCount();
if ($result > 0) {
return true;
}
return false;
}
if (isPost()) {
$connection->beginTransaction();
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$username = $_POST['username'];
$password = $_POST['password'];
$businessName = $_POST['businessName'];
$businessEmail = $_POST['businessEmail'];
$businessPhone = $_POST['businessPhone'];
$businessAddress = $_POST['businessAddress'];
$commandForTenant = "insert into tenants (Name, Email, Phone, Address, Status, CreatedAt) values (:businessName, :businessEmail, :businessPhone, :businessAddress, :businessStatus, :createdAt)";
$statement = $connection->prepare($commandForTenant);
$statement->bindParam('businessName', $businessName);
$statement->bindParam('businessEmail', $businessEmail);
$statement->bindParam('businessPhone', $businessPhone);
$statement->bindParam('businessAddress', $businessAddress);
$statement->bindParam('createdAt', date('Y-m-d H:i:s'));
$statement->bindParam('businessStatus', TenantStatus::$Pending);
$statement->execute();
$tenantId = $connection->lastInsertId();
if ($tenantId > 0) {
if (checkUsername($username)) {
$connection->rollBack();
addErrorMessage("Username already exists");
header("Location: /register.php");
return;
}
$commandForUser = "insert into user (FirstName, LastName, Email, Phone, Address, Username, PasswordHash, TenantId, CreatedAt, Role) values (:firstName, :lastName, :email, :phone, :address, :username, :passwordHash, :tenantId, :createdAt, :role)";
$role = 'Admin';
$statement = $connection->prepare($commandForUser);
$statement->bindParam('firstName', $firstName);
$statement->bindParam('lastName', $lastName);
$statement->bindParam('email', $email);
$statement->bindParam('phone', $phone);
$statement->bindParam('address', $address);
$statement->bindParam('username', $username);
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
$statement->bindParam('passwordHash', $passwordHash);
$statement->bindParam('tenantId', $tenantId);
$statement->bindParam('createdAt', date('Y-m-d H:i:s'));
$statement->bindParam('role', $role);
$statement->execute();
$result = $statement->rowCount();
if ($result > 0) {
//inserting type PurchaseBill and Number into auto_generated_number table
$commandForAutoGeneratedNumber = "insert into auto_generated_number (Type, Number, TenantId) values (:type, :number, :tenantId)";
$statement = $connection->prepare($commandForAutoGeneratedNumber);
$type = 'SalesBill';
$number = 0;
$statement->bindParam('type', $type);
$statement->bindParam('number', $number);
$statement->bindParam('tenantId', $tenantId);
$statement->execute();
$result = $statement->rowCount();
if ($result > 0) {
$connection->commit();
addSuccessMessage("Registration Successful! Login Now");
header("Location: /");
} else {
$connection->rollBack();
addErrorMessage("Registration Failed! Please try again");
header("Location: /register.php");
}
}
}
}
require_once 'includes/header.php';
?>
<!-- ======= Services Section ======= -->
<section id="services" class="services section-bg">
<div class="container" data-aos="fade-up">
<div class="section-title">
<h2>Register On Digital Kirana</h2>
<p>Simplify Inventory Management with Digital Kirana</p>
</div>
<div class="icon-box text-center">
<?php renderMessages(); ?>
<form action="" method="post">
<div class="row">
<div class="col-12 mb-3">
<h3 class="text-start text-uppercase">Personal Details</h3>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="text" id="firstName" name="firstName" class="form-control" placeholder="Enter First Name (*)" required>
<label for="firstName">First Name (*)</label>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="text" id="lastName" name="lastName" class="form-control" placeholder="Enter First Name (*)" required>
<label for="lastName">Last Name (*)</label>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="email" id="email" name="email" class="form-control" placeholder="Enter Email (*)" required>
<label for="email">Email (*)</label>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="tel" id="phone" name="phone" class="form-control" placeholder="Enter Phone (*)" required>
<label for="phone">Phone (*)</label>
</div>
</div>
<div class="col-sm-12 col-md-12">
<div class="form-floating mb-3">
<textarea id="address" name="address" class="form-control" placeholder="Enter Address (*)" required style="height: 100px;"></textarea>
<label for="phone">Address (*)</label>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="text" id="username" name="username" class="form-control" placeholder="Enter Username (*)" required>
<label for="username">Username (*)</label>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="password" id="password" name="password" class="form-control" placeholder="Enter Password (*)" required>
<label for="password">Password (*)</label>
</div>
</div>
<div class="col-12 my-3">
<h3 class="text-start text-uppercase">Business Details</h3>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="text" id="businessName" name="businessName" class="form-control" placeholder="Enter Business Name (*)" required>
<label for="businessName">Business Name (*)</label>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="email" id="businessEmail" name="businessEmail" class="form-control" placeholder="Enter Business Email (*)" required>
<label for="businessEmail">Business Email (*)</label>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="tel" id="businessPhone" name="businessPhone" class="form-control" placeholder="Enter Business Phone (*)" required>
<label for="businessPhone">Business Phone (*)</label>
</div>
</div>
<div class="col-sm-12 col-md-6">
<div class="form-floating mb-3">
<input type="tel" id="businessAddress" name="businessAddress" class="form-control" placeholder="Enter Business Address (*)" required>
<label for="businessAddress">Business Address (*)</label>
</div>
</div>
<div class="col-12 mb-3">
<button class="btn btn-primary w-100">Register</button>
</div>
<div class="col-12">
<p class="text-center"><span>Already have an account? </span> <a href="/">Login</a>
</p>
</div>
</div>
</form>
</div>
</div>
</section><!-- End Services Section -->
<?php
require_once 'includes/footer.php';
?>