From 80f9b87d34427d2e4b0c169aac866c1f4aa7a53d Mon Sep 17 00:00:00 2001 From: Stefan Dworschak Date: Wed, 20 Jan 2021 21:50:13 +0000 Subject: [PATCH 1/6] Changing settings for Slack signup/login --- .env_sample | 1 + main/settings.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.env_sample b/.env_sample index 8cca200f..ced571e2 100644 --- a/.env_sample +++ b/.env_sample @@ -1,3 +1,4 @@ DEVELOPMENT=1 SECRET_KEY="your_secret_key_here" SITE_NAME="localhost" +SLACK_ENABLED=True \ No newline at end of file diff --git a/main/settings.py b/main/settings.py index f0b554dd..a0990fb2 100644 --- a/main/settings.py +++ b/main/settings.py @@ -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" @@ -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'], + } + } From 8be854cec71e1fdac01bdf3effdb9e1ee35ed757 Mon Sep 17 00:00:00 2001 From: Stefan Dworschak Date: Wed, 20 Jan 2021 21:51:40 +0000 Subject: [PATCH 2/6] Adjusting templates and views for Slack login --- home/urls.py | 3 ++- home/views.py | 14 +++++++++++++- static/css/allauthstyles.css | 10 ++++++++++ static/css/profile.css | 4 ++++ templates/allauth/account/login.html | 16 +++++++--------- .../socialaccount/authentication_error.html | 2 +- .../socialaccount/snippets/slack_signin.html | 12 ++++++++++++ templates/includes/navbar.html | 7 +++++++ templates/registration/login.html | 10 ++++++++++ 9 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 templates/allauth/socialaccount/snippets/slack_signin.html create mode 100644 templates/registration/login.html diff --git a/home/urls.py b/home/urls.py index cd9ee426..e0cf0efe 100644 --- a/home/urls.py +++ b/home/urls.py @@ -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"), ] diff --git a/home/views.py b/home/views.py index d569946b..310cebe1 100644 --- a/home/views.py +++ b/home/views.py @@ -1,13 +1,25 @@ -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 """ + hackathons = Hackathon.objects.all() return render(request, "home/index.html", {"hackathons": hackathons}) diff --git a/static/css/allauthstyles.css b/static/css/allauthstyles.css index d882ccc3..aaa2c0b7 100644 --- a/static/css/allauthstyles.css +++ b/static/css/allauthstyles.css @@ -59,3 +59,13 @@ 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); +} \ No newline at end of file diff --git a/static/css/profile.css b/static/css/profile.css index 7084b83f..e5c6247e 100644 --- a/static/css/profile.css +++ b/static/css/profile.css @@ -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; diff --git a/templates/allauth/account/login.html b/templates/allauth/account/login.html index 9917dcb1..468e450a 100644 --- a/templates/allauth/account/login.html +++ b/templates/allauth/account/login.html @@ -15,19 +15,16 @@ {% block allauth %}

{% trans "Sign In" %}

- {% get_providers as socialaccount_providers %} {% if socialaccount_providers %} -

{% blocktrans with site.name as site_name %}Please sign in with one - of your existing third party accounts. Or, sign up - for a {{ site_name }} account and sign in below:{% endblocktrans %} +

{% blocktrans with site.name as site_name %} + Please sign in with your Code Institute Slack!
+ (Workspace name: code-institiute-room) + {% endblocktrans %}

-
    - {% include "socialaccount/snippets/provider_list.html" with process="login" %} -
- + {% include "socialaccount/snippets/slack_signin.html" with process="login" %}
{% include "socialaccount/snippets/login_extra.html" %} @@ -35,7 +32,7 @@

{% trans "Sign In" %}

{% else %}

{% blocktrans %}If you have not created an account yet, then please sign up first.{% endblocktrans %}

- {% endif %} + + {% endif %} {% endblock %} {% block authhacklogo %} diff --git a/templates/allauth/socialaccount/authentication_error.html b/templates/allauth/socialaccount/authentication_error.html index 69f3ee19..892a1d14 100644 --- a/templates/allauth/socialaccount/authentication_error.html +++ b/templates/allauth/socialaccount/authentication_error.html @@ -1,5 +1,5 @@ {% extends "socialaccount/base.html" %} - +{% load static %} {% load i18n %} {% block head_title %}{% trans "Social Network Login Failure" %}{% endblock %} diff --git a/templates/allauth/socialaccount/snippets/slack_signin.html b/templates/allauth/socialaccount/snippets/slack_signin.html new file mode 100644 index 00000000..0fbff1d7 --- /dev/null +++ b/templates/allauth/socialaccount/snippets/slack_signin.html @@ -0,0 +1,12 @@ +{% load socialaccount %} + +{% get_providers as socialaccount_providers %} + +{% for provider in socialaccount_providers %} + {% if provider.name == 'Slack' %} + + + + {% endif %} +{% endfor %} diff --git a/templates/includes/navbar.html b/templates/includes/navbar.html index 5efb66df..d7efa9fa 100644 --- a/templates/includes/navbar.html +++ b/templates/includes/navbar.html @@ -1,5 +1,10 @@ {% load static %} +{% load account socialaccount %} +{% get_providers as socialaccount_providers %} + + +