Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github oauth added ( to avoid the spam contents ) #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
db.sqlite3
db.sqlite3
migrations
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ whitenoise = "*"
"psycopg2" = "*"
dj-database-url = "*"
djangorestframework = "*"
django-crispy-forms = "*"

[dev-packages]
pylint = "*"

[requires]
python_version = "3.7"
python_version = "3.6.5"
20 changes: 18 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions csqa_project/settings.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
"""
Django settings for csqa_project project.

Generated by 'django-admin startproject' using Django 3.0.5.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import sys
import dj_database_url
import os
Expand Down Expand Up @@ -51,6 +39,9 @@
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.github', # for github authentication ( to avoid spam register )

'crispy_forms',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -86,6 +77,8 @@
},
]

CRISPY_TEMPLATE_PACK = 'bootstrap4'

WSGI_APPLICATION = 'csqa_project.wsgi.application'


Expand Down Expand Up @@ -141,7 +134,15 @@

USE_TZ = True


SOCIALACCOUNT_PROVIDERS = {
'github': {
'SCOPE': [
'user',
'repo',
'read:org',
],
}
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

Expand All @@ -160,8 +161,11 @@
"allauth.account.auth_backends.AuthenticationBackend",
)

SITE_ID = 1
SITE_ID = 2

LOGIN_REDIRECT_URL = '/'

AUTH_USER_MODEL = 'users.User'
AUTH_USER_MODEL = 'users.User'



36 changes: 19 additions & 17 deletions templates/account/login.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{% extends "base.html" %}

{% load crispy_forms_tags %}
{% load account socialaccount %}

{% block content %}

<h3>Sign In</h3>

{% include "socialaccount/snippets/login_extra.html" %}

<p class="text-secondary">If you have not created an account yet, then please
<a href="{{ signup_url }}">sign up</a> first.</p>

<form class="login" method="POST" action="{% url 'account_login' %}">
{% csrf_token %}
{{ form.as_p }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button class="btn btn-primary primaryAction" type="submit">Sign In</button>
<div class="mt-3"><a class="button secondaryAction" href="{% url 'account_reset_password' %}">Forgot Password?</a></div>
</form>
<div class="col-md-12">
<h3 class="text-center">Sign In</h3>
<div class="col-md-12">
<form class="login" method="POST" action="{% url 'account_login' %}">
{% csrf_token %}
{{ form | crispy }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button class="btn btn-primary primaryAction form-control" type="submit">Sign In</button>
<div class="mt-3"><a class="button secondaryAction" href="{% url 'account_reset_password' %}">Forgot Password?</a></div>
</form>
<hr>
<a href="http://127.0.0.1:8000/accounts/github/login/?process=login" class="btn btn-secondary form-control my-3"><i class="fab fa-github"></i> Login with Github</a>
<p class="text-secondary text-center">If you have not created an account yet, then please
<a href="{{ signup_url }}">sign up</a> first.</p>
</div>

</div>
{% endblock %}
2 changes: 2 additions & 0 deletions templates/account/logout.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "base.html" %}

{% block content %}
<div class="col-md-12 text-center">
<h3>Sign Out</h3>

<p style="margin-top:10; margin-bottom:14">Are you sure you want to sign out?</p>
Expand All @@ -12,6 +13,7 @@ <h3>Sign Out</h3>
{% endif %}
<button type="submit" class="btn btn-sm btn-primary">Confirm</button>
</form>
</div>


{% endblock %}
33 changes: 21 additions & 12 deletions templates/account/signup.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{% extends "account/base.html" %}

{% load crispy_forms_tags %}
{% load account socialaccount %}
{% block content %}
<h3>Sign Up</h3>
<div class="col-md-12">
<h3 class="text-center">Sign Up</h3>

<div class="col-md-12 py-3">
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{{ form | crispy }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button type="submit" class="btn btn-primary form-control">Sign Up</button>
</form>
<hr>
<a href="http://127.0.0.1:8000/accounts/github/login/?process=login" class="btn btn-secondary form-control my-3"><i class="fab fa-github"></i> Sign up with Github</a>
<p class="text-secondary text-center">Already have an account? Then please <a href="{{ login_url }}">sign in</a>.</p>
</div>
</div>
{% endblock %}

<p class="text-secondary">Already have an account? Then please <a href="{{ login_url }}">sign in</a>.</p>

<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{{ form.as_p }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button type="submit" class="btn btn-primary">Sign Up</button>
</form>
<!-- http://127.0.0.1:8000/accounts/github/login/?process=login

{% endblock %}
1 change: 1 addition & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'style.css' %}">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
Expand Down