-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
275 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,53 @@ Install the app in settings.py : | |
```python | ||
INSTALLED_APPS = [ | ||
[...] | ||
'social_django', | ||
'crispy_forms', | ||
'user_app', | ||
] | ||
``` | ||
|
||
Then add the settings for `social-auth-app-django` package, for example : | ||
Specify static files and media files in settings : | ||
|
||
```python | ||
STATIC_URL = '/static/' | ||
STATIC_ROOT = os.path.join(BASE_DIR, 'var/static/') | ||
MEDIA_URL = '/media/' | ||
MEDIA_ROOT = os.path.join(BASE_DIR, 'var/media/') | ||
``` | ||
|
||
Then add the settings for `social-auth-app-django` and 'django-crispy-froms' packages, for example : | ||
|
||
```python | ||
CRISPY_TEMPLATE_PACK = 'bootstrap4' | ||
|
||
USER_APP_PROVIDERS = [ | ||
{ | ||
"provider": "google-oauth2", | ||
"name": "Google", | ||
"link": None, | ||
"username": None, | ||
}, | ||
{ | ||
"provider": "github", | ||
"name": "Github", | ||
"link": "https://github.com/{{ data.login }}", | ||
"username": "{{ data.login }}", | ||
}, | ||
{ | ||
"provider": "twitter", | ||
"name": "Twitter", | ||
"link": "https://twitter.com/{{ data.access_token.screen_name }}/", | ||
"username": "@{{ data.access_token.screen_name }}", | ||
}, | ||
{ | ||
"provider": "facebook", | ||
"name": "Facebook", | ||
"link": None, | ||
"username": None, | ||
}, | ||
] | ||
|
||
AUTHENTICATION_BACKENDS = ( | ||
'django.contrib.auth.backends.ModelBackend', | ||
'social_core.backends.google.GoogleOAuth2', | ||
|
@@ -50,7 +90,7 @@ SOCIAL_AUTH_FACEBOOK_SECRET = "" | |
|
||
LOGIN_REDIRECT_URL = "/accounts/profile/" | ||
SOCIAL_AUTH_URL_NAMESPACE = 'social' | ||
AUTH_PROFILE_MODULE = 'accounts.Profile' | ||
AUTH_PROFILE_MODULE = 'user_app.Profile' | ||
|
||
SOCIAL_AUTH_PIPELINE = ( | ||
'social_core.pipeline.social_auth.social_details', | ||
|
@@ -69,56 +109,32 @@ SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/accounts/profile/' | |
SOCIAL_AUTH_DISCONNECT_REDIRECT_URL = '/' | ||
``` | ||
|
||
And finally use the `base.html` template like : | ||
|
||
```html | ||
<!doctype html> | ||
<html lang="fr"> | ||
|
||
<head> | ||
<!-- Required meta tags --> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>{% block title %}{% endblock title %}</title> | ||
{% block head %}{% endblock head %} | ||
|
||
<!-- Bootstrap CSS --> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" | ||
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> | ||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" | ||
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" | ||
crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" | ||
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" | ||
crossorigin="anonymous"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" | ||
integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" | ||
crossorigin="anonymous"></script> | ||
</head> | ||
|
||
<body> | ||
{% include 'nav.html' %} | ||
<div class="container pt-4 pd-4"> | ||
{% if success is True %} | ||
<div class="alert alert-success alert-dismissible fade show" role="alert"> | ||
Les modifications ont bien été enregistrées. | ||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
{% elif success is False %} | ||
<div class="alert alert-danger alert-dismissible fade show" role="alert"> | ||
Une erreur est survenue, les modifications n'ont pas été enregistrées. | ||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
{% endif %} | ||
{% block content %}{% endblock content %} | ||
</div> | ||
</body> | ||
|
||
</html> | ||
Then add the urls to the urlpattern of the project : | ||
|
||
```python | ||
from django.conf import settings | ||
from django.conf.urls.static import static | ||
#from django.contrib import admin | ||
from django.urls import path, include | ||
|
||
urlpatterns = [ | ||
#path('admin/', admin.site.urls), | ||
path('accounts/', include('user_app.urls')), | ||
path('accounts/', include('django.contrib.auth.urls')), | ||
path('', include("social_django.urls", namespace="social")), | ||
] + static( | ||
settings.STATIC_URL, | ||
document_root=settings.STATIC_ROOT | ||
) + static( | ||
settings.MEDIA_URL, | ||
document_root=settings.MEDIA_ROOT | ||
) | ||
``` | ||
|
||
And finally add the context_processor : | ||
|
||
```python | ||
user_app.context_processors.providers_settings | ||
``` | ||
|
||
Then you have to migrate the database with `python3 manage.py migrate` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Django>=3.0.8 | ||
Pillow>=7.2.0 | ||
Django==3.0.8 | ||
Pillow==7.2.0 | ||
social-auth-app-django==4.0.0 | ||
django-crispy-forms==1.9.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.conf import settings | ||
|
||
|
||
def providers_settings(request): | ||
return { | ||
'USER_APP_PROVIDERS': settings.USER_APP_PROVIDERS, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!doctype html> | ||
<html lang="fr"> | ||
|
||
<head> | ||
<!-- Required meta tags --> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>{% block title %}{% endblock title %}</title> | ||
{% block head %}{% endblock head %} | ||
|
||
<!-- Bootstrap --> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" | ||
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> | ||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" | ||
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" | ||
crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" | ||
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" | ||
crossorigin="anonymous"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" | ||
integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" | ||
crossorigin="anonymous"></script> | ||
</head> | ||
|
||
<body> | ||
{% include 'navbar.html' %} | ||
<div class="container pt-4 pd-4"> | ||
{% if success is True %} | ||
<div class="alert alert-success alert-dismissible fade show" role="alert"> | ||
Les modifications ont bien été enregistrées. | ||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
{% elif success is False %} | ||
<div class="alert alert-danger alert-dismissible fade show" role="alert"> | ||
Une erreur est survenue, les modifications n'ont pas été enregistrées. | ||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
{% endif %} | ||
{% block content %}{% endblock content %} | ||
</div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% load static %} | ||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> | ||
<a class="navbar-brand" href="/">Django-Template</a> | ||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" | ||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
|
||
<div class="collapse navbar-collapse" id="navbarSupportedContent"> | ||
<ul class="navbar-nav mr-auto"> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="#">Link</a> | ||
</li> | ||
</ul> | ||
<ul class="navbar-nav"> | ||
{% if user.is_authenticated %} | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{% url 'user_app:index' %}">Mon compte</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{% url 'logout' %}">Se déconnecter</a> | ||
</li> | ||
{% else %} | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{% url 'login' %}">Se connecter</a> | ||
</li> | ||
{% endif %} | ||
</ul> | ||
</div> | ||
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% extends 'base.html' %} | ||
{% load crispy_forms_tags %} | ||
|
||
|
||
{% block title %}Déconnecté{% endblock title %} | ||
|
||
{% block content %} | ||
<h1>Vous avez été déconnecté</h1> | ||
<p> | ||
Merci du temps que vous avez accordé à ce site. A bientôt ! | ||
</p> | ||
<p> | ||
Vous pouvez aussi vous <a href="{% url 'login' %}">reconnecter ici</a>. | ||
Ou simplement <a href="/">rester sur le site</a>. | ||
</p> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% extends 'base.html' %} | ||
{% load crispy_forms_tags %} | ||
|
||
|
||
{% block title %}Connexion{% endblock title %} | ||
|
||
{% block content %} | ||
<h1>Connexion</h1> | ||
<h2>Se connecter avec un compte utilisateur</h2> | ||
<div class="mb-3"> | ||
<form method="POST"> | ||
{% csrf_token %} | ||
{{ form|crispy }} | ||
<input type="submit" value="Enregistrer" class="btn btn-primary"> | ||
<input type="reset" value="Annuler" class="btn btn-secondary"> | ||
</form> | ||
<div class="mt-3"> | ||
<a href="{% url 'user_app:register' %}">Créer un compte</a> - <a href="{% url 'password_reset' %}">Mot de passe oublié</a> | ||
</div> | ||
</div> | ||
<h2>Se connecter avec un service tiers</h2> | ||
<div class="mb-3"> | ||
{% for provider in USER_APP_PROVIDERS %} | ||
<a href="{% url 'social:begin' provider.provider %}">Connectez-vous avec {{ provider.name }}</a><br> | ||
{% endfor %} | ||
</div> | ||
{% endblock content %} |
11 changes: 11 additions & 0 deletions
11
user_app/templates/registration/password_reset_complete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends 'base.html' %} | ||
|
||
|
||
{% block title %}Changement de mot de passe effectué{% endblock title %} | ||
|
||
{% block content %} | ||
<h1>Changement de mot de passe effectué</h1> | ||
<p> | ||
Votre mot de passe a bien été mis à jour. Vous pouvez vous <a href="{% url 'login' %}">connecter ici</a>. | ||
</p> | ||
{% endblock content %} |
22 changes: 22 additions & 0 deletions
22
user_app/templates/registration/password_reset_confirm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends 'base.html' %} | ||
{% load crispy_forms_tags%} | ||
|
||
|
||
{% block title %}Mot de passe oublié{% endblock title %} | ||
|
||
{% block content %} | ||
{% if validlink %} | ||
<h3>Changement de mot de passe</h3> | ||
<form method="POST"> | ||
{% csrf_token %} | ||
{{ form|crispy }} | ||
<input type="submit" value="Enregistrer" class="btn btn-primary"> | ||
<input type="reset" value="Annuler" class="btn btn-secondary"> | ||
</form> | ||
{% else %} | ||
<p> | ||
Le lien de réinitialisation du mot de passe n'était pas valide, peut-être parce qu'il a déjà été utilisé. | ||
Veuillez demander une nouvelle réinitialisation du mot de passe. | ||
</p> | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% extends 'base.html' %} | ||
|
||
|
||
{% block title %}Message de réinitialisation du mot de passe envoyé{% endblock title %} | ||
|
||
{% block content %} | ||
<h2>Message de réinitialisation du mot de passe envoyé</h2> | ||
<p> | ||
Nous vous avons envoyé par courriel les instructions pour changer de mot de passe, pour autant qu’un compte existe avec | ||
l’adresse que vous avez indiquée. Vous devriez recevoir rapidement ce message. | ||
</p> | ||
<p> | ||
Si vous ne recevez pas de message, vérifiez que vous avez saisi l’adresse avec laquelle vous vous êtes enregistré et | ||
contrôlez votre dossier de pourriels. | ||
</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% extends 'base.html' %} | ||
{% load crispy_forms_tags %} | ||
|
||
|
||
{% block title %}Mot de passe oublié{% endblock title %} | ||
|
||
{% block content %} | ||
<h1>Réinitialiser son mot de passe</h1> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{{ form|crispy }} | ||
<input type="submit" value="Enregistrer" class="btn btn-primary"> | ||
<input type="reset" value="Annuler" class="btn btn-secondary"> | ||
</form> | ||
<div class="mt-3"> | ||
<a href="{% url 'login' %}">Se connecter</a> | ||
</div> | ||
{% endblock %} |
Oops, something went wrong.