Ejemplo n.º 1
0
def login(request):
    """Login to the service."""
    errors = {}
    data = {}
    if request.method == 'POST':
        data = yield from request.post()
        email = data.get('email')
        password = data.get('password')
        try:
            operator = Operator.get(Operator.email == email)
            if operator.check_password(password):
                yield from app.ps.session.login(request, operator.pk)
                return HTTPFound('/')
            errors['password'] = '******'
        except Operator.DoesNotExist:
            errors['email'] = 'Wrong email'

    return app.ps.jinja2.render('pages/login.html', data=data, errors=errors, request=request)
Ejemplo n.º 2
0
def remove_superuser(email: str):
    """Remove superuser."""
    Operator.delete().where(Operator.email == email).execute()
    app.logger.info('Operator %s has been deleted.', email)
Ejemplo n.º 3
0
def load_operator(pk):
    """Load current user from saved session PK."""
    try:
        return Operator.get(Operator.id == pk)
    except Operator.DoesNotExist:
        return None