Skip to content

Commit e3c7887

Browse files
committed
Feature Update.
Added social authentication feature. Updated readme file & requirments.txt file. Automation of Social Profile creation. Update in the UI.
1 parent 3544d89 commit e3c7887

23 files changed

+417
-243
lines changed
1015 Bytes
Binary file not shown.
106 Bytes
Binary file not shown.

Base_Master/settings.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
# External pacakages
4444
'crispy_forms',
4545
'import_export',
46+
'social_django',
4647
'django_cleanup.apps.CleanupConfig',
4748
]
4849
IMPORT_EXPORT_USE_TRANSACTIONS = True #Mandatory for Transactions perfomred with import_export package
@@ -153,6 +154,7 @@
153154
EMAIL_HOST_USER = 'Email Id' #You should type your Email address
154155
EMAIL_HOST_PASSWORD = 'password' #You should type your Email password
155156
EMAIL_USE_TLS = True
157+
DEFAULT_FROM_EMAIL = 'noreply<no_reply@company.com>'
156158

157159
LOGIN_REDIRECT_URL = 'home' #this Url is used to redirect Users after login
158160
LOGOUT_REDIRECT_URL = 'login' #this Url is used to redirect Users after logout
@@ -239,4 +241,38 @@
239241
"changeform_format": "horizontal_tabs",
240242
# override change forms on a per modeladmin basis
241243
"changeform_format_overrides": {"auth.user": "collapsible", "auth.group": "vertical_tabs"},
242-
}
244+
}
245+
246+
## Social Authentication Configuration
247+
AUTHENTICATION_BACKENDS = (
248+
'social_core.backends.google.GoogleOAuth2', ## Google Authentication
249+
'social_core.backends.github.GithubOAuth2', ## Github Authentication
250+
'django.contrib.auth.backends.ModelBackend', ## Normal Username & Password Authentication
251+
)
252+
253+
## Google Authentication Keys
254+
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'xxxxxxxxxxxxxxxxxxxxx'
255+
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'xxxxxxxxxxxxxxxxl'
256+
257+
## Github Authetication Keys
258+
SOCIAL_AUTH_GITHUB_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
259+
SOCIAL_AUTH_GITHUB_SECRET = 'xxxxxxxxxxxxxxxxxxxxx'
260+
SOCIAL_AUTH_GITHUB_SCOPE = ['user:email','user.user','user:profile_name']
261+
262+
## Social Authentication Features.
263+
## Remove from pipeline, if you want to remove any feature.
264+
265+
## Example: If you dont want user to be created automatically, if the user is not there in database.
266+
## Remove 'social_core.pipeline.user.create_user', from the pipeline. Then it wont create users if user not exist.
267+
268+
SOCIAL_AUTH_PIPELINE = (
269+
'social_core.pipeline.social_auth.social_details',
270+
'social_core.pipeline.social_auth.social_uid',
271+
'social_core.pipeline.social_auth.social_user',
272+
'social_core.pipeline.user.get_username',
273+
'social_core.pipeline.social_auth.associate_by_email',
274+
'social_core.pipeline.user.create_user',
275+
'social_core.pipeline.social_auth.associate_user',
276+
'social_core.pipeline.social_auth.load_extra_data',
277+
'social_core.pipeline.user.user_details',
278+
)

Base_Master/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
path('update/', views.profile_update, name="update"),
1515
path('disable/<str:id>/', views.disable_user, name="disable_user"),
1616
path('theme', views.theme, name="theme"),
17+
path('social-auth/', include('social_django.urls', namespace='social')),
1718
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

README.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,32 @@ Follow these steps to make the project run locally:
6464
```sh
6565
python manage.py createsuperuser
6666
```
67-
7. Run the server locally on your system.
67+
7. Configurations on <b>settings.py</b> file
68+
69+
<b>Step 1:</b> Go to your Gmail and create an App.<br>
70+
[Click Here ](https://github.com/tamaraiselvan/Base-django-project-Setup/wiki/Email-Configuration.) to Refer the Documentation for the configuration.<br><br>
71+
<b>Step 2:</b> Go to Google could platform. Create an OAuth app.<br>
72+
[Click Here ](https://github.com/tamaraiselvan/Base-django-project-Setup/wiki/Google-Oauth-Configuration.) to Refer the Documentation for the configuration.
73+
<br><br>
74+
<b>Step 3:</b> Go to Github. Create an OAuth app.<br>
75+
[Click Here ](https://github.com/tamaraiselvan/Base-django-project-Setup/wiki/GitHub-OAuth-Configuration.) to Refer the Documentation for the configuration.
76+
77+
8. Run the server locally on your system.
6878
```sh
6979
python manage.py runserver
7080
```
71-
8. Open your browser and type.
81+
9. Open your browser and type.
7282
```sh
73-
http://127.0.0.1:8000/
83+
http://localhost:8000/
7484
```
85+
Note: Only on the localhost Social Authentication will work.
7586

87+
## Sponsor to TS Tamarai Selvan
88+
[![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/tamaraiselvan)
89+
7690
## License
7791

7892
Licensed under the MIT License.
7993
Copyright © 2022 TS Tamarai Selvan [Copy of the license](LICENSE).
94+
95+

db.sqlite3

68 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
753 Bytes
Binary file not shown.
2 Bytes
Binary file not shown.

firstapp/signals.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@
22
from django.contrib.auth.models import User
33
from django.dispatch import receiver
44
from .models import Profile
5+
from social_django.models import UserSocialAuth
56

67
### This signal used to create the Profile once the users gets added into the User table
78
@receiver(post_save, sender=User)
89
def create_profile(sender, instance, created, **kwargs):
910
if created:
1011
Profile.objects.create(user=instance)
1112

13+
### This signal used to create the Social Profile once the users gets added into the User table
14+
@receiver(post_save, sender=User)
15+
def create_google_auth(sender, instance, created, **kwargs):
16+
if created:
17+
UserSocialAuth.objects.create(user=instance, provider=' google-oauth2', uid=instance.email)
18+
1219
### The profile created will be saved to the database.
1320
@receiver(post_save, sender=User)
1421
def save_profile(sender, instance, **kwargs):
15-
instance.profile.save()
22+
instance.profile.save()
23+
24+
### The Social profile created will be saved to the database.
25+
@receiver(post_save, sender=create_google_auth)
26+
def save_google_auth(sender, instance, **kwargs):
27+
instance.UserSocialAuth.save()

requirements.txt

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
asgiref==3.5.2
2+
certifi==2022.12.7
23
cffi==1.15.1
4+
charset-normalizer==3.1.0
35
cryptography==39.0.0
46
defusedxml==0.7.1
57
diff-match-patch==20200713
@@ -9,14 +11,23 @@ django-crispy-forms==1.14.0
911
django-import-export==3.1.0
1012
django-jazzmin==2.5.0
1113
et-xmlfile==1.1.0
14+
idna==3.4
1215
MarkupPy==1.14
16+
oauthlib==3.2.2
1317
odfpy==1.4.1
1418
openpyxl==3.1.1
1519
Pillow==9.4.0
1620
pycparser==2.21
21+
PyJWT==2.6.0
22+
python3-openid==3.2.0
1723
PyYAML==6.0
24+
requests==2.28.2
25+
requests-oauthlib==1.3.1
26+
social-auth-app-django==5.1.0
27+
social-auth-core==4.4.0
1828
sqlparse==0.4.2
1929
tablib==3.3.0
2030
tzdata==2022.1
31+
urllib3==1.26.15
2132
xlrd==2.0.1
2233
xlwt==1.3.0

templates/registration/login.html

+81-89
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,91 @@
1+
{% extends 'registration/registerbase.html' %}
12
{% load static %}
2-
<html lang="en">
3+
{% block pagetitle %}Login{% endblock %}
34

4-
<head>
5-
<meta charset="UTF-8">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8-
<title>
9-
{% if user.is_authenticated %}
10-
You have already logged in
11-
{% else %}
12-
Company Name
13-
{% endif %}
14-
</title>
15-
<link href="https://fonts.googleapis.com/css?family=Karla:400,700&amp;display=swap" rel="stylesheet">
16-
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/4.8.95/css/materialdesignicons.min.css">
17-
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
18-
<link rel="stylesheet" href="{% static 'login_styling/loginstyle.css' %}">
19-
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
20-
<link rel="shortcut icon" href="{% static 'login_styling/favicon.svg' %}" type="image/x-icon">
21-
<!--Provide your company logo-->
22-
</head>
23-
24-
<body style="overflow-y: hidden;">
25-
<main>
26-
{% if user.is_authenticated %}
27-
<div class="container">
28-
<div class="d-flex align-items-center justify-content-center align-self-center">
29-
<div class="card">
30-
<div class="card-header">
31-
Featured
32-
</div>
33-
<div class="card-body">
34-
<h5 class="card-title">Already Logged In</h5>
35-
<p class="card-text">You have already logged In.</p>
36-
<a href="#" class="btn btn-primary">Go to Dashboard</a>
37-
</div>
38-
</div>
5+
{% block content %}
6+
{% if user.is_authenticated %}
7+
<div class="container">
8+
<div class="d-flex align-items-center justify-content-center align-self-center">
9+
<div class="card">
10+
<div class="card-header">
11+
Featured
12+
</div>
13+
<div class="card-body">
14+
<h5 class="card-title">Already Logged In</h5>
15+
<p class="card-text">You have already logged In.</p>
16+
<a href="#" class="btn btn-primary">Go to Dashboard</a>
3917
</div>
4018
</div>
41-
<script>
42-
setTimeout("location.href = '{% url 'home' %}';", 0);
43-
</script>
44-
{% else %}
45-
<div class="container-fluid">
46-
<div class="row">
47-
<div class="col-sm-6 login-section-wrapper">
48-
<div class="brand-wrapper">
49-
<img src="https://www.bootstrapdash.com/demo/login-template-free-1/assets/images/logo.svg" alt="logo" class="logo">
19+
</div>
20+
</div>
21+
<script>
22+
setTimeout("location.href = '{% url 'home' %}';", 0);
23+
</script>
24+
{% else %}
25+
<div class="container-fluid">
26+
<div class="row">
27+
<div class="col-sm-6 login-section-wrapper">
28+
<div class="brand-wrapper">
29+
<img src="https://www.bootstrapdash.com/demo/login-template-free-1/assets/images/logo.svg" alt="logo" class="logo">
30+
</div>
31+
<div class="">
32+
<h1 class="login-title">Log in</h1>
33+
{% if form.errors %}
34+
<div class="alert alert-danger alert-dismissable fade show" role="alert">
35+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
36+
<span aria-hidden="true">&times;</span>
37+
</button>
38+
<p>Invalid Credentials. Retry again.</p>
39+
</div>
40+
{% endif %}
41+
{% if messages %}
42+
{% for message in messages %}
43+
<div class="alert {% if message.tags %} {{ message.tags }} {% endif %} alert-dismissable fade show" role="alert">
44+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
45+
<span aria-hidden="true">&times;</span>
46+
</button>
47+
<p>{{message}}</p>
48+
</div>
49+
{% endfor %}
50+
{% endif %}
51+
<form action="{% url 'login' %}" method="POST">
52+
{% csrf_token %}
53+
<div class="form-group">
54+
<label for="username">Username:</label>
55+
<input type="username" name="username" id="username" class="form-control" placeholder="Enter your Username">
56+
</div>
57+
<div class="form-group mb-4">
58+
<label for="password">Password:</label>
59+
<input type="password" name="password" id="password" class="form-control" placeholder="Enter your passsword">
5060
</div>
51-
<div class="">
52-
<h1 class="login-title">Log in</h1>
53-
{% if form.errors %}
54-
<div class="alert alert-danger alert-dismissable fade show" role="alert">
55-
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
56-
<span aria-hidden="true">&times;</span>
57-
</button>
58-
<p>Invalid Credentials. Retry again.</p>
61+
<button class="btn btn-outline-primary btn-block btn-lg" type="submit" name="Login" id="Login">Log In</button>
62+
<div class="row pt-3">
63+
<div class="col-sm-6 mb-3 mb-sm-0">
64+
<a href="{% url 'social:begin' 'google-oauth2' %}" class="btn btn-outline-primary btn-block">
65+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-google" viewBox="0 0 16 16">
66+
<path d="M15.545 6.558a9.42 9.42 0 0 1 .139 1.626c0 2.434-.87 4.492-2.384 5.885h.002C11.978 15.292 10.158 16 8 16A8 8 0 1 1 8 0a7.689 7.689 0 0 1 5.352 2.082l-2.284 2.284A4.347 4.347 0 0 0 8 3.166c-2.087 0-3.86 1.408-4.492 3.304a4.792 4.792 0 0 0 0 3.063h.003c.635 1.893 2.405 3.301 4.492 3.301 1.078 0 2.004-.276 2.722-.764h-.003a3.702 3.702 0 0 0 1.599-2.431H8v-3.08h7.545z"/>
67+
</svg>
68+
Sign in With Google
69+
</a>
5970
</div>
60-
{% endif %}
61-
{% if messages %}
62-
{% for message in messages %}
63-
<div class="alert {% if message.tags %} {{ message.tags }} {% endif %} alert-dismissable fade show" role="alert">
64-
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
65-
<span aria-hidden="true">&times;</span>
66-
</button>
67-
<p>{{message}}</p>
71+
<div class="col-sm-6 mb-3 mb-sm-0">
72+
<a href="{% url 'social:begin' 'github' %}" class="btn btn-outline-dark btn-block">
73+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-github" viewBox="0 0 16 16">
74+
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"/>
75+
</svg>
76+
Sign in with Github
77+
</a>
6878
</div>
69-
{% endfor %}
70-
{% endif %}
71-
<form action="{% url 'login' %}" method="POST">
72-
{% csrf_token %}
73-
<div class="form-group">
74-
<label for="username">Username:</label>
75-
<input type="username" name="username" id="username" class="form-control" placeholder="Enter your Username">
76-
</div>
77-
<div class="form-group mb-4">
78-
<label for="password">Password:</label>
79-
<input type="password" name="password" id="password" class="form-control" placeholder="Enter your passsword">
80-
</div>
81-
<button class="btn btn-outline-primary btn-block btn-lg" type="submit" name="Login" id="Login">Log In</button>
82-
</form>
83-
<a href="{% url 'password_reset' %}" class="forgot-password-link">Forgot password?</a>
84-
<p class="login-wrapper-footer-text">Don't have an account? <a href="{% url 'sign_up' %}" class="text-reset">Register here</a></p>
8579
</div>
86-
</div>
87-
<div class="col-sm-6 px-0 d-none d-sm-block">
88-
<img src="https://www.bootstrapdash.com/demo/login-template-free-1/assets/images/login.jpg" alt="login image" class="login-img">
89-
</div>
80+
</form>
81+
<a href="{% url 'password_reset' %}" class="forgot-password-link">Forgot password?</a>
82+
<p class="login-wrapper-footer-text">Don't have an account? <a href="{% url 'sign_up' %}" class="text-reset">Register here</a></p>
9083
</div>
9184
</div>
92-
{% endif %}
93-
</main>
94-
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
95-
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
96-
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
97-
</body>
98-
99-
</html>
85+
<div class="col-sm-6 px-0 d-none d-sm-block">
86+
<img src="https://www.bootstrapdash.com/demo/login-template-free-1/assets/images/login.jpg" alt="login image" class="login-img">
87+
</div>
88+
</div>
89+
</div>
90+
{% endif %}
91+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
11
{% extends 'registration/registerbase.html' %}
22

3-
{% block title %}Password changed successfully{% endblock %}
3+
{% block pagetitle %}Password changed successfully{% endblock %}
4+
{% load crispy_forms_tags %}
5+
<!DOCTYPE html>
6+
<html lang="en">
47

5-
{% block content %}
6-
<h2>Change password</h2>
7-
<p style="color:green;">Password changed with success!</p>
8-
{% endblock %}
8+
<head>
9+
<meta charset="UTF-8">
10+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
11+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
12+
<link rel="shortcut icon" href="#" type="image/x-icon">
13+
<!--Insert your brand favicon-->
14+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
15+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
16+
<title>Change Password</title>
17+
</head>
18+
19+
<body>
20+
<nav class="navbar navbar-expand-lg bg-light">
21+
<div class="container-fluid">
22+
<a class="navbar-brand" href="{% url 'home' %}">Company Name</a>
23+
</div>
24+
</nav>
25+
<div class="pb-5"></div>
26+
<div class="row justify-content-center">
27+
<div class="col-8">
28+
<div class="card mb-4">
29+
<div class="card-body">
30+
<h2>Change password</h2>
31+
<p style="color:green;">Password changed with success!</p>
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
<script>
37+
setTimeout("location.href = '{% url 'home' %}';", 1000);
38+
</script>
39+
</body>
40+
41+
</html>

0 commit comments

Comments
 (0)