def decorated_function(*args, **kwargs): basic_auth = request.authorization if not basic_auth: return response_auth_failed() g.user = auth.authenticate(basic_auth.username, basic_auth.password) if not g.user: return response_auth_failed() return f(*args, **kwargs)
def login(username, password): if not username or not password: raise Fault("unknown_data", "Username and password are required!") user = auth.authenticate(username, password) if not user: raise Fault("invalid_user", "Invalid username/password, please try again.") else: auth.login_user(user) return session["user_pk"]