コード例 #1
0
ファイル: endpoint.py プロジェクト: fazalIqubal/track
        return None
    return user

@userpassword_ns.route("/")
class UserPassword(Resource):
    __tablename__ = 'users'
    @api.expect(put_parser)
    @jwt_required
    def put(self):
        """ Update a users with a given id """
        args = put_parser.parse_args()
        temp_password = args["temp_password"]
        user_newpassword = args["user_newpassword"]
        user_confirm_password = args['user_confirm_password']
        id = args['id']
        user = get_user(id)
        
        if temp_password == user.temp_password:
            key = 'abc123'.encode()
            newpassword = encrypt(key, user_newpassword.encode("latin-1") )
            user.encrypted_password = newpassword
            user.temp_password = ''
            user.isemail_verified = True
            user.update()
            return Response.createSuccessResponse(self, user.to_json(), ResponseMessages.update_success, HTTPStatus.CREATED)
        else :
            return Response.createFailResponse( self, ResponseMessages.update_fail, HTTPStatus.BAD_REQUEST),  HTTPStatus.BAD_REQUEST
      

api.add_namespace(userpassword_ns)
コード例 #2
0
ファイル: endpoint.py プロジェクト: fazalIqubal/track
            else:
                tenant.updated_at = None
        return Response.createSuccessResponse(
            self,
            [tenant_subscription.to_json() for tenant_subscription in data],
            ResponseMessages.get_success, HTTPStatus.OK)

    @api.expect(post_parser)
    def post(self):
        args = post_parser.parse_args()
        tenant_id = args["tenant_id"]
        membership_plan_id = args["membership_plan_id"]
        status = args["status"]
        created_by = args["created_by"]

        tenant_subscription = TenantSubscriptionModel(
            effective_from=date.today(),
            tenant_id=tenant_id,
            membership_plan_id=membership_plan_id,
            status=status,
            created_by=created_by,
            created_at=date.today())
        tenant_subscription.save()
        return Response.createSuccessResponse(self,
                                              tenant_subscription.to_json(),
                                              ResponseMessages.create_success,
                                              HTTPStatus.CREATED)


api.add_namespace(tenant_subscription_ns)
コード例 #3
0
                response_data.update(result)
                return response_data
        # if "user" in g:
        #     return response_data
        # return {'User is not available'}, HTTPStatus.UNAUTHORIZED
        return result, HTTPStatus.UNAUTHORIZED


# Only for API docs purposes. Should be parsed on each backend
# if they expect payload
logout_post_parser = api.parser()
logout_post_parser.add_argument("refresh_token",
                                required=False,
                                location="json")


@auth_ns.route("/logout")
class Logout(Resource):
    @api.response(HTTPStatus.OK, HTTPStatus.OK.phrase)
    @api.response(HTTPStatus.UNAUTHORIZED, HTTPStatus.UNAUTHORIZED.phrase)
    @api.expect(logout_post_parser)
    @check_user_token_and_roles([])
    def post(self):
        """ Logout user """
        for backend in current_app.authenticators:
            backend.logout()
        return {}


api.add_namespace(auth_ns)
コード例 #4
0
ファイル: endpoint.py プロジェクト: fazalIqubal/track
            for membership in data:
                membership.created_at = Utility.date_month_year(self, membership.created_at)
                if membership.updated_at != None:
                    membership.updated_at = Utility.date_month_year(self, membership.updated_at)
                else:
                    membership.updated_at = None
            return Response.createSuccessResponse(self, [membership_plan.to_json() for membership_plan in data], ResponseMessages.get_success, HTTPStatus.OK)
        except:
            return Response.createFailResponse(self, ResponseMessages.get_fail, HTTPStatus.NOT_FOUND)
    @api.expect(post_parser)

    @jwt_required
    def post(self):
        args = post_parser.parse_args()
        name = args["name"]
        description =  args["description"]
        price = args["price"]
        project_limit = args["project_limit"]
        user_limit = args["user_limit"]
        plan_duration = args["plan_duration"]
        created_by = get_jwt_identity()

        try:
            membership_plan = MembershipPlanModel( name = name, description = description, price = price, project_limit = project_limit, user_limit = user_limit, plan_duration = plan_duration, created_by = created_by, created_at = date.today())
            membership_plan.save()
            return Response.createSuccessResponse(self, membership_plan.to_json(), ResponseMessages.create_success, HTTPStatus.CREATED)
        except:
            return Response.createFailResponse(self, ResponseMessages.get_fail, HTTPStatus.NOT_FOUND)
 
api.add_namespace(membership_plan_ns)
コード例 #5
0
ファイル: endpoint.py プロジェクト: fazalIqubal/track
                             company_size=company_size,
                             primary_interest=primary_interest,
                             created_by=created_by)
        try:
            tenant.save()
            return Response.createSuccessResponse(
                self, tenant.to_json(), ResponseMessages.create_success,
                HTTPStatus.CREATED)
        except:
            return Response.createFailResponse(self,
                                               ResponseMessages.create_fail,
                                               HTTPStatus.BAD_REQUEST)


@tenant_ns.route("/<string:includeDeleted>")
class TenantList(Resource):
    @api.doc(params={"includeDeleted": "To include isDeleted"})
    @jwt_required
    def get(self, includeDeleted):
        """ Get all tenants. """
        try:
            return Response.createSuccessResponse(self, [
                tenant.to_json() for tenant in TenantModel.all(includeDeleted)
            ], ResponseMessages.get_success, HTTPStatus.OK)
        except:
            return Response.createFailResponse(self, ResponseMessages.get_fail,
                                               HTTPStatus.NOT_FOUND)


api.add_namespace(tenant_ns)
コード例 #6
0
from flask_jwt_extended import (
    jwt_refresh_token_required,
    get_jwt_identity,
    create_access_token,
)
from flask_restx import Resource, Namespace
from flask_restx._http import HTTPStatus

from project.app import api

jwt_bp = Blueprint("jwt", __name__)
jwt_ns = Namespace("jwt", description="Endpoints for JWT token management.")


@jwt_ns.route("/refresh_token")
class RefreshToken(Resource):
    @api.response(HTTPStatus.OK, HTTPStatus.OK.phrase)
    @api.response(HTTPStatus.UNAUTHORIZED, HTTPStatus.UNAUTHORIZED.phrase)
    @jwt_refresh_token_required
    def post(self):
        """ Generate new access token """
        current_user = get_jwt_identity()
        ret = {
            "access_token": create_access_token(identity=current_user,
                                                fresh=False)
        }
        return ret, 200


api.add_namespace(jwt_ns)
コード例 #7
0
ファイル: endpoint.py プロジェクト: fazalIqubal/track
        emailAlreadyexist = usersModel.get_email(self, email)
        try:
            if emailAlreadyexist is None:
                data = {'email': email, 'password': temp}
                template = EmailTemplate.tenantEmailVerification(data)
                EmailHandler.send_email(email, "email verification", template)
                users = usersModel(first_name=first_name,
                                   last_name=last_name,
                                   address=address,
                                   username=username,
                                   temp_password=temp,
                                   mobile=mobile,
                                   email=email,
                                   created_by=created_by)
                users.save()
                return Response.createSuccessResponse(
                    self, users.to_json(), ResponseMessages.create_success,
                    HTTPStatus.CREATED)
            else:
                return Response.createFailResponse(
                    self, ResponseMessages.create_fail,
                    HTTPStatus.BAD_REQUEST), HTTPStatus.BAD_REQUEST
        except:
            return Response.createFailResponse(
                self, ResponseMessages.create_fail,
                HTTPStatus.BAD_REQUEST), HTTPStatus.BAD_REQUEST


api.add_namespace(users_ns)
コード例 #8
0
post_parser = api.parser()
post_parser.add_argument("email", required=True, location="json")


@tenantemail_ns.route("/email_verify")
class TenantEmailCheck(Resource):
    __tablename__ = 'tenant'

    @api.expect(post_parser)
    def post(self):
        """ check the tenant email. """
        args = post_parser.parse_args()
        email = args["email"]
        password = "******"
        data = {'email': email, 'password': password}

        try:
            template = EmailTemplate.tenantEmailVerification(data)
            EmailHandler.send_email(email, "email verification", template)
            return Response.createSuccessResponse(
                self, data, ResponseMessages.email_sent,
                HTTPStatus.CREATED), HTTPStatus.OK
        except:
            return Response.createFailResponse(
                self, ResponseMessages.email_fail,
                HTTPStatus.BAD_REQUEST), HTTPStatus.BAD_REQUEST


api.add_namespace(tenantemail_ns)