Ejemplo n.º 1
0
    def add_staff(role, agency_id, staff_id):
        if role == "BR":
            new_broker_staff = BRStaff(staff_id, agency_id)
            new_broker_staff.save()
            # Assign staff role
            staff_role = "BRSTF"
            new_user_role = UserRolePlacement(
                staff_id, Role.fetch_role_by_name(staff_role))
            new_user_role.save()

        elif role == "TA":
            new_ta_staff = TAStaff(staff_id, agency_id)
            new_ta_staff.save()
            # assign staff role
            staff_role = "TASTF"
            new_user_role = UserRolePlacement(
                staff_id, Role.fetch_role_by_name(staff_role))
            new_user_role.save()

        elif role == "IA":
            new_ia_staff = IAStaff(staff_id, agency_id)
            new_ia_staff.save()

            # assign staff role
            staff_role = "IASTF"
            new_user_role = UserRolePlacement(
                staff_id, Role.fetch_role_by_name(staff_role))
            new_user_role.save()
Ejemplo n.º 2
0
    def post(self):
        # get the user details from the request sent by the client
        user_details = user_parser.parse_args()
        # check if the user exists before registering them
        user_db_row = User.get_user_by_email(user_details['email'])
        if user_db_row:
            err_msg = f"{user_details['email']} already exists"
            response_msg = helper.make_rest_fail_response(err_msg)
            return make_response(response_msg, 409)

        # check if user phone number exists
        phone_number = UserProfile.get_profile_by_phone_number(
            user_details["phone"])
        if phone_number:
            err_msg = f"{user_details['phone']} already exists"
            response_msg = helper.make_rest_fail_response(err_msg)
            return make_response(response_msg, 409)

        # save the user authentication details and profile details
        # in their respective database tables
        user_uuid = uuid.uuid4()
        new_user_authentication = User(user_uuid, user_details['email'],
                                       user_details['password'])
        new_user_authentication.save()

        new_user_profile = UserProfile(new_user_authentication.id,
                                       user_details['first_name'],
                                       user_details['last_name'],
                                       user_details['phone'])
        new_user_profile.save()

        new_user_role = UserRolePlacement(
            new_user_authentication.id,
            Role.fetch_role_by_name(user_details['role']))
        new_user_role.save()

        # Account confirmation email generation
        # Save extra user details depending on their role
        role = user_details["role"]
        self.onboard_client(role, new_user_authentication.id, user_details)

        #   Send a confirmation link to the user for account confirmation
        confirmation_code = token_handler.user_account_confirmation_token(
            new_user_authentication.id)
        email_template = helper.generate_confirmation_template(
            application.config['CONFIRMATION_ENDPOINT'], confirmation_code)
        subject = "Your account is inactive, please confirm account or check with your administrator"
        email_text = f"Use this link {application.config['CONFIRMATION_ENDPOINT']}/{confirmation_code}" \
                     f" to confirm your account"

        helper.send_email(user_details['email'], subject, email_template,
                          email_text)

        response_msg = helper.make_rest_success_response(
            "Registration successful, kindly"
            " check your email for confirmation link")
        return make_response(response_msg, 200)
Ejemplo n.º 3
0
 def role_placement(role_id, role):
     new_user_role = UserRolePlacement(role_id,
                                       Role.fetch_role_by_name(role))
     new_user_role.save()