Esempio n. 1
0
def create_user(request):

    LOG.info("****** start to create user *****")
    LOG.info("******* data is ******" + str(request.data))
    LOG.info("****** username is ******" + str(request.data['username']))
    LOG.info("****** password is ******" + str(request.data['password1']))
    user = User()
    LOG.info("ccccccccccccc")
    form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user)
    LOG.info("ddddddddddddd")
    if not form.is_valid():
        LOG.info("form is not valid")
        return Response({"success": False, "msg": _("Data is not valid")})

    user = form.save()



    #update start
    if settings.TRI_ENABLED and request.data['is_system_user'] == 'true':

        LOG.info("******** I am systemuser  ***************")
        #user = User.objects.create_superuser(username=username, email=email, password=password1)
        UserProxy.grant_system_user(user)
        LOG.info("fffffffffff")

        #return Response({"success": True,
        #                 "msg": _("User is created successfully!")})


    if settings.TRI_ENABLED and request.data['is_safety_user'] == 'true':

        LOG.info("******** I am safetyuser  ***************")
        #user = User.objects.create_superuser(username=username, email=email, password=password1)
        LOG.info("******** SUPERUSER CREATE SUCCESS **********")
        UserProxy.grant_safety_user(user)
        LOG.info("fffffffffff")

        #return Response({"success": True,
        #                 "msg": _("User is created successfully!")})


    if settings.TRI_ENABLED and request.data['is_audit_user'] == 'true':

        LOG.info("******** I am audituser  ***************")
        #user = User.objects.create_superuser(username=username, email=email, password=password1)
        LOG.info("******** SUPERUSER CREATE SUCCESS **********")
        UserProxy.grant_audit_user(user)
        LOG.info("fffffffffff")

        #return Response({"success": True,
        #                 "msg": _("User is created successfully!")})


    # If workflow is disabled, then only resrouce user can be created,
    # otherwise admin can create resource user and workflow approver user.
    if not settings.WORKFLOW_ENABLED:
        tenant_id = request.data['tenant']
        LOG.info("tennat_id is " + str(tenant_id))
        password = request.data['password1']
        link_user_to_dc_task.delay(user, DataCenter.get_default(), tenant_id, password)
    else:

        if 'is_resource_user' in request.data and \
                request.data['is_resource_user'] == 'true':
            tenant_id = request.data['tenant']
            link_user_to_dc_task(user, DataCenter.get_default(), tenant_id, password)

        if 'is_approver' in request.data and \
                request.data['is_approver'] == 'true':
            UserProxy.grant_workflow_approve(user)

    return Response({"success": True,
                     "msg": _("User is created successfully!")})
Esempio n. 2
0
def create_user(request):

    LOG.info("****** start to create user *****")
    LOG.info("******* data is ******" + str(request.data))
    LOG.info("****** username is ******" + str(request.data['username']))
    LOG.info("****** password is ******" + str(request.data['password1']))
    user = User()
    LOG.info("ccccccccccccc")
    form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user)
    LOG.info("ddddddddddddd")
    if not form.is_valid():
        LOG.info("form is not valid")
        return Response({"success": False, "msg": _("Data is not valid")})

    user = form.save()

    #update start
    if settings.TRI_ENABLED and request.data['is_system_user'] == 'true':

        LOG.info("******** I am systemuser  ***************")
        #user = User.objects.create_superuser(username=username, email=email, password=password1)
        UserProxy.grant_system_user(user)
        LOG.info("fffffffffff")

        #return Response({"success": True,
        #                 "msg": _("User is created successfully!")})

    if settings.TRI_ENABLED and request.data['is_safety_user'] == 'true':

        LOG.info("******** I am safetyuser  ***************")
        #user = User.objects.create_superuser(username=username, email=email, password=password1)
        LOG.info("******** SUPERUSER CREATE SUCCESS **********")
        UserProxy.grant_safety_user(user)
        LOG.info("fffffffffff")

        #return Response({"success": True,
        #                 "msg": _("User is created successfully!")})

    if settings.TRI_ENABLED and request.data['is_audit_user'] == 'true':

        LOG.info("******** I am audituser  ***************")
        #user = User.objects.create_superuser(username=username, email=email, password=password1)
        LOG.info("******** SUPERUSER CREATE SUCCESS **********")
        UserProxy.grant_audit_user(user)
        LOG.info("fffffffffff")

        #return Response({"success": True,
        #                 "msg": _("User is created successfully!")})

    # If workflow is disabled, then only resrouce user can be created,
    # otherwise admin can create resource user and workflow approver user.
    if not settings.WORKFLOW_ENABLED:
        tenant_id = request.data['tenant']
        LOG.info("tennat_id is " + str(tenant_id))
        password = request.data['password1']
        link_user_to_dc_task.delay(user, DataCenter.get_default(), tenant_id,
                                   password)
    else:

        if 'is_resource_user' in request.data and \
                request.data['is_resource_user'] == 'true':
            tenant_id = request.data['tenant']
            link_user_to_dc_task(user, DataCenter.get_default(), tenant_id,
                                 password)

        if 'is_approver' in request.data and \
                request.data['is_approver'] == 'true':
            UserProxy.grant_workflow_approve(user)

    return Response({
        "success": True,
        "msg": _("User is created successfully!")
    })
Esempio n. 3
0
def create_user(request):

    LOG.info("****** start to create user *****")
    LOG.info("******* data is ******" + str(request.data))
    LOG.info("****** username is ******" + str(request.data['username']))
    posted_username = request.data['username']
    if str(posted_username) in ['neutron', 'cinder', 'keystone', 'nova', 'glance', 'heat', 'swift', 'admin', 'ceilometer']:     
        return Response({"success": False,
                     "msg": _("Service user must not be created.")})
    LOG.info("****** password is ******" + str(request.data['password1']))
    user = User()
    LOG.info("ccccccccccccc")
    form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user)
    LOG.info("ddddddddddddd")
    if not form.is_valid():
        LOG.info("form is not valid")
        return Response({"success": False, "msg": _("Data is not valid")})

    user = form.save()



    #update start
    if settings.TRI_ENABLED and request.data['is_system_user'] == 'true':

        LOG.info("******** I am systemuser  ***************")
        #user = User.objects.create_superuser(username=username, email=email, password=password1)
        UserProxy.grant_system_user(user)
        LOG.info("fffffffffff")

        #return Response({"success": True,
        #                 "msg": _("User is created successfully!")})


    if settings.TRI_ENABLED and request.data['is_safety_user'] == 'true':

        LOG.info("******** I am safetyuser  ***************")
        #user = User.objects.create_superuser(username=username, email=email, password=password1)
        LOG.info("******** SUPERUSER CREATE SUCCESS **********")
        UserProxy.grant_safety_user(user)
        LOG.info("fffffffffff")

        #return Response({"success": True,
        #                 "msg": _("User is created successfully!")})


    if settings.TRI_ENABLED and request.data['is_audit_user'] == 'true':

        LOG.info("******** I am audituser  ***************")
        #user = User.objects.create_superuser(username=username, email=email, password=password1)
        LOG.info("******** SUPERUSER CREATE SUCCESS **********")
        UserProxy.grant_audit_user(user)
        LOG.info("fffffffffff")

        #return Response({"success": True,
        #                 "msg": _("User is created successfully!")})


    # If workflow is disabled, then only resrouce user can be created,
    # otherwise admin can create resource user and workflow approver user.
    if not settings.WORKFLOW_ENABLED:
        tenant_id = request.data['tenant']
        LOG.info("tennat_id is " + str(tenant_id))
        password = request.data['password1']
        link_user_to_dc_task.delay(user, DataCenter.get_default(), tenant_id, password)


        try:
            operation = Operation(user=request.user, udc_id=request.session['UDC_ID'], resource='用户', resource_id=1, resource_name='用户',action="创建用户", result=1)
            operation.save()
        except Exception as e:
            LOG.info(str(e))
    else:

        if 'is_resource_user' in request.data and \
                request.data['is_resource_user'] == 'true':
            tenant_id = request.data['tenant']
            link_user_to_dc_task(user, DataCenter.get_default(), tenant_id, password)

        if 'is_approver' in request.data and \
                request.data['is_approver'] == 'true':
            UserProxy.grant_workflow_approve(user)

    return Response({"success": True,
                     "msg": _("User is created successfully!")})