Exemplo n.º 1
0
	def post(self):

		manage = ManageUser()
		strategy = LoginUserStrategy()
		try:
			tokens = manage.login(strategy, request.json)

		except InvalidParametersError as e:
			return Utils.response(status=e.status, data=e.errors, message="Invalid parameters")
		
		except AuthenticationError as e:
			return Utils.response(status=e.status, data=e.errors, message="Invalid credentials")

		return Utils.response_auth(tokens["token_id"], tokens["refresh_token"])
Exemplo n.º 2
0
	def post(self):

		manage = ManageUser()
		strategy = SignupAdminStrategy()
		try:
			admin = manage.signup(strategy, request.json)
			data = AdminCreateSchema().dumps(admin)
			
		except InvalidParametersError as e:
			return Utils.response(status=e.status, data=e.errors, message="Invalid parameters")

		except UserExistsError as e:
			return Utils.response(status=e.status, data=e.errors, message="Parameter must be unique")
		
		return Utils.response(status=201, data=json.loads(data), message="Request succesfull")
Exemplo n.º 3
0
    def wrapper(*args, **kwars):

        token = request.headers.get("Authorization")
        role = Utils.request_role()

        try:
            if not token or token.split(" ")[0] != "Bearer":
                raise InvalidTokenError(token, "Token must be a bearer token",
                                        "Invalid token")

            token_decode = Auth.token_decode(token.split(" ")[1])
            session_id = token_decode["token"]
            exists = Auth.session_exists(session_id, role)

            if not exists:
                raise InvalidTokenError(
                    token, "User does not have an active session",
                    "Invalid token")

        except InvalidTokenError as e:
            return Utils.response(status=e.status,
                                  message="Invalid token",
                                  data=e.errors)

        return f(*args, **kwars)
Exemplo n.º 4
0
        def wrapper(*args, **kwars):

            token = request.headers.get("REFRESH_TOKEN")

            try:
                if not token or token.split(" ")[0] != "Bearer":
                    raise InvalidTokenError(token,
                                            "Token must be a bearer token",
                                            "Invalid token")

                exists = Auth.refresh_token_exists(token.split(" ")[1], role)

                if not exists:
                    raise InvalidTokenError(token, "Invalid refresh token",
                                            "Invalid token")

            except InvalidTokenError as e:
                return Utils.response(status=e.status,
                                      message="Invalid token",
                                      data=e.errors)

            return f(*args, **kwars)
Exemplo n.º 5
0
	def get(self):

		token = request.headers.get("Authorization").split(" ")[-1]
		Auth.delete_session(token)

		return Utils.response(message="Request succesfull")