aboutsummaryrefslogtreecommitdiff
blob: 6383c49c90cdde03614022ab7f773452b4e348b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python

from django.contrib.auth import authenticate, login

from okupy.common.ssh import ssh_handler
from okupy.common.test_helpers import set_request
from okupy.crypto.ciphers import sessionrefcipher
from okupy.otp import init_otp


ssh_handlers = {}


@ssh_handler
def auth(session_id, key):
    try:
        session = sessionrefcipher.decrypt(session_id)
    except ValueError:
        return None

    request = set_request('/')

    user = authenticate(ssh_key=key)
    if user and user.is_active:
        login(request, user)
        init_otp(request)
        session.update(request.session)
        session.save()
        return 'Authenticated.'
    return None