Skip to content

Commit fe5db6d

Browse files
committed
added admin sign up functionality
1 parent bc8556c commit fe5db6d

File tree

8 files changed

+761
-17
lines changed

8 files changed

+761
-17
lines changed

controllers/AuthController.php

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use app\core\Controller;
77
use app\core\Request;
88
use app\core\Response;
9+
use app\models\Admin;
910
use app\models\Customer;
1011
use app\models\CustomerLoginForm;
1112

@@ -163,4 +164,26 @@ public function serviceCenterLogout(Request $request, Response $response)
163164
$response->redirect('/service-centre-landing');
164165
}
165166

167+
/* admin sign up method */
168+
public function adminSignUp(Request $request)
169+
{
170+
$admin = new Admin();
171+
if ($request->isPost()) {
172+
173+
$admin->loadData($request->getBody());
174+
if ($admin->validate() && $admin->save()) {
175+
Application::$app->session->setFlash('success', 'You have been registered successfully!');
176+
Application::$app->response->redirect('/admin-login');
177+
}
178+
$this->setLayout('auth');
179+
return $this->render('/admin/admin-sign-up', [
180+
'model' => $admin
181+
]);
182+
}
183+
$this->setLayout('auth');
184+
return $this->render('/admin/admin-sign-up', [
185+
'model' => $admin
186+
]);
187+
}
188+
166189
}

models/Admin.php

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
use app\core\Application;
6+
use app\core\DbModel;
7+
8+
class Admin extends DbModel
9+
{
10+
11+
public string $fname = '';
12+
public string $lname = '';
13+
public string $email = '';
14+
public string $phone_no = '';
15+
public string $address = '';
16+
public string $password = '';
17+
public string $confirmPassword = '';
18+
19+
public function tableName(): string
20+
{
21+
return 'admin';
22+
}
23+
24+
public function primaryKey(): string
25+
{
26+
return 'admin_id';
27+
}
28+
29+
public function save()
30+
{
31+
$this->password = password_hash($this->password, PASSWORD_DEFAULT);
32+
return parent::save();
33+
}
34+
35+
public function updateAdmin()
36+
{
37+
$sql = "UPDATE admin SET fname = :fname, lname = :lname, phone_no = :phone_no, address = :address WHERE admin_id = :admin_id";
38+
$stmt = self::prepare($sql);
39+
$stmt->bindValue(':fname', $this->fname);
40+
$stmt->bindValue(':lname', $this->lname);
41+
$stmt->bindValue(':phone_no', $this->phone_no);
42+
$stmt->bindValue(':address', $this->address);
43+
$stmt->bindValue(':admin_id', Application::$app->admin->{'admin_id'});
44+
return $stmt->execute();
45+
}
46+
47+
public function rules(): array
48+
{
49+
return [
50+
'fname' => [self::RULE_REQUIRED],
51+
'lname' => [self::RULE_REQUIRED],
52+
'email' => [self::RULE_REQUIRED, self::RULE_EMAIL, [
53+
self::RULE_UNIQUE,
54+
'class' => self::class
55+
]],
56+
'phone_no' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 10]],
57+
'address' => [self::RULE_REQUIRED],
58+
'password' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 8]],
59+
'confirmPassword' => [self::RULE_REQUIRED, [self::RULE_MATCH, 'match' => 'password']],
60+
];
61+
}
62+
63+
public function updateRules(): array
64+
{
65+
return [
66+
'fname' => [self::RULE_REQUIRED],
67+
'lname' => [self::RULE_REQUIRED],
68+
'phone_no' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 10]],
69+
'address' => [self::RULE_REQUIRED],
70+
];
71+
}
72+
73+
public function attributes(): array
74+
{
75+
return [
76+
'fname',
77+
'lname',
78+
'email',
79+
'phone_no',
80+
'address',
81+
'password',
82+
];
83+
}
84+
}

public/css/admin/admin-sign-up.css

+241
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
.container {
2+
display: grid;
3+
grid-template-columns: 1fr 1fr;
4+
grid-gap: 0;
5+
min-height: 100vh;
6+
overflow: hidden;
7+
max-width: 100vw;
8+
}
9+
10+
.container .box-1 {
11+
background-color: #010336;
12+
}
13+
14+
.branding, .box-1 {
15+
flex: 1;
16+
padding: 2rem;
17+
}
18+
19+
.container .box-2 {
20+
display: flex;
21+
flex-direction: column;
22+
justify-content: center;
23+
align-items: center;
24+
background: #eef3f4;
25+
}
26+
27+
.container .box-2 .wrapper {
28+
background: #f9f9f9;
29+
border: 1px solid #e0e0e0;
30+
border-radius: .6rem;
31+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
32+
}
33+
34+
.branding {
35+
display: flex;
36+
padding: 1rem;
37+
background-color: transparent;
38+
flex-direction: column;
39+
justify-content: center;
40+
margin-top: 200px;
41+
42+
}
43+
44+
.brand-name {
45+
font-weight: bold;
46+
font-size: 2rem;
47+
margin-bottom: 1rem;
48+
color: #333;
49+
}
50+
51+
.brand-button {
52+
padding: 0.25rem 0.5rem;
53+
background: linear-gradient(to right, #183369, #1e8dc5);
54+
border-radius: 0.5rem;
55+
color: white;
56+
font-size: 5rem;
57+
display: inline-block;
58+
float: right;
59+
}
60+
61+
.tagline {
62+
margin-top: 10px;
63+
line-height: 1.5;
64+
color: white;
65+
text-align: right;
66+
}
67+
68+
.container .box-2 .wrapper .title-1 {
69+
margin-bottom: 2rem;
70+
}
71+
72+
.container .box-2 .wrapper .title-1 h2 {
73+
font-size: 1.5rem;
74+
font-weight: 500;
75+
margin-bottom: 0.3rem;
76+
}
77+
78+
.container .box-2 .wrapper .title-1 h5 {
79+
font-size: 0.9rem;
80+
font-weight: 300;
81+
color: #666;
82+
}
83+
84+
.container .box-2 .wrapper {
85+
padding: 2rem;
86+
}
87+
88+
.container .box-2 .wrapper .admin-signup-form {
89+
display: flex;
90+
flex-direction: column;
91+
}
92+
93+
.container .box-2 .wrapper .admin-signup-form > * {
94+
margin-bottom: 1rem;
95+
}
96+
97+
.container .box-2 .wrapper .admin-signup-form {
98+
font-size: 0.9rem;
99+
font-weight: 400;
100+
color: #747373;
101+
}
102+
103+
.container .box-2 .wrapper .admin-signup-form .input-element {
104+
display: flex;
105+
flex-direction: column;
106+
margin-bottom: 1rem;
107+
}
108+
109+
.container .box-2 .wrapper .admin-signup-form .input-element label {
110+
margin-bottom: .4rem;
111+
}
112+
113+
.container .box-2 .wrapper .admin-signup-form .input-element input {
114+
padding: 0.8rem 0.6rem;
115+
border-radius: .6rem;
116+
border: 1px solid #e0e0e0;
117+
color: #747373;
118+
}
119+
120+
.container .box-2 .wrapper .admin-signup-form .input-element input:focus {
121+
border-color: #5db8f5ed;
122+
outline: none;
123+
}
124+
125+
.container .box-2 .wrapper .admin-signup-form .input-element:focus-within label {
126+
color: #5db8f5f0;
127+
}
128+
129+
.container .box-2 .wrapper .admin-signup-form .input-element:nth-child(3) h6 {
130+
margin-top: 0.2rem;
131+
font-size: 0.7rem;
132+
color: #949393;
133+
}
134+
135+
.container .box-2 .wrapper .admin-signup-form .terms-cond {
136+
font-size: 0.8rem;
137+
}
138+
139+
.container .box-2 .wrapper .admin-signup-form .not-robot {
140+
border: 1px solid #e0e0e0;
141+
padding: 1rem 0.6rem;
142+
border-radius: 0.6rem;
143+
font-size: 0.8rem;
144+
background-color: #eff3f4;
145+
}
146+
147+
.container .box-2 .wrapper .admin-signup-form input[type="checkbox"] {
148+
accent-color: #5db8f5;
149+
}
150+
151+
.container .box-2 .wrapper .admin-signup-form .btn {
152+
padding: 0.8rem 1.2rem;
153+
border-radius: 2rem;
154+
background: #5db8f5;
155+
color: #fff;
156+
font-size: 0.9rem;
157+
font-weight: 500;
158+
cursor: pointer;
159+
border: none;
160+
transition: background 0.3s;
161+
}
162+
163+
.admin-signup-form .log-in a {
164+
text-align: center;
165+
font-size: 0.8rem;
166+
color: #5db8f5;
167+
text-decoration: none;
168+
margin-top: 1rem;
169+
}
170+
171+
172+
@media screen and (max-width: 768px) {
173+
.container {
174+
grid-template-columns: 1fr;
175+
}
176+
177+
.container .box-2 {
178+
padding: 2rem;
179+
}
180+
181+
.container .box-2 .wrapper {
182+
padding: 1.5rem;
183+
}
184+
185+
.container .box-2 .wrapper .title-1 h2 {
186+
font-size: 1.3rem;
187+
}
188+
189+
.container .box-2 .wrapper .title-1 h5 {
190+
font-size: 0.8rem;
191+
}
192+
193+
.container .box-2 .wrapper .admin-signup-form {
194+
font-size: 0.8rem;
195+
}
196+
197+
.container .box-2 .wrapper .admin-signup-form .input-element input {
198+
padding: 0.7rem 0.5rem;
199+
}
200+
201+
.container .box-2 .wrapper .admin-signup-form .input-element:nth-child(3) h6 {
202+
font-size: 0.6rem;
203+
}
204+
205+
.container .box-2 .wrapper .admin-signup-form .terms-cond {
206+
font-size: 0.7rem;
207+
}
208+
209+
.container .box-2 .wrapper .admin-signup-form .not-robot {
210+
padding: 0.8rem 0.5rem;
211+
font-size: 0.7rem;
212+
}
213+
214+
.container .box-2 .wrapper .admin-signup-form .btn {
215+
padding: 0.7rem 1.1rem;
216+
font-size: 0.8rem;
217+
}
218+
}
219+
220+
/* Highlight invalid input fields */
221+
.container .box-2 .wrapper .admin-signup-form .input-element .invalid {
222+
border-color: #dc3545; /* Red border for error */
223+
background-color: #f8d7da; /* Light red background for error */
224+
}
225+
226+
.container .box-2 .wrapper .admin-signup-form .input-element .invalid {
227+
color: #dc3545; /* Red color for label to indicate error */
228+
}
229+
230+
/* Error feedback message */
231+
.container .box-2 .wrapper .admin-signup-form .input-element .invalid-feedback {
232+
color: #dc3545;
233+
font-size: 0.8rem;
234+
margin-top: 0.4rem;
235+
/*display: none; /* Hide by default, show only when invalid */
236+
}
237+
238+
/* Display error feedback when invalid */
239+
.container .box-2 .wrapper .admin-signup-form .input-element.invalid .invalid-feedback {
240+
display: block;
241+
}

0 commit comments

Comments
 (0)