Skip to content

Commit

Permalink
Authentication added
Browse files Browse the repository at this point in the history
  • Loading branch information
imanaspaul committed Jan 23, 2020
1 parent 326add7 commit 1fefae9
Show file tree
Hide file tree
Showing 15 changed files with 617 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ verify_ssl = true

[packages]
django = "*"
django-allauth = "*"
django-crispy-forms = "*"

[requires]
python_version = "3.6"
43 changes: 24 additions & 19 deletions backend/settings.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
"""
Django settings for backend project.
Generated by 'django-admin startproject' using Django 3.0.2.
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 os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'c!s_xdh8^va%uy#p$b4(0!#lzz@vh*_7wnmz10qka0#nyr9dkn'

# SECURITY WARNING: don't run with debug turned on in production!

DEBUG = True

ALLOWED_HOSTS = []
Expand All @@ -39,6 +22,14 @@
'django.contrib.staticfiles',
'message',
'userprofile',

'django.contrib.sites',

'allauth',
'allauth.account',
'allauth.socialaccount',

'crispy_forms',
]

MIDDLEWARE = [
Expand All @@ -51,12 +42,20 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

# Djngo all-auth authentication backend settings

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)


ROOT_URLCONF = 'backend.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -123,3 +122,9 @@
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static")
]


SITE_ID = 1
CRISPY_TEMPLATE_PACK = 'bootstrap4'

LOGIN_REDIRECT_URL = '/dashboard/'
1 change: 1 addition & 0 deletions backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

urlpatterns = [
path('', include("userprofile.urls")),
path('', include('allauth.urls')),
path('send/', include('message.urls', namespace="sendmessage")),
path('admin/', admin.site.urls),
]
Binary file modified db.sqlite3
Binary file not shown.
24 changes: 23 additions & 1 deletion message/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@

urlpatterns = [
# path('<id>/', sendmail, name='sendmail'),

path('success/', success, name='success'),
path('user/<id>/', sendmail, name='sendmail'),
]
]


# Django all-auth urls


# accounts/ signup/ [name='account_signup']
# accounts/ login/ [name='account_login']
# accounts/ logout/ [name='account_logout']
# accounts/ password/change/ [name='account_change_password']
# accounts/ password/set/ [name='account_set_password']
# accounts/ inactive/ [name='account_inactive']
# accounts/ email/ [name='account_email']
# accounts/ confirm-email/ [name='account_email_verification_sent']
# accounts/ ^confirm-email/(?P<key>[-:\w]+)/$ [name='account_confirm_email']
# accounts/ password/reset/ [name='account_reset_password']
# accounts/ password/reset/done/ [name='account_reset_password_done']
# accounts/ ^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$ [name='account_reset_password_from_key']
# accounts/ password/reset/key/done/ [name='account_reset_password_from_key_done']
# accounts/ social/
# send/
# admin/
2 changes: 1 addition & 1 deletion message/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def sendmail(request, id):
print(id)
name = request.GET.get("name")
email = request.GET.get("email")
# context = {""}
# context = {""}
return redirect('sendmessage:success')


Expand Down
58 changes: 58 additions & 0 deletions templates/account/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<title>{% block head_title %}{% endblock %}</title>
{% block extra_head %}
{% endblock %}
<style>
body{
width: 100%;
height: 100vh;
background-color: #2F2E41;
}
</style>
</head>
<body>
{% block body %}

{% if messages %}
{% for message in messages %}
<script>
const Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
onOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer)
toast.addEventListener('mouseleave', Swal.resumeTimer)
}
})

Toast.fire({
icon: 'success',
title: {{ message }}
});
</script>
{% endfor %}
{% endif %}
{% block content %}
{% endblock %}
{% endblock %}
{% block extra_body %}
{% endblock %}
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions templates/account/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

{% extends 'account/base.html' %}
{% load crispy_forms_tags %}
{% load i18n %}

{% block head_title %}{% trans "Signup" %}{% endblock %}

{% block content %}
<section class="container pt-5">
<div class="row pt-5">
<div class="col-md-6 offset-md-3">
<div class="card text-center">
<div class="card-body px-5">
<h2>Login</h2>
<hr>
<form class="signup text-left" id="signup_form" 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-success form-control " type="submit">{% trans "Sign Up" %} &raquo;</button>
</form>
<br>
<p>{% blocktrans %}Already have an account? Then please <a href="{{ signup_url }}">sign in</a>.{% endblocktrans %}</p>
</div>
</div>
</div>
</div>
</section>
{% endblock %}
31 changes: 31 additions & 0 deletions templates/account/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

{% extends 'account/base.html' %}
{% load crispy_forms_tags %}
{% load i18n %}

{% block head_title %}{% trans "Signup" %}{% endblock %}

{% block content %}
<section class="container pt-5">
<div class="row pt-5">
<div class="col-md-6 offset-md-3">
<div class="card text-center">
<div class="card-body px-5">
<h2>Sign up</h2>
<hr>
<form class="signup text-left" 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 class="btn btn-success form-control " type="submit">{% trans "Sign Up" %} &raquo;</button>
</form>
<br>
<p>{% blocktrans %}Already have an account? Then please <a href="{{ login_url }}">sign in</a>.{% endblocktrans %}</p>
</div>
</div>
</div>
</div>
</section>
{% endblock %}
93 changes: 93 additions & 0 deletions userprofile/static/userprofile/css/dashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
body {
font-size: .875rem;
}

.feather {
width: 16px;
height: 16px;
vertical-align: text-bottom;
}

/*
* Sidebar
*/

.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
z-index: 100; /* Behind the navbar */
padding: 0;
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}

.sidebar-sticky {
position: -webkit-sticky;
position: sticky;
top: 48px; /* Height of navbar */
height: calc(100vh - 48px);
padding-top: .5rem;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
}

.sidebar .nav-link {
font-weight: 500;
color: #333;
}

.sidebar .nav-link .feather {
margin-right: 4px;
color: #999;
}

.sidebar .nav-link.active {
color: #007bff;
}

.sidebar .nav-link:hover .feather,
.sidebar .nav-link.active .feather {
color: inherit;
}

.sidebar-heading {
font-size: .75rem;
text-transform: uppercase;
}

/*
* Navbar
*/

.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
font-size: 1rem;
background-color: rgba(0, 0, 0, .25);
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}

.navbar .form-control {
padding: .75rem 1rem;
border-width: 0;
border-radius: 0;
}

.form-control-dark {
color: #fff;
background-color: rgba(255, 255, 255, .1);
border-color: rgba(255, 255, 255, .1);
}

.form-control-dark:focus {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}

/*
* Utilities
*/

.border-top { border-top: 1px solid #e5e5e5; }
.border-bottom { border-bottom: 1px solid #e5e5e5; }
Loading

0 comments on commit 1fefae9

Please sign in to comment.