Added basic HS auth.

master
q3k 2013-05-30 22:16:01 +02:00
parent 783b3b8166
commit aab5b5536b
1 changed files with 30 additions and 0 deletions

View File

@ -7,6 +7,7 @@ from flask.ext.principal import Identity
import hashlib
import os
import yaml
import requests
from octoprint.settings import settings
@ -44,6 +45,19 @@ class UserManager(object):
def getAllUsers(self):
return []
class HackerspaceUserManager(UserManager):
"""A user manager for the Warsaw Hackerspace, uses interal apis."""
def __init__(self):
super(HackerspaceUserManager, self).__init__(self)
self.group = settings().get(["accessControl", "group"])
def findUser(self, username=None):
if requests.get("https://capacifier.hackerspace.pl/{}/{}".format(self.group, username)).status_code == 200:
return HackerspaceUser(username)
else
return None
##~~ FilebasedUserManager, takes available users from users.yaml file
class FilebasedUserManager(UserManager):
@ -218,6 +232,22 @@ class User(UserMixin):
def is_admin(self):
return "admin" in self._roles
class HackerspaceUser(User):
def __init__(self, username):
self._username = username
self._active = True
self._roles = ["user"]
if requests.get("https://capacifier.hackerspace.pl/staff/{}".format(username)).status_code == 200:
self._roles.append("admin")
def check_password(self, password):
data = {
"login": self._username,
"password": password,
}
return requests.post("https://auth.hackerspace.pl/", data).status_code == 200
##~~ DummyUser object to use when accessControl is disabled
class DummyUser(User):