diff --git a/.gitignore b/.gitignore index 1ab2623..7db42fd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ db.sqlite3 node_modules venv +settings.py diff --git a/README.md b/README.md index 70e741f..3b54f0d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ * https * cookies: secure, httpOnly -Client: +## Client: + * Rewrite client side code in Backbone.js * Start here: https://github.com/backbone-boilerplate/backbone-boilerplate * Backbone Extensions: diff --git a/duskenweb/__init__.py b/duskenweb/__init__.py index e69de29..edaec93 100644 --- a/duskenweb/__init__.py +++ b/duskenweb/__init__.py @@ -0,0 +1,9 @@ +import pydusken +from django.conf import settings + +# Init DuskenAPI +system_api_conn = pydusken.DuskenApi(settings.DUSKEN_CLIENT_ID, settings.DUSKEN_CLIENT_SECRET) +if not system_api_conn.is_authenticated(): + system_api_conn.authenticate(settings.DUSKEN_USERNAME, settings.DUSKEN_PASSWORD) + +user_api_conn = pydusken.DuskenApi(settings.DUSKEN_CLIENT_ID, settings.DUSKEN_CLIENT_SECRET) diff --git a/duskenweb/settings.py b/duskenweb/settings-sample.py similarity index 93% rename from duskenweb/settings.py rename to duskenweb/settings-sample.py index ccdc07a..410db7d 100644 --- a/duskenweb/settings.py +++ b/duskenweb/settings-sample.py @@ -104,12 +104,16 @@ USE_TZ = True STATIC_URL = '/static/' LOGIN_REDIRECT_URL = "/profile/" +LOGIN_URL = "/login/" -DUSKEN_CLIENT_ID = 'd802768a8afd9dec2660' -DUSKEN_CLIENT_SECRET = '3962467fe60a94727812053c8a4f44533f4ef610' +DUSKEN_CLIENT_ID = '' +DUSKEN_CLIENT_SECRET = '' +# Dusken API system user +DUSKEN_USERNAME = 'duskenweb' +DUSKEN_PASSWORD = '' CORS_ORIGIN_ALLOW_ALL = True -# Allow Ajax calls only from tuple of domain:port +# Allow Ajax calls only from domain:port #CORS_ORIGIN_WHITELIST = ( # '127.0.0.1:3000', # 'dusken.neuf.no:3000', diff --git a/duskenweb/static/css/app.css b/duskenweb/static/css/app.css index 29e9fa1..21555b3 100644 --- a/duskenweb/static/css/app.css +++ b/duskenweb/static/css/app.css @@ -1,6 +1,6 @@ /* line 1, ../sass/app.scss */ .title-header { - margin-bottom: 3em; + margin-bottom: 2em; } /* line 4, ../sass/app.scss */ @@ -30,7 +30,7 @@ top: 2px; padding-right: 6px; } -/* line 29, ../sass/app.scss */ +/* line 30, ../sass/app.scss */ .social-login .btn-facebook-login:hover, .social-login .btn-facebook-login:focus { background-color: #2f477a; color: white; diff --git a/duskenweb/static/sass/app.scss b/duskenweb/static/sass/app.scss index d6903fe..d76fe6e 100644 --- a/duskenweb/static/sass/app.scss +++ b/duskenweb/static/sass/app.scss @@ -1,5 +1,5 @@ .title-header { - margin-bottom: 3em; + margin-bottom: 2em; } .social-login { text-align: center; diff --git a/duskenweb/templates/base.html b/duskenweb/templates/base.html index 8f94e24..85d6a02 100644 --- a/duskenweb/templates/base.html +++ b/duskenweb/templates/base.html @@ -15,8 +15,7 @@
-

D.U.S.K.E.N.

- DÃ¥rlig Utrustet Studentsystem som Kan Endre Norge +

Dusken

diff --git a/duskenweb/templates/members_index.html b/duskenweb/templates/members_index.html new file mode 100644 index 0000000..4b701ec --- /dev/null +++ b/duskenweb/templates/members_index.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% block content %} +
+
+
+
    + {% for member in members_list.objects %} +
  • {{member.username}}: {{member.email}}
  • + {% endfor %} +
+
+
+
+{% endblock %} diff --git a/duskenweb/templates/profile.html b/duskenweb/templates/profile.html index 534487c..48d33b8 100644 --- a/duskenweb/templates/profile.html +++ b/duskenweb/templates/profile.html @@ -8,6 +8,15 @@
  • Username: '{{user.username}}'
  • Email: '{{user.email}}'
  • +

    Actions

    + + + +
    +
    + Logout
    diff --git a/duskenweb/urls.py b/duskenweb/urls.py index ff73a24..b8ce8b3 100644 --- a/duskenweb/urls.py +++ b/duskenweb/urls.py @@ -13,6 +13,8 @@ urlpatterns = patterns('', urlpatterns += patterns('duskenweb.views', url(r'^$', 'home', name='home'), url(r'^profile/$', 'profile', name='profile'), + url(r'^members/$', 'members_list', name='members_list'), + ) # Authentication views diff --git a/duskenweb/views.py b/duskenweb/views.py index c383e70..e3e363a 100644 --- a/duskenweb/views.py +++ b/duskenweb/views.py @@ -1,7 +1,10 @@ from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required -# Create your views here. +from django.views import generic + +from . import user_api_conn # Note: initialized in __init__.py + def home(request): if request.user.is_authenticated(): return redirect('profile') @@ -11,3 +14,12 @@ def home(request): @login_required def profile(request): return render(request, 'profile.html') + +@login_required +def members_list(request): + # TODO put these two lines somewhere else, on authenticate? + if not user_api_conn.is_authenticated() and request.user.duskenaccesstoken: + user_api_conn.set_access_token(request.user.duskenaccesstoken.access_token) + + members_list = user_api_conn.members.get_list() + return render(request, 'members_index.html', locals())