from flask import Blueprint, current_app, g, session from flask_restx import Resource, Namespace from flask_restx._http import HTTPStatus from project.app import api from project.authentication.decorators import check_user_token_and_roles auth_bp = Blueprint("auth", __name__) auth_ns = Namespace("auth", description="Endpoints for authentication.") # Parser only for API docs purposes so we show what is expected as input # even though each backend is responsible by parsing the specific input they need # e.g. JWT backend reads from request header, LDAP backend reads username/password from json post_parser = api.parser() post_parser.add_argument("username", required=True, location="json") post_parser.add_argument("password", required=True, location="json") @auth_ns.route("/login") class Login(Resource): @api.response(HTTPStatus.OK, HTTPStatus.OK.phrase) @api.response(HTTPStatus.UNAUTHORIZED, HTTPStatus.UNAUTHORIZED.phrase) @api.expect(post_parser, validate=True, strict=True) def post(self): """ Login user """ response_data = {} for backend in current_app.authenticators: result = backend.authenticate() if result and isinstance(result, dict): response_data.update(result) return response_data
from project.helpers.utility import Utility from project.helpers.response import Response from project.helpers.responseMessages import ResponseMessages from flask import Flask, render_template, redirect, url_for, request from flask_jwt_extended import ( jwt_required, get_jwt_identity ) from project.authentication.backends.decryption import decrypt, encrypt import jwt parser = reqparse.RequestParser() parser.add_argument("user_password") userpassword_bp = Blueprint("user_password", __name__) userpassword_ns = Namespace("user_password", description="Endpoints for users password for encryption column") put_parser = api.parser() put_parser.add_argument("temp_password", required=True, location="json") put_parser.add_argument("user_newpassword", required=True, location="json") put_parser.add_argument("user_confirm_password", required=True, location="json") put_parser.add_argument("id", required=True, location="json") def get_user(id ): user = usersModel.get(id) if not user or user.is_deleted: return None return user @userpassword_ns.route("/") class UserPassword(Resource): __tablename__ = 'users'
parser = reqparse.RequestParser() parser.add_argument("tenant_subscription") tenant_subscription_bp = Blueprint("tenant_subscription", __name__) tenant_subscription_ns = Namespace( "tenant_subscription", description="Endpoints for tenant_subscription") def get_tenant_subscription(self, id): tenant_subscription = TenantSubscriptionModel.get(id) if not tenant_subscription or tenant_subscription.is_deleted: return None return tenant_subscription put_parser = api.parser() put_parser.add_argument("membership_plan_id", required=True, location="json") put_parser.add_argument("tenant_id", required=True, location="json") put_parser.add_argument("status", required=True, location="json") put_parser.add_argument("updated_by", required=True, location="json") @tenant_subscription_ns.route("/<int:id>") class TenantSubscription(Resource): @api.doc(params={"id": "ID of the tenant_subscription to retrieve"}) def get(self, id): tenant_subscription_data = get_tenant_subscription(self, id) tenant_subscription_data.effective_from = Utility.date_month_year( self, tenant_subscription_data.effective_from) tenant_subscription_data.effective_to = Utility.date_month_year( self, tenant_subscription_data.effective_to)