diff --git a/.env_sample b/.env_sample index 8cca200f..89fa2b3c 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 diff --git a/accounts/urls.py b/accounts/urls.py index c5a41e4b..c8ffc9df 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -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()), ] diff --git a/accounts/views.py b/accounts/views.py index 9230cb43..276ba47f 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -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 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..4193fa91 100644 --- a/home/views.py +++ b/home/views.py @@ -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 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'], + } + } diff --git a/static/css/allauthstyles.css b/static/css/allauthstyles.css index d882ccc3..e70f869c 100644 --- a/static/css/allauthstyles.css +++ b/static/css/allauthstyles.css @@ -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); +} 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..133a56d6 100644 --- a/templates/allauth/account/login.html +++ b/templates/allauth/account/login.html @@ -15,19 +15,16 @@ {% block allauth %}
{% 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-institute-room)
+ {% endblocktrans %}
{% 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..77fa8f20 --- /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..dcd75f72 100644
--- a/templates/includes/navbar.html
+++ b/templates/includes/navbar.html
@@ -1,5 +1,7 @@
{% load static %}
+{% load account socialaccount %}
+{% get_providers as socialaccount_providers %}