Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 46903b6

Browse files
puneeth-chandaaswinshenoy
authored andcommitted
github auth and signup added (#31)
1 parent e063e34 commit 46903b6

File tree

12 files changed

+71
-3
lines changed

12 files changed

+71
-3
lines changed

accounts/__init__.py

Whitespace-only changes.

accounts/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

accounts/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountsConfig(AppConfig):
5+
name = 'accounts'

accounts/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

accounts/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

accounts/urls.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.urls import path
2+
3+
from . import views
4+
5+
urlpatterns = [
6+
path('signup/', views.SignUp.as_view(), name='signup'),
7+
]

accounts/views.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.contrib.auth.forms import UserCreationForm
2+
from django.urls import reverse_lazy
3+
from django.views import generic
4+
5+
6+
class SignUp(generic.CreateView):
7+
form_class = UserCreationForm
8+
success_url = reverse_lazy('login')
9+
template_name = 'signup.html'

portal/settings.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
'user',
4141
'algorithms',
4242
'repo',
43-
'social_django'
43+
'social_django',
44+
'accounts.apps.AccountsConfig'
4445
]
4546

4647
MIDDLEWARE = [
@@ -51,6 +52,7 @@
5152
'django.contrib.auth.middleware.AuthenticationMiddleware',
5253
'django.contrib.messages.middleware.MessageMiddleware',
5354
'django.middleware.clickjacking.XFrameOptionsMiddleware',
55+
'social_django.middleware.SocialAuthExceptionMiddleware',
5456
]
5557

5658
ROOT_URLCONF = 'portal.urls'
@@ -130,8 +132,11 @@
130132
STATIC_URL = '/static/'
131133
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
132134

135+
LOGIN_URL = 'accounts/login'
136+
LOGOUT_URL = 'logout'
137+
133138
LOGIN_REDIRECT_URL = '/'
134139
LOGOUT_REDIRECT_URL = '/'
135140

136-
SOCIAL_AUTH_GITHUB_KEY = '<key-here>'
137-
SOCIAL_AUTH_GITHUB_SECRET = '<key-here>'
141+
SOCIAL_AUTH_GITHUB_KEY = '<token>'
142+
SOCIAL_AUTH_GITHUB_SECRET = '<token>'

portal/urls.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@
2020
path('admin/', admin.site.urls),
2121
path('',include('user.urls')),
2222
path('repo/', include('repo.urls')),
23+
path('accounts/', include('accounts.urls')),
2324
path('accounts/', include('django.contrib.auth.urls')),
25+
path('oauth/',include('social_django.urls'), name='social'),
2426
]

templates/base.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
{%load static%}
3+
<html>
4+
<title href='/'>GitLit</title>
5+
<body>
6+
<div>
7+
<div >
8+
<div>
9+
{%block content%}
10+
{%endblock%}
11+
</div>
12+
</div>
13+
</div>
14+
</body>
15+
</html>

templates/signup.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% extends 'base.html' %}
2+
3+
{% block title %}Sign Up{% endblock %}
4+
5+
{% block content %}
6+
<h2>Sign up</h2>
7+
<form method="post">
8+
{% csrf_token %}
9+
{{ form.as_p }}
10+
<button type="submit">Sign up</button>
11+
<a href="{% url 'social:begin' 'github' %}">SignUp with GitHub</a><br>
12+
</form>
13+
14+
{% endblock %}

user/templates/user/name.html

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
{% else %}
1111
<p>You are not logged in</p>
1212
<a href="{% url 'login' %}">login</a>
13+
<a href="{% url 'social:begin' 'github' %}">Login with GitHub</a><br>
14+
<a href = "{% url 'signup' %}">Signup</a>
1315
{% endif %}
1416
{% endblock %}

0 commit comments

Comments
 (0)