Skip to content

Commit

Permalink
Merge pull request #13 from Decide-Part-Rota/Rota3-003
Browse files Browse the repository at this point in the history
Arreglado conflictos con social applications en la base de datos, importante que no existe social applications previas en la base de datos(ver panel admin) y que el site conocido como example tenga id en la URL igual a 1(ver también panel admin)
  • Loading branch information
alfcadmorUS authored Nov 29, 2022
2 parents a629d0d + 7abe5bc commit e6f71b2
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 10 deletions.
4 changes: 4 additions & 0 deletions decide/authentication/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Meta:
model=User
fields=["username","password1","password2","email","sex","age"]

class CompleteForm(forms.Form):
sex = forms.ChoiceField(choices=sexos, required=True)
age = forms.IntegerField(required=True)




Expand Down
28 changes: 28 additions & 0 deletions decide/authentication/templates/complete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html>

<head>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Complete</title>

</head>

<body>

<h2 class="d-flex justify-content-center" style="margin: 20;">Complete demographic information</h2>
<h2 class="d-flex justify-content-center" style="margin: 20;">before proceeding</h2>

<div class="d-flex justify-content-center">
<form method="POST" style="margin: 10;">
{%csrf_token%}
<table>
{{form.as_table}}
</table>
<br>
<button type="submit" class="btn btn-outline-dark">Submit</button>
</form>
</div>

</body>

</html>
4 changes: 2 additions & 2 deletions decide/authentication/templates/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<head>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="{% static "registration/style.css" %}" />
<link type="text/css" rel="stylesheet" href="{% static 'registration/style.css' %}" />
<title>Register</title>

</head>
Expand All @@ -28,7 +28,7 @@ <h1 class="d-flex justify-content-center" style="margin: 20;">Register form</h1>

<br><br>

<a href="{% provider_login_url 'google' %}">
<a href="{% provider_login_url 'google' next='/authentication/completeForm/' %}">
<button type="button" class="login-with-google-btn" >
Sign in with Google
</button>
Expand Down
4 changes: 2 additions & 2 deletions decide/authentication/templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="{% static "registration/style.css" %}" />
<link type="text/css" rel="stylesheet" href="{% static 'registration/style.css' %}" />
<title>Login</title>
</head>

Expand Down Expand Up @@ -35,7 +35,7 @@ <h1>Iniciar sesión</h1>

<br><br>

<a href="{% provider_login_url 'google' %}">
<a href="{% provider_login_url 'google' next='/authentication/completeForm/' %}">
<button type="button" class="login-with-google-btn" >
Sign in with Google
</button>
Expand Down
3 changes: 2 additions & 1 deletion decide/authentication/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework.authtoken.views import obtain_auth_token


from .views import GetUserView, LogoutView, RegisterView, loginForm, register, salir, loginForm
from .views import GetUserView, LogoutView, RegisterView, loginForm, register, salir, loginForm, complete

from django.contrib import admin
from django.views.generic import TemplateView
Expand All @@ -17,6 +17,7 @@
path('providers/', include('allauth.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('salir/', salir, name='salir'),
path('completeForm/', complete),


]
27 changes: 25 additions & 2 deletions decide/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.contrib.auth import authenticate, login, logout

from .serializers import UserSerializer
from .forms import PersonForm, LoginForm
from .forms import PersonForm, LoginForm, CompleteForm
from .models import Person


Expand Down Expand Up @@ -135,4 +135,27 @@ def welcome(request):

def salir(request):
logout(request)
return redirect('/')
return redirect('/')


def complete(request):
if request.user.is_authenticated and not Person.objects.filter(user = request.user.id).exists():
user = request.user
form=CompleteForm

if request.method=="POST":
form=CompleteForm(request.POST)

if form.is_valid():
sex = form.cleaned_data.get('sex')
age = form.cleaned_data.get('age')

person = Person(user = user, sex = sex, age = age)
person.save()

return redirect('/')

return render(request,'complete.html',{'form':form})
else:
return redirect('/')

10 changes: 7 additions & 3 deletions decide/local_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@
'allauth.account.auth_backends.AuthenticationBackend'
]

SITE_ID = 2
LOGIN_REDIRECT_URL = '/'
SITE_ID = 1
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
SOCIALACCOUNT_LOGIN_ON_GET = True
ACCOUNT_LOGOUT_ON_GET = True

SOCIALACCOUNT_PROVIDERS = {
'google': {
'APP': {
'client_id': '992476478153-6p58v7uvoa569ola5jogpm8nr64fpiop.apps.googleusercontent.com',
'secret': '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',
'key': ''
},
'SCOPE': [
'profile',
'email',
Expand Down

0 comments on commit e6f71b2

Please sign in to comment.