Skip to content

Commit fb5bf12

Browse files
committed
Configured the register functionality to enable registering of new users
1 parent 01cd690 commit fb5bf12

File tree

10 files changed

+172
-95
lines changed

10 files changed

+172
-95
lines changed
0 Bytes
Binary file not shown.

AuthenticationProject/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
urlpatterns = [
2121
path('admin/', admin.site.urls),
2222
path('', include('core.urls'))
23-
]
23+
]
1.62 KB
Binary file not shown.

core/views.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,40 @@ def Home(request):
1414
return render(request, 'index.html')
1515

1616
def RegisterView(request):
17+
18+
if request.method == "POST":
19+
first_name = request.POST.get('first_name')
20+
last_name = request.POST.get('last_name')
21+
last_name = request.POST.get('last_name')
22+
username = request.POST.get('username')
23+
email = request.POST.get('email')
24+
password = request.POST.get('password')
25+
26+
user_data_has_error = False
27+
28+
if User.objects.filter(username=username).exists():
29+
user_data_has_error = True
30+
messages.error(request, 'Username already exists')
31+
32+
if User.objects.filter(email=email).exists():
33+
user_data_has_error = True
34+
messages.error(request, 'Email already exists')
35+
36+
if len(password) < 5:
37+
user_data_has_error = True
38+
messages.error(request, 'Password must be at least 5 characters')
39+
40+
if not user_data_has_error:
41+
new_user = User.objects.create_user(
42+
first_name = first_name,
43+
last_name = last_name,
44+
email = email,
45+
username = username,
46+
password = password
47+
)
48+
messages.success(request, 'Account created. Login now')
49+
return redirect('login')
50+
return redirect('register')
1751
return render(request, 'register.html')
1852

1953
def LoginView(request):

db.sqlite3

0 Bytes
Binary file not shown.

static/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
body{
1010
margin: 0;
1111
padding: 0;
12-
background: linear-gradient(120deg,#2980b9, #8e44ad);
12+
background: linear-gradient(120deg,hsla(238, 100%, 50%, 0.6), hsla(125, 100%, 50%, 0.6));
1313
height: 100vh;
1414
overflow: hidden;
1515
}

templates/forgot_password.html

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
<!DOCTYPE html>
22
<html lang="en" dir="ltr">
3-
<head>
4-
<meta charset="utf-8">
5-
<title>Forgot Password</title>
6-
<link rel="stylesheet" href="style.css">
7-
</head>
8-
<body>
9-
<div class="center">
10-
<h1>Reset Password</h1>
11-
12-
<div class="signup_link">Enter your email to reset password</div>
13-
14-
<form method="POST">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Forgot Password</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
9+
<div class="center">
10+
<h1>Reset Password</h1>
1511

16-
<div class="txt_field">
17-
<input type="email" required>
18-
<span></span>
19-
<label>Email</label>
20-
</div>
12+
{% if messages %}
13+
{% for message in messages %}
14+
{% if message.tags == 'error' %}
15+
<center><h4 style="color: firebrick;">{{message}}</h4></center>
16+
{% else %}
17+
<center><h4 style="color: dodgerblue;">{{message}}</h4></center>
18+
{% endif %}
19+
{% endfor %}
20+
{% endif %}
21+
22+
<div class="signup_link">Enter your email to reset password</div>
2123

22-
<input type="submit" value="Reset Password">
23-
<div class="signup_link">
24-
Not a member? <a href="register.html">Signup</a>
25-
<p>Remember your Password? <a href="#">Login</a></p>
24+
<form method="POST">
25+
26+
<div class="txt_field">
27+
<input type="email" required>
28+
<span></span>
29+
<label>Email</label>
30+
</div>
31+
32+
<input type="submit" value="Reset Password">
33+
<div class="signup_link">
34+
Not a member? <a href="register.html">Signup</a>
35+
<p>Remember your Password? <a href="#">Login</a></p>
36+
</div>
37+
</form>
2638
</div>
27-
</form>
28-
</div>
2939

30-
</body>
40+
</body>
3141
</html>

templates/login.html

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
11
<!DOCTYPE html>
22
<html lang="en" dir="ltr">
3-
<head>
4-
<meta charset="utf-8">
5-
<title>Login</title>
6-
<link rel="stylesheet" href="style.css">
7-
</head>
8-
<body>
9-
<div class="center">
10-
<h1>Login</h1>
11-
12-
<form method="POST">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Login</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
9+
<div class="center">
10+
<h1>Login</h1>
1311

14-
<div class="txt_field">
15-
<input type="text" required>
16-
<span></span>
17-
<label>Username</label>
18-
</div>
12+
{% if messages %}
13+
{% for message in messages %}
14+
{% if message.tags == 'error' %}
15+
<center><h4 style="color: firebrick;">{{message}}</h4></center>
16+
{% else %}
17+
<center><h4 style="color: dodgerblue;">{{message}}</h4></center>
18+
{% endif %}
19+
{% endfor %}
20+
{% endif %}
21+
22+
<form method="POST">
1923

20-
<div class="txt_field">
21-
<input type="password" required>
22-
<span></span>
23-
<label>Password</label>
24-
</div>
24+
<div class="txt_field">
25+
<input type="text" required>
26+
<span></span>
27+
<label>Username</label>
28+
</div>
29+
30+
<div class="txt_field">
31+
<input type="password" required>
32+
<span></span>
33+
<label>Password</label>
34+
</div>
2535

26-
<input type="submit" value="Login">
27-
<div class="signup_link">
28-
Not a member? <a href="register.html">Signup</a>
29-
<p>Forgot your Password? <a href="#">Reset Password</a></p>
36+
<input type="submit" value="Login">
37+
<div class="signup_link">
38+
Not a member? <a href="register.html">Signup</a>
39+
<p>Forgot your Password? <a href="#">Reset Password</a></p>
40+
</div>
41+
</form>
3042
</div>
31-
</form>
32-
</div>
3343

34-
</body>
44+
</body>
3545
</html>

templates/register.html

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,67 @@
11
<!DOCTYPE html>
22
<!-- Coding By CodingNepal - youtube.com/codingnepal -->
33
<html lang="en" dir="ltr">
4-
<head>
5-
<meta charset="utf-8">
6-
<title>Register</title>
7-
<link rel="stylesheet" href="style.css">
8-
</head>
9-
<body>
10-
<div class="center">
11-
<h1>Register</h1>
4+
<head>
5+
{% load static %}
6+
<meta charset="utf-8">
7+
<title>Register</title>
8+
<link rel="stylesheet" href="{% static 'style.css' %}">
9+
</head>
10+
<body>
11+
<div class="center">
12+
<h1>Register</h1>
13+
14+
{% if messages %}
15+
{% for message in messages %}
16+
{% if message.tags == 'error' %}
17+
<center><h4 style="color: firebrick;">{{message}}</h4></center>
18+
{% else %}
19+
<center><h4 style="color: dodgerblue;">{{message}}</h4></center>
20+
{% endif %}
21+
{% endfor %}
22+
{% endif %}
1223

13-
<form method="POST">
14-
15-
<div class="txt_field">
16-
<input type="text" required>
17-
<span></span>
18-
<label>First Name</label>
19-
</div>
24+
<form method="POST">
25+
26+
{% csrf_token %}
27+
28+
<div class="txt_field">
29+
<input type="text" name="first_name" required>
30+
<span></span>
31+
<label>First Name</label>
32+
</div>
2033

21-
<div class="txt_field">
22-
<input type="text" required>
34+
<div class="txt_field">
35+
<input type="text" name="last_name" required>
36+
<span></span>
37+
<label>Last Name</label>
38+
</div>
39+
40+
<div class="txt_field">
41+
<input type="text" name="username" required>
2342
<span></span>
24-
<label>Last Name</label>
25-
</div>
43+
<label>Username</label>
44+
</div>
2645

27-
<div class="txt_field">
28-
<input type="text" required>
29-
<span></span>
30-
<label>Username</label>
31-
</div>
46+
<div class="txt_field">
47+
<input type="email" name="email" required>
48+
<span></span>
49+
<label>Email</label>
50+
</div>
3251

33-
<div class="txt_field">
34-
<input type="email" required>
52+
<div class="txt_field">
53+
<input type="password" name="password" required>
3554
<span></span>
36-
<label>Email</label>
37-
</div>
38-
39-
<div class="txt_field">
40-
<input type="password" required>
41-
<span></span>
42-
<label>Password</label>
43-
</div>
44-
45-
<!-- <div class="pass">Forgot Password?</div> -->
46-
<input type="submit" value="Register">
47-
<div class="signup_link">
48-
Already have an account? <a href="login.html">Login</a>
55+
<label>Password</label>
56+
</div>
57+
58+
<!-- <div class="pass">Forgot Password?</div> -->
59+
<input type="submit" value="Register">
60+
<div class="signup_link">
61+
Already have an account? <a href="login.html">Login</a>
62+
</div>
63+
</form>
4964
</div>
50-
</form>
51-
</div>
5265

53-
</body>
66+
</body>
5467
</html>

templates/reset_password.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
<body>
1010
<div class="center">
1111
<h1>Reset Password</h1>
12+
13+
{% if messages %}
14+
{% for message in messages %}
15+
{% if message.tags == 'error' %}
16+
<center><h4 style="color: firebrick;">{{message}}</h4></center>
17+
{% else %}
18+
<center><h4 style="color: dodgerblue;">{{message}}</h4></center>
19+
{% endif %}
20+
{% endfor %}
21+
{% endif %}
1222

1323
<form method="POST">
1424

0 commit comments

Comments
 (0)