merge
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
# from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@@ -1,5 +0,0 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AccountsConfig(AppConfig):
|
||||
name = 'accounts'
|
||||
@@ -1,27 +0,0 @@
|
||||
import ldap3
|
||||
|
||||
|
||||
def authentication(username, password):
|
||||
# no empty passwords
|
||||
if password is None or password.strip() == "":
|
||||
# messages.info("username:%s Login denied for blank password", username)
|
||||
return None
|
||||
|
||||
# username format
|
||||
new_username = 'uid={username}, cn=users, cn=accounts, dc=demo1, dc=freeipa, dc=org'
|
||||
userdn = new_username.format(username=username)
|
||||
|
||||
server_uri = 'ipa.demo1.freeipa.org'
|
||||
server = ldap3.Server(server_uri, get_info=ldap3.ALL)
|
||||
|
||||
try:
|
||||
ldap3.Connection(
|
||||
server,
|
||||
userdn,
|
||||
password,
|
||||
auto_bind=True,
|
||||
)
|
||||
except ldap3.core.exceptions.LDAPBindError:
|
||||
username = None
|
||||
|
||||
return username
|
||||
@@ -1,11 +0,0 @@
|
||||
from django.shortcuts import redirect
|
||||
|
||||
|
||||
def unauthenticated_user(view_func):
|
||||
def wrapper_func(request, *args, **kwargs):
|
||||
if request.user.is_authenticated:
|
||||
return redirect('home')
|
||||
else:
|
||||
return view_func(request, *args, **kwargs)
|
||||
|
||||
return wrapper_func
|
||||
@@ -1,3 +0,0 @@
|
||||
# from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@@ -1,3 +0,0 @@
|
||||
# from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -1,8 +0,0 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('login/', views.loginPage, name="login"),
|
||||
path('logout/', views.logoutUser, name="logout"),
|
||||
]
|
||||
@@ -1,40 +0,0 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib.auth import login, logout
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from .authentications import authentication
|
||||
# from .decorators import unauthenticated_user
|
||||
|
||||
|
||||
# @unauthenticated_user
|
||||
def loginPage(request):
|
||||
"""
|
||||
if request.user.is_authenticated:
|
||||
return redirect('home')
|
||||
else:
|
||||
"""
|
||||
if request.method == 'POST':
|
||||
username = request.POST.get('username')
|
||||
password = request.POST.get('password')
|
||||
|
||||
auth_user = authentication(username, password)
|
||||
|
||||
if auth_user is not None:
|
||||
try:
|
||||
user = User.objects.get(username=username)
|
||||
except User.DoesNotExist:
|
||||
user = User.objects.create_user(auth_user)
|
||||
|
||||
login(request, user)
|
||||
return redirect('home')
|
||||
else:
|
||||
messages.info(request, 'username OR password is incorrect')
|
||||
|
||||
context = {}
|
||||
return render(request, 'accounts/login.html', context)
|
||||
|
||||
|
||||
def logoutUser(request):
|
||||
logout(request)
|
||||
return redirect('home')
|
||||
@@ -3,23 +3,30 @@ from etherpad_lite import EtherpadLiteClient
|
||||
from datetime import datetime, timedelta
|
||||
from django.utils.text import slugify
|
||||
import urllib.parse
|
||||
t=datetime.now() + timedelta(days=1)
|
||||
t = datetime.now() + timedelta(days=1)
|
||||
|
||||
SERVER_URL="https://etherpad2.2020.fet.at/"
|
||||
|
||||
|
||||
with open("/srv/andis_test/etherpad_test2/etherpad-lite/APIKEY.txt","r") as f:
|
||||
k=f.read()
|
||||
epc=EtherpadLiteClient( base_params={'apikey':k,}, base_url=urllib.parse.urljoin("http://localhost:9003","api"))
|
||||
a=epc.createAuthorIfNotExistsFor(name="andis", authorMapper="andis")
|
||||
g=epc.createGroupIfNotExistsFor(groupMapper="fet")
|
||||
|
||||
with open("/srv/andis_test/etherpad_test2/etherpad-lite/APIKEY.txt", "r") as f:
|
||||
k = f.read()
|
||||
epc = EtherpadLiteClient(
|
||||
base_params={'apikey': k, },
|
||||
base_url=urllib.parse.urljoin("http://localhost:9003", "api")
|
||||
)
|
||||
a = epc.createAuthorIfNotExistsFor(name="andis", authorMapper="andis")
|
||||
g = epc.createGroupIfNotExistsFor(groupMapper="fet")
|
||||
|
||||
|
||||
def get_ep_sessionid(request):
|
||||
if request.user is None:
|
||||
return "NoUser", None
|
||||
server = SERVER_URL
|
||||
author = epc.createAuthorIfNotExistsFor(name=str(request.user), authorMapper=str(request.user))['authorID']
|
||||
# server = SERVER_URL
|
||||
author = epc.createAuthorIfNotExistsFor(
|
||||
name=str(request.user),
|
||||
authorMapper=str(request.user)
|
||||
)['authorID']
|
||||
expires = datetime.utcnow() + timedelta(
|
||||
hours=3
|
||||
)
|
||||
@@ -32,38 +39,42 @@ def get_ep_sessionid(request):
|
||||
except Exception as e:
|
||||
raise e
|
||||
return None, None
|
||||
|
||||
return result['sessionID'],expires
|
||||
|
||||
return result['sessionID'], expires
|
||||
|
||||
|
||||
def get_pad_link(padID):
|
||||
return urllib.parse.urljoin(SERVER_URL,'p/'+g["groupID"] + '$' + slugify(padID))
|
||||
return urllib.parse.urljoin(SERVER_URL, 'p/' + g["groupID"] + '$' + slugify(padID))
|
||||
|
||||
|
||||
def add_ep_to_response(request, response):
|
||||
if request.user is None:
|
||||
return response
|
||||
padID=id
|
||||
# padID = id
|
||||
server = SERVER_URL
|
||||
#padLink = urllib.parse.urljoin(SERVER_URL , 'p/' + g["groupID"] + '$' + padID)
|
||||
author = epc.createAuthorIfNotExistsFor(name=str(request.user), authorMapper=str(request.user))['authorID']
|
||||
expires = datetime.utcnow() + timedelta(
|
||||
hours=3
|
||||
)
|
||||
# padLink = urllib.parse.urljoin(SERVER_URL , 'p/' + g["groupID"] + '$' + padID)
|
||||
author = epc.createAuthorIfNotExistsFor(
|
||||
name=str(request.user),
|
||||
authorMapper=str(request.user)
|
||||
)['authorID']
|
||||
expires = datetime.utcnow() + timedelta(hours=3)
|
||||
|
||||
try:
|
||||
result = epclient.createSession(
|
||||
result = epc.createSession(
|
||||
groupID=str(g['groupID']),
|
||||
authorID=str(author),
|
||||
validUntil=str(int(expires.timestamp()))
|
||||
)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return response
|
||||
|
||||
|
||||
if ('padSessionID' in request.COOKIES):
|
||||
epclient.deleteSession(request.COOKIES['sessionID'])
|
||||
# TODO - fix it: epclient.deleteSession(request.COOKIES['sessionID'])
|
||||
response.delete_cookie('sessionID', server.hostname)
|
||||
response.delete_cookie('padSessionID')
|
||||
|
||||
response=response.set_cookie(
|
||||
response = response.set_cookie(
|
||||
'sessionID',
|
||||
value=result['sessionID'],
|
||||
expires=expires,
|
||||
|
||||
@@ -32,7 +32,7 @@ LOGGING = {
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
#SESSION_COOKIE_DOMAIN = ".2020.fet.at"
|
||||
# SESSION_COOKIE_DOMAIN = ".2020.fet.at"
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||
@@ -64,7 +64,6 @@ INSTALLED_APPS = [
|
||||
'rest_framework',
|
||||
'django_filters',
|
||||
'django_static_jquery_ui',
|
||||
'accounts.apps.AccountsConfig',
|
||||
'posts.apps.PostsConfig',
|
||||
'members.apps.MembersConfig',
|
||||
'documents.apps.DocumentsConfig',
|
||||
|
||||
@@ -35,6 +35,4 @@ urlpatterns = [
|
||||
path('ckeditor/', include('ckeditor_uploader.urls')),
|
||||
path('api/', include(router.urls)),
|
||||
path('members/', include('members.urls'), name='members'),
|
||||
path('accounts/', include('accounts.urls')),
|
||||
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
@@ -39,26 +39,6 @@ def index(request, slug=None, filter=None):
|
||||
return render(request, 'members/index.html', context)
|
||||
|
||||
|
||||
|
||||
def show_job(request, slug=None):
|
||||
job=Job.objects.get(slug=slug)
|
||||
return render(request, 'members/show_job.html', {"job": job})
|
||||
|
||||
def show_member(request, slug=None):
|
||||
member=Member.objects.get()
|
||||
return render(request, 'members/show_member.html', {"member": member})
|
||||
|
||||
def list(request, filter=None):
|
||||
"""
|
||||
View for a list of members filtered or not
|
||||
"""
|
||||
if filter is None:
|
||||
members = deque(Member.all_members.all())
|
||||
if filter in Member.role_choices:
|
||||
members=deque(Member.all_members.filter(role=filter).all())
|
||||
|
||||
return render(request, 'members/list.html',{"members": members})
|
||||
|
||||
class MemberViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows users to be viewed or edited.
|
||||
|
||||
@@ -10,7 +10,8 @@ from rest_framework import viewsets
|
||||
# from rest_framework import permissions
|
||||
|
||||
from .models import Post, PostSerializer
|
||||
from documents import add_ep_to_response, get_ep_sessionid, get_pad_link
|
||||
# from documents import add_ep_to_response
|
||||
from documents import get_ep_sessionid, get_pad_link
|
||||
|
||||
from collections import deque
|
||||
|
||||
@@ -44,14 +45,35 @@ def show(request, id=None):
|
||||
"post": p,
|
||||
"next": get_next_dict().get(p.slug, None),
|
||||
"related_posts": p.tags.similar_objects(),
|
||||
"ep_link": get_pad_link(p.slug+"-agenda")
|
||||
"ep_link": get_pad_link(p.slug + "-agenda")
|
||||
}
|
||||
response=render(request, 'posts/show.html', context)
|
||||
response = render(request, 'posts/show.html', context)
|
||||
response.set_cookie("HelloWorld", "TestWert", domain="https://etherpad2.2020.fet.at")
|
||||
<<<<<<< HEAD
|
||||
ep_sessid, expires=get_ep_sessionid(request)
|
||||
response.set_cookie("sessionID",ep_sessid,expires=expires, domain=".2020.fet.at", path="/")
|
||||
#response.set_cookie("express_sid",ep_sessid,expires=expires, domain="https://andis.2020.fet.at",path="/etherpad")
|
||||
#response=add_ep_to_response(request, response )
|
||||
=======
|
||||
ep_sessid, expires = get_ep_sessionid(request)
|
||||
response.set_cookie(
|
||||
"sessionID",
|
||||
ep_sessid,
|
||||
expires=expires,
|
||||
domain=".2020.fet.at",
|
||||
path="/etherpad"
|
||||
)
|
||||
'''
|
||||
response.set_cookie(
|
||||
"express_sid",
|
||||
ep_sessid,
|
||||
expires=expires,
|
||||
domain="https://andis.2020.fet.at",
|
||||
path="/etherpad"
|
||||
)
|
||||
'''
|
||||
# response=add_ep_to_response(request, response )
|
||||
>>>>>>> a9b7ca5faead194ba253fadc59f6f1d83a8e5bc1
|
||||
|
||||
return response
|
||||
|
||||
@@ -59,6 +81,7 @@ def show(request, id=None):
|
||||
# HELPERS #
|
||||
###########
|
||||
|
||||
|
||||
def slug_calc(request):
|
||||
"""
|
||||
Ajax function that is called to calculate a slug from the title
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Login</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous">
|
||||
|
||||
|
||||
<style>
|
||||
body,
|
||||
html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
background: #7abecc !important;
|
||||
}
|
||||
.user_card {
|
||||
width: 350px;
|
||||
margin-top: auto;
|
||||
margin-bottom: auto;
|
||||
background: #74cfbf;
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||
-webkit-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||
-moz-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||
border-radius: 5px;
|
||||
|
||||
}
|
||||
|
||||
.form_container {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
#form-title{
|
||||
color: #fff;
|
||||
|
||||
}
|
||||
|
||||
.login_btn {
|
||||
width: 100%;
|
||||
background: #33ccff !important;
|
||||
color: white !important;
|
||||
}
|
||||
.login_btn:focus {
|
||||
box-shadow: none !important;
|
||||
outline: 0px !important;
|
||||
}
|
||||
.login_container {
|
||||
padding: 0 2rem;
|
||||
}
|
||||
.input-group-text {
|
||||
background: #f7ba5b !important;
|
||||
color: white !important;
|
||||
border: 0 !important;
|
||||
border-radius: 0.25rem 0 0 0.25rem !important;
|
||||
}
|
||||
.input_user,
|
||||
.input_pass:focus {
|
||||
box-shadow: none !important;
|
||||
outline: 0px !important;
|
||||
}
|
||||
|
||||
#messages{
|
||||
background-color: grey;
|
||||
color: #fff;
|
||||
padding: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="container h-100">
|
||||
<div class="d-flex justify-content-center h-100">
|
||||
<div class="user_card">
|
||||
<div class="d-flex justify-content-center">
|
||||
|
||||
|
||||
<h3 id="form-title">LOGIN</h3>
|
||||
</div>
|
||||
<div class="d-flex justify-content-center form_container">
|
||||
<form method="POST" action="">
|
||||
{% csrf_token %}
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text"><i class="fas fa-user"></i></span>
|
||||
</div>
|
||||
|
||||
<input type="text" name="username" placeholder="Username..." class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text"><i class="fas fa-key"></i></span>
|
||||
</div>
|
||||
|
||||
<input type="password" name="password" placeholder="Password..." class="form-control" >
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-center mt-3 login_container">
|
||||
<input class="btn login_btn" type="submit" value="Login">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
{% for message in messages %}
|
||||
<p id="messages">{{message}}</p>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user