def resetpassword_user(request, userid):
    """
    This function will reset the password for the existing user
    :param userid:
    :param request: request django object
    :return: json object
    """

    obj = None

    try:
        if request.method == PUT_REQUEST:

            loggedin_user_details = _TokenValidation.validate_token(request)

            if loggedin_user_details:
                request_payload = _RequestValidation().validate_request(
                    request, [USERNAME_KEY, USERPASSWORD_KEY])
                obj = UserPasswordReset(loggedin_user_details, request_payload)
                return obj.reset_user_password()

        log_debug(METHOD_NOT_ALLOWED)
        return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED},
                            status=HTTP_405_METHOD_NOT_ALLOWED)
    except jwt.ExpiredSignatureError:
        token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1]
        return JsonResponse({MESSAGE_KEY: "Token Expired"},
                            status=HTTP_401_UNAUTHORIZED)
    except Exception as e:
        return error_instance(e)

    finally:
        if obj:
            del obj
def get_lbt_external_targets(request):
    """
    :param request: request django object
    :return: json response
    """
    obj = None
    external = None

    try:
        if request.method == GET_REQUEST:
            loggedin_external_details = _TokenValidation.validate_token(
                request)

            r_name = loggedin_external_details['role']
            names = ['superadmin', 'admin', 'operator']
            if r_name in names:
                if loggedin_external_details:
                    obj = lbt_external_targets(external)
                    return obj.get_externl_targets()
            else:
                return JsonResponse({MESSAGE_KEY: "Bad request"},
                                    status=HTTP_400_BAD_REQUEST)
        log_debug(METHOD_NOT_ALLOWED)
        return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED},
                            status=HTTP_405_METHOD_NOT_ALLOWED)
    except jwt.ExpiredSignatureError:
        token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1]
        return JsonResponse({MESSAGE_KEY: "Token Expired"},
                            status=HTTP_401_UNAUTHORIZED)
    except Exception as e:
        return error_instance(e)

    finally:
        if obj:
            del obj
Exemplo n.º 3
0
def get_user_list(request, username):
    """
    This function will help to get all the users
    :param request: request django object
    :param username : for particular username
    :return: json object
    """

    obj = None
    try:
        if request.method == GET_REQUEST:

            loggedin_user_details = _TokenValidation.validate_token(request)

            if loggedin_user_details:
                obj = GetUserList(username, loggedin_user_details)
                return obj.getuser_list()

        log_debug(METHOD_NOT_ALLOWED)
        return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED)
    except jwt.ExpiredSignatureError:
        token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1]
        return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED)
    except Exception as e:
        return error_instance(e)

    finally:
        if obj:
            del obj
Exemplo n.º 4
0
def get_equipment_level_data(request,
                             unit_name=None,
                             console_name=None,
                             equipment_name=None):
    """
    This function will return the equipment level overview
    :param unit_name: unit name
    :param console_name: Console name
    :param equipment_name: equipment name
    :param request: request django object
    :return: json response
    """
    obj = None

    try:

        if InputValidation.df[
            (InputValidation.df.unit_name == unit_name)
                & (InputValidation.df.console_name == console_name) &
            (InputValidation.df.equipment_tag_name == equipment_name)].empty:
            return JsonResponse(
                {
                    MESSAGE_KEY:
                    "This {} or {} or {} is not registered with us !".format(
                        unit_name, console_name, equipment_name)
                },
                safe=False,
                status=HTTP_404_NOT_FOUND)
    except Exception as e:
        log_error("Exception due to : %s" + str(e))
        return JsonResponse({MESSAGE_KEY: EXCEPTION_CAUSE.format(str(e))},
                            safe=False,
                            status=HTTP_500_INTERNAL_SERVER_ERROR)

    try:
        if request.method == GET_REQUEST:
            jwt_value = _TokenValidation.validate_token(request)
            if jwt_value:
                obj = EquipmentLevelFeatures(unit_name, console_name,
                                             equipment_name)
                return obj.get_values()
            else:
                return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"},
                                    status=HTTP_403_FORBIDDEN)
        log_debug(METHOD_NOT_ALLOWED)
        return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED},
                            status=HTTP_405_METHOD_NOT_ALLOWED)
    except jwt.ExpiredSignatureError:
        token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1]
        return JsonResponse({MESSAGE_KEY: "Token Expired"},
                            status=HTTP_401_UNAUTHORIZED)

    except Exception as e:
        return error_instance(e)

    finally:
        if obj:
            del obj
Exemplo n.º 5
0
def get_lbt_update_external_targets(request):
    """
    This function will update the existing user
    :param request: request django object
    :return: jsonobject
    """

    obj = query_params = None

    try:

        query_params = {
            EQUIPMENT: request.GET[EQUIPMENT],
            TAG_NAME_REQUEST: request.GET[TAG_NAME_REQUEST]
        }

    except:
        pass

    try:
        if request.method == PUT_REQUEST:

            loggedin_external_details = _TokenValidation.validate_token(
                request)

            r_name = loggedin_external_details['role']
            names = ['superadmin', 'admin']
            if r_name in names:
                if loggedin_external_details:

                    request_payload = _RequestValidation().validate_request(
                        request, [COMMENT_NAME])

                    obj = lbt_update_external_targets(query_params,
                                                      request_payload)

                    return obj.update_external_targets()
            else:
                return JsonResponse({MESSAGE_KEY: "Bad request"},
                                    status=HTTP_400_BAD_REQUEST)
        log_debug(METHOD_NOT_ALLOWED)
        return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED},
                            status=HTTP_405_METHOD_NOT_ALLOWED)
    except jwt.ExpiredSignatureError:
        token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1]
        return JsonResponse({MESSAGE_KEY: "Token Expired"},
                            status=HTTP_401_UNAUTHORIZED)

    except Exception as e:
        return error_instance(e)

    finally:
        if obj:
            del obj
Exemplo n.º 6
0
def create_user(request):
    """
    This function will crete a new user
    :param request: request django object
    :return: json object
    """

    obj = None

    try:
        if request.method == POST_REQUEST:
            jwt_value = _TokenValidation().validate_token(request)

            loggedin_user_details = _TokenValidation.validate_token(request)
            r_name = loggedin_user_details['role']
            names = ['superadmin', 'admin']
            if r_name in names:
                if loggedin_user_details:
                    request_payload = _RequestValidation().validate_request(
                        request, [
                            USERFIRSTNAME_KEY, USERMIDDLENAME_KEY,
                            USERLASTNAME_KEY, USEREMAIL_KEY, USERPASSWORD_KEY,
                            GENDER_KEY, AGE_KEY, PHONE_KEY, ADDRESS_KEY,
                            STATUS_KEY, ROLE_ID
                        ])
                    if jwt_value:
                        obj = CreateUser(loggedin_user_details,
                                         request_payload)
                        return obj.add_user()
                    else:
                        return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"},
                                            status=HTTP_403_FORBIDDEN)
            else:
                return JsonResponse({MESSAGE_KEY: "Bad request"},
                                    status=HTTP_400_BAD_REQUEST)

        log_debug(METHOD_NOT_ALLOWED)
        return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED},
                            status=HTTP_405_METHOD_NOT_ALLOWED)
    except jwt.ExpiredSignatureError:
        token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1]
        return JsonResponse({MESSAGE_KEY: "Token Expired"},
                            status=HTTP_401_UNAUTHORIZED)
    except Exception as e:
        return error_instance(e)

    finally:
        if obj:
            del obj
Exemplo n.º 7
0
def delete_user(request):
    """
    This function will delete the existing user
    :param request: request django object
    :param username : username that need to be deleted
    :return: json object
    """
    obj = None

    try:
        if request.method == DELETE_REQUEST:
            # jwt_value = _TokenValidation().validate_token(request)
            loggedin_user_details = _TokenValidation.validate_token(request)
            r_name = loggedin_user_details['role']
            names = ['superadmin', 'admin']
            if r_name in names:
                if loggedin_user_details:
                    request_payload = _RequestValidation().validate_request(
                        request, [USEREMAIL_KEY])
                    obj = DeleteUser(loggedin_user_details, request_payload)
                    return obj.delete_user()
            else:
                return JsonResponse({MESSAGE_KEY: "Bad request"},
                                    status=HTTP_400_BAD_REQUEST)

        log_debug(METHOD_NOT_ALLOWED)
        return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED},
                            status=HTTP_405_METHOD_NOT_ALLOWED)
    except jwt.ExpiredSignatureError:
        token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1]
        return JsonResponse({MESSAGE_KEY: "Token Expired"},
                            status=HTTP_401_UNAUTHORIZED)
    except Exception as e:
        return error_instance(e)

    finally:
        if obj:
            del obj