Repository: CiviWiki/OpenCiviWiki

Issue:
Restore SessionAuthenticationMiddleware
We aim to move away from having a heavy JavaScript front-end, preferring instead to use Django templates (and sprinkles of JS where needed). This means we can use SessionAuthenticationMiddleware.

This will also require restoring the default authentication classes in `settings.py`


Discussion:
Hi, can I try to solve this issue? This is my first time contributing to an open source project so I was wondering if I can ask questions here :)
Thank you in advance!
Sure @yutytuty. I will assign you to this issue.
I'm having an issue installing the dependencies. I solved the first one by changing pyscopg2 to pyscopg-binary and now it's showing this.
![Screenshot from 2021-05-23 03-50-06](https://user-images.githubusercontent.com/49990984/119252393-fe7d6600-bb79-11eb-9953-747ca1872769.png)

Hi,
I guess I know how to fix this. Can I work on this ?
I can't seem to get the dependencies working. Can you remove me from this issue @brylie 
@yutytuty we will try to fix the Dockerfile ASAP. Sorry for the difficulties.
@yutytuty I have fixed the Dockerfile so that it includes all necessary dependencies. Can you please verify that the project will run on your computer via Docker? I.e. run the following command in the base directory (where we keep docker-compose.yml):

```
docker-compose up
```
Hi @brylie, I can try to assist with this issue if it still needs to be fixed. Please let me know. Thanks!
Thanks, @CJZ-14! I'll assign you to the task. Please open a pull request with your changes when you start development. That way, I can help out along the way.
Hey, @brylie I would like to work on this issue if it's still open.
Thanks, @vishalda! I'll assign you to the task :smiley: 
Hey @brylie,
I have changed default authentication classes to 
`DEFAULT_AUTHENTICATION_CLASSES = ("rest_framework.authentication.SessionAuthentication",)`
 and uncommented the SessionAuthenticationMiddleware in MIDDLEWARE inside settings.py file, but I get following error on running the server.
 
 `Traceback (most recent call last):
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/utils/module_loading.py", line 20, in import_string
    return getattr(module, class_name)
AttributeError: module 'django.contrib.auth.middleware' has no attribute 'SessionAuthenticationMiddleware'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 45, in get_internal_wsgi_application
    return import_string(app_path)
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/vishal/Projects/OpenCiviWiki/project/core/wsgi.py", line 13, in <module>
    application = get_wsgi_application()
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 127, in __init__
    self.load_middleware()
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/core/handlers/base.py", line 40, in load_middleware
    middleware = import_string(middleware_path)
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/utils/module_loading.py", line 22, in import_string
    raise ImportError('Module "%s" does not define a "%s" attribute/class' % (
ImportError: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 138, in inner_run
    handler = self.get_handler(*args, **options)
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 65, in get_handler
    return get_internal_wsgi_application()
  File "/home/vishal/Projects/OpenCiviWiki/env/lib/python3.8/site-packages/django/core/servers/basehttp.py", line 47, in get_internal_wsgi_application
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application 'core.wsgi.application' could not be loaded; Error importing module.`
This project is now using Django 3.x. The middleware class names have changed. Please refer to the Django 3 [User Authentication documentation](https://docs.djangoproject.com/en/3.2/topics/auth/#installation) for the correct middleware class names :smiley: 
@brylie, I have changed middleware to `django.contrib.sessions.middleware.SessionMiddleware` and changed default authentication classes as mentioned above. Is there anything to change?
I think that is all that is needed. Please ensure that you can create a user and then log in via the web interface. We may need some development work related to user registration/login UX.
@brylie I am able to create and log in the user, so I'll open a PR for this issue. I would like to work on development related to user registration/login UX.

Resolving patch:
diff --git a/project/core/settings.py b/project/core/settings.py
--- a/project/core/settings.py
+++ b/project/core/settings.py
@@ -148,7 +148,7 @@
 # Django REST API Settings
 DEFAULT_RENDERER_CLASSES = ("rest_framework.renderers.JSONRenderer",)
 
-DEFAULT_AUTHENTICATION_CLASSES = ("rest_framework.authentication.BasicAuthentication",)
+DEFAULT_AUTHENTICATION_CLASSES = ("rest_framework.authentication.SessionAuthentication",)
 
 if DEBUG:
     # Browsable HTML - Enabled only in Debug mode (dev)


Test patch: