# Path: surveilr/models.py
# class Service(RiakObject):
# class User(RiakObject):
# class LogEntry(RiakObject):
#     def pre_save(self):


from webob.dec import wsgify
from webob.exc import HTTPUnauthorized
from surveilr import models
from riakalchemy import NoSuchObjectError
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public
    License along with this program.  If not, see
    <http://www.gnu.org/licenses/>.

    API server auth implementation
"""




def require_auth_middleware_factory(global_config):
    @wsgify.middleware
    def require_auth_middleware(req, app):
        if 'repoze.who.identity' not in req.environ:
            raise HTTPUnauthorized()
        return app
    return require_auth_middleware


class SurveilrAuthPlugin(object):
    def authenticate(self, environ, identity):
        try:
            login = identity['login']
            password = identity['password']
        except KeyError:
            return None

        try:

# Path: surveilr/models.py
# class Service(RiakObject):
# class User(RiakObject):
# class LogEntry(RiakObject):
#     def pre_save(self):


# Path: surveilr/api/server/auth.py
from webob.dec import wsgify
from webob.exc import HTTPUnauthorized
from surveilr import models
from riakalchemy import NoSuchObjectError

    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public
    License along with this program.  If not, see
    <http://www.gnu.org/licenses/>.

    API server auth implementation
"""




def require_auth_middleware_factory(global_config):
    @wsgify.middleware
    def require_auth_middleware(req, app):
        if 'repoze.who.identity' not in req.environ:
            raise HTTPUnauthorized()
        return app
    return require_auth_middleware


class SurveilrAuthPlugin(object):
    def authenticate(self, environ, identity):
        try:
            login = identity['login']
            password = identity['password']
        except KeyError:
            return None

        try:

            user = models.User.get(key=login)