diff --git a/config/settings.py b/config/settings.py index 5a79664..2ed6734 100644 --- a/config/settings.py +++ b/config/settings.py @@ -178,4 +178,4 @@ CRISPY_TEMPLATE_PACK = 'bootstrap4' LOGIN_URL = 'login' LOGOUT_URL = 'logout' -LOGIN_REDIRECT_URL = 'home' +LOGIN_REDIRECT_URL = 'profile' diff --git a/config/urls.py b/config/urls.py index b64b45e..f0c3811 100644 --- a/config/urls.py +++ b/config/urls.py @@ -30,6 +30,7 @@ urlpatterns = [ path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'), path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'), path('profile/', user_views.profile, name='profile'), + path('profile/password/', user_views.password, name='password'), path('oauth/', include('social_django.urls', namespace='social')), diff --git a/news/views.py b/news/views.py index afba160..287642e 100644 --- a/news/views.py +++ b/news/views.py @@ -1,4 +1,5 @@ from django.shortcuts import render +from users.models import Profile # Create your views here. @@ -6,4 +7,7 @@ def about (request): return render (request, 'news/about.html') def home (request): + if request.user.is_authenticated and Profile.objects.filter(user=request.user).count() < 1: + Profile.objects.create(user=request.user).save() + return render (request, 'news/home.html') diff --git a/users/signals.py b/users/signals.py index cb32c48..c0d507c 100644 --- a/users/signals.py +++ b/users/signals.py @@ -3,11 +3,17 @@ from django.contrib.auth.models import User from django.dispatch import receiver from .models import Profile +#from social_auth.signals import socialauth_registered + + @receiver(post_save, sender=User) def create_profile(sender, instance, created, **kwargs): if created: + print ("CREATED") Profile.objects.create(user=instance) + @receiver(post_save, sender=User) def save_profile(sender, instance, **kwargs): + print ("SAVED") instance.profile.save() diff --git a/users/templates/users/password.html b/users/templates/users/password.html new file mode 100644 index 0000000..2458c16 --- /dev/null +++ b/users/templates/users/password.html @@ -0,0 +1,13 @@ +{% extends 'news/base.html' %} +{% load crispy_forms_tags %} +{% block content %} +
You have not defined a password yet.
+ {% endif %} + +{% endblock %} diff --git a/users/templates/users/profile.html b/users/templates/users/profile.html index ecbc3b1..503ee53 100644 --- a/users/templates/users/profile.html +++ b/users/templates/users/profile.html @@ -9,6 +9,58 @@{{ user.email }}
+ +Connected as {{ github_login.extra_data.login }}
+ {% if can_disconnect %} + + {% else %} + +You must define a password for your account before disconnecting from Github.
+ {% endif %} + {% else %} + Connect to GitHub + {% endif %} + +Connected as @{{ google_login.extra_data.access_token.screen_name }}
+ {% if can_disconnect %} + + {% else %} + +You must define a password for your account before disconnecting from Google.
+ {% endif %} + {% else %} + Connect to Google + {% endif %} + +Connected as {{ facebook_login.extra_data.id }}
+ {% if can_disconnect %} + + {% else %} + +You must define a password for your account before disconnecting from Facebook.
+ {% endif %} + {% else %} + Connect to Facebook + {% endif %} + +