Skip to content
Merged
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
1 change: 1 addition & 0 deletions .env_sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEVELOPMENT=1
SECRET_KEY="your_secret_key_here"
SITE_NAME="localhost"
SLACK_ENABLED=True
2 changes: 2 additions & 0 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.contrib.auth.views import LoginView
from django.urls import path
from . import views

urlpatterns = [
path("edit_profile/", views.edit_profile, name="edit_profile"),
path('admin/', LoginView.as_view()),
]
2 changes: 2 additions & 0 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from allauth.account.views import SignupView

from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.contrib import messages
Expand Down
3 changes: 2 additions & 1 deletion home/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from . import views

urlpatterns = [
path("", views.index, name="home"),
path("", views.home, name="home"),
path("faq/", views.faq, name="faq"),
path("judging_criteria/", views.judging_criteria, name="judging_criteria"),
path("plagiarism_policy/", views.plagiarism_policy, name="plagiarism_policy"),
path("privacy_policy/", views.privacy_policy, name="privacy_policy"),
path("post_login/", views.index, name="post_login"),
]

13 changes: 12 additions & 1 deletion home/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from django.shortcuts import render
from django.shortcuts import render, redirect, reverse

from hackathon.models import Hackathon


def index(request):
""" The view to be redirected to after login which will check if the
user's full name is present, if it is not redirect to edit profile,
otherwise redirect to home
"""
if request.user.full_name:
return redirect(reverse('home'))

return redirect(reverse('edit_profile'))


def home(request):
"""
A view to return the index page
and upcoming Hackathon information
Expand Down
13 changes: 11 additions & 2 deletions main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@
AUTH_USER_MODEL = "accounts.CustomUser"
ACCOUNT_SIGNUP_FORM_CLASS = "accounts.forms.SignupForm"
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_EMAIL_VERIFICATION = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_SIGNUP_EMAIL_ENTER_TWICE = False
ACCOUNT_USER_MODEL_USERNAME_FIELD = 'slack_display_name'
ACCOUNT_USERNAME_MIN_LENGTH = 4
LOGIN_URL = "/accounts/login/"
LOGIN_REDIRECT_URL = "/"
LOGIN_REDIRECT_URL = "/post_login/"


WSGI_APPLICATION = "main.wsgi.application"
Expand Down Expand Up @@ -151,3 +152,11 @@
MEDIAFILES_LOCATION = "media"
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")

if os.environ.get("SLACK_ENABLED") == 'True':
INSTALLED_APPS += ['allauth.socialaccount.providers.slack']
SOCIALACCOUNT_PROVIDERS = {
'slack': {
'SCOPE':['identity.basic', 'identity.email'],
}
}
9 changes: 9 additions & 0 deletions static/css/allauthstyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ html form button:hover {
.mt-4 {
margin-bottom: 3.2rem;
}

.slack-workspace {
font-size: .75rem;
}

.slack-workspace .slack-workspace-name {
font-style: italic;
color: var(--p-orange);
}
4 changes: 4 additions & 0 deletions static/css/profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
white-space: pre-wrap;
}

.edit-profile div form p label {
display: block;
}

.card .card-body p.profile-website-url a {
text-transform: lowercase;
font-size: 1rem;
Expand Down
16 changes: 7 additions & 9 deletions templates/allauth/account/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,24 @@
{% block allauth %}

<h1>{% trans "Sign In" %}</h1>

{% get_providers as socialaccount_providers %}

{% if socialaccount_providers %}
<p>{% blocktrans with site.name as site_name %}Please sign in with one
of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
for a {{ site_name }} account and sign in below:{% endblocktrans %}
<p>{% blocktrans with site.name as site_name %}
Please sign in with your Code Institute Slack!<br>
<span class="slack-workspace">(Workspace name: <span class="slack-workspace-name">code-institute-room</span></span>)
{% endblocktrans %}
</p>
<div class="socialaccount_ballot">
<ul class="socialaccount_providers">
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
</ul>
<div class="login-or">{% trans 'or' %}</div>
{% include "socialaccount/snippets/slack_signin.html" with process="login" %}
</div>

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

{% else %}
<p>{% blocktrans %}If you have not created an account yet, then please
<a href="{{ signup_url }}">sign up</a> first.{% endblocktrans %}</p>
{% endif %}


<form class="login" method="POST" action="{% url 'account_login' %}">
{% csrf_token %}
Expand All @@ -46,6 +43,7 @@ <h1>{% trans "Sign In" %}</h1>
<a class="button secondaryAction" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
<button class="primaryAction" type="submit">{% trans "Sign In" %}</button>
</form>
{% endif %}
{% endblock %}

{% block authhacklogo %}
Expand Down
2 changes: 1 addition & 1 deletion templates/allauth/socialaccount/authentication_error.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "socialaccount/base.html" %}

{% load static %}
{% load i18n %}

{% block head_title %}{% trans "Social Network Login Failure" %}{% endblock %}
Expand Down
12 changes: 12 additions & 0 deletions templates/allauth/socialaccount/snippets/slack_signin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% load socialaccount %}

{% get_providers as socialaccount_providers %}

{% for provider in socialaccount_providers %}
{% if provider.name == 'Slack' %}
<a title="{{ provider.name }}" class="socialaccount_provider {{ provider.id }}"
href="{% provider_login_url provider.id process=process scope=scope auth_params=auth_params %}">
<img src="https://api.slack.com/img/sign_in_with_slack.png">
</a>
{% endif %}
{% endfor %}
4 changes: 4 additions & 0 deletions templates/includes/navbar.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% load static %}

{% load account socialaccount %}
{% get_providers as socialaccount_providers %}
<nav class="navbar navbar-expand-lg navbar-light bg-navbar">
<div class="container">
<a href="{% url 'home' %}" class="navbar-brand"></a>
Expand Down Expand Up @@ -44,7 +46,9 @@
</a>
<div class="dropdown-menu" aria-labelledby="navbarAccount">
{% if not user.is_authenticated %}
{% if not socialaccount_providers%}
<a class="dropdown-item" href="{% url 'account_signup' %}">Register</a>
{% endif %}
<a class="dropdown-item" href="{% url 'account_login' %}">Login</a>
{% else %}
<a class="dropdown-item" href="{% url 'profile' %}">My Profile</a>
Expand Down
9 changes: 9 additions & 0 deletions templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% block content %}
<h2>Admin Login</h2>
<form action="/accounts/admin/" method="POST">
{% csrf_token %}
{{form.as_p}}
<input type="submit" class="btn btn-primary">
</form>
{% endblock %}