Ejemplo n.º 1
0
def tenant_create():
    from application.tenant_app import tenant_app
    requestObj = request.get_json()
    fields = request.args.get('fields')
    needed = ['name', 'remark', 'activated', 'namespace']
    query_list = [
        'name', 'logo', 'remark', 'resources', 'activated', 'namespace'
    ]
    requestObj = filter(query_list=query_list, updateObj=requestObj)
    for i in needed:
        if i not in requestObj.keys():
            return raise_status(400, '信息有缺失')
    try:
        TENANT.objects.get({'name': requestObj['name'], 'delete': False})
        return raise_status(400, '租户名已存在')
    except TENANT.DoesNotExist:
        if not requestObj.get('resources'):
            requestObj['resources'] = {}
        if 'logo' not in requestObj.keys():
            requestObj['logo'] = None
        try:
            tenant = tenant_app(requestObj=requestObj).tenant_insert()
            re = tenant_app(fields=fields).get_return_by_fields(tenant=tenant)
            return jsonify(re)
        except Exception as e:
            logging.error('Request Error: {}\nStack: {}\n'.format(
                e, traceback.format_exc()))
            return raise_status(400, '租户创建失败')
Ejemplo n.º 2
0
def project_change(projectId):
    from application.project_app import project_app
    from model import PROJECT
    from bson import ObjectId

    try:
        projectId = ObjectId(projectId)
        project_app().projectId_check(projectId=projectId)
    except PROJECT.DoesNotExist:
        return jsonify({'error': raise_status(400, 'projectIdError')})
    except Exception as e:
        logging.error('Request Error: {}\nStack: {}\n'.format(
            e, traceback.format_exc()))
        return jsonify({'error': raise_status(400, 'ObjectIdError')})
    requestObj = {'_id': projectId}
    updateObj = request.json
    query_list = [
        'creator', 'title', 'description', 'requirement', 'timeConsume',
        'material', 'reference', 'image', 'base', 'spec', 'tag'
    ]
    updateObj = filter(query_list=query_list, updateObj=updateObj)
    if updateObj.get('id'):
        del updateObj['id']
    try:
        if updateObj.get('base') and updateObj.get('base') != projectId:
            updateObj['base'] = ObjectId(updateObj['base'])
            project_app().project_reference_check(reference=updateObj['base'])
    except PROJECT.DoesNotExist:
        return jsonify({'error': raise_status(400, 'referenceError')})
    try:
        project_app(requestObj=requestObj,
                    updateObj=request.json).project_update_set()
        project = project_app(requestObj=requestObj).project_find_one()
    except Exception as e:
        logging.error('Request Error: {}\nStack: {}\n'.format(
            e, traceback.format_exc()))
        return '后台异常', 500
    if project._id == project.base:
        baseId = None
    else:
        baseId = str(project.base._id)
    returnObj = {
        'id': str(project._id),
        'creator': str(project.creator),
        'title': project.title,
        'description': project.description,
        'requirement': project.requirement,
        'material': project.material,
        'reference': project.reference,
        'tag': project.tag.name,
        'labs': project.labs,
        'timeConsume': project.timeConsume,
        'image': project.image,
        'base': baseId,
        'spec': project.spec,
        'createdAt': project.createdAt,
        'updatedAt': project.updatedAt
    }
    return jsonify(returnObj)
Ejemplo n.º 3
0
def tenant_update_partly(tenant_id):
    from application.tenant_app import tenant_app
    try:
        TENANT.objects.get({'_id': ObjectId(tenant_id), 'delete': False})
    except TENANT.DoesNotExist:
        return raise_status(400, '无效的租户id')
    requestObj = {'_id': tenant_id}
    updateObj = request.get_json()
    fields = request.args.get('fields')
    query_list = [
        'name', 'logo', 'remark', 'resources', 'activated', 'namespace'
    ]
    updateObj = filter(query_list=query_list, updateObj=updateObj)
    tenant_app(requestObj=requestObj, updateObj=updateObj).tenant_update_set()
    tenant = tenant_app(requestObj=requestObj,
                        collection='tenant').tenant_find_one()
    re = tenant_app(fields=fields).get_return_by_fields(tenant=tenant)
    return jsonify(re)
Ejemplo n.º 4
0
def tenant_custom_change(tenant_id):
    from application.tenant_app import unfold_custom
    try:
        CUSTOM.objects.get({'tenant': ObjectId(tenant_id), 'delete': False})
    except CUSTOM.DoesNotExist:
        return '请先创建定制数据', 400
    query_list = [
        'name', 'logo', 'background', 'description', 'characteristic',
        'introduction', 'remark', 'tags', 'connect'
    ]
    updateObj = filter(query_list=query_list, updateObj=request.json)
    updateObj['updatedAt'] = datetime.now()
    CUSTOM.objects.raw({
        'tenant': ObjectId(tenant_id),
        'delete': False
    }).update({'$set': updateObj})
    Model = CUSTOM.objects.get({
        'tenant': ObjectId(tenant_id),
        'delete': False
    })
    custom = unfold_custom(Model=Model, embed=request.args.get('embed'))
    return jsonify(custom)
Ejemplo n.º 5
0
def tenant_custom_create(tenant_id):
    from application.tenant_app import unfold_custom
    try:
        TENANT.objects.get({'_id': ObjectId(tenant_id), 'delete': False})
    except TENANT.DoesNotExist:
        return '无效的租户', 400
    query_list = [
        'name', 'logo', 'background', 'description', 'characteristic',
        'introduction', 'remark', 'tags', 'connect'
    ]
    insertObj = filter(query_list=query_list, updateObj=request.json)
    try:
        check = CUSTOM.objects.get({
            'tenant': ObjectId(tenant_id),
            'delete': False
        })
        # 若该租户已有定制数据,则替换为新的定制数据,因此数据库中一个租户应该只有一套定制数据
        insertObj['updatedAt'] = datetime.now()
        CUSTOM.objects.raw({
            '_id': check._id,
            'delete': False
        }).update({'$set': insertObj})
        Model = CUSTOM.objects.get({'_id': check._id, 'delete': False})
    except CUSTOM.DoesNotExist:
        Model = CUSTOM(name=insertObj.get('name'),
                       logo=insertObj.get('logo'),
                       background=insertObj.get('background'),
                       description=insertObj.get('description'),
                       characteristic=insertObj.get('characteristic'),
                       introduction=insertObj.get('introduction'),
                       remark=insertObj.get('remark'),
                       tags=insertObj.get('tags'),
                       connect=insertObj.get('connect'),
                       tenant=ObjectId(tenant_id),
                       createdAt=datetime.now(),
                       updatedAt=datetime.now(),
                       delete=False).save()
    custom = unfold_custom(Model=Model, embed=request.args.get('embed'))
    return jsonify(custom)
Ejemplo n.º 6
0
def project_create():
    from application.project_app import project_app
    from model import PROJECT
    requestObj = request.json
    try:
        requestObj['creator'] = ObjectId(requestObj['creator'])
        requestObj['tag'] = ObjectId(requestObj['tag'])
        git_list = requestObj['githuburl'].split('/')
        git_account = git_list[3] + '/'
        if '.git' in git_list[4]:
            repo = git_list[4][:-4] + '/'
        else:
            repo = git_list[4] + '/'
        url = 'https://raw.githubusercontent.com/' + git_account + repo + 'master/index.json'
        try:
            r = requests.get(url=url)
            labs = r.json()['labs']
        except Exception as e:
            logging.error('Request Error: {}\nStack: {}\n'.format(
                e, traceback.format_exc()))
            return raise_status(400, '获取元数据失败')
        query_list = [
            'creator', 'title', 'description', 'requirement', 'timeConsume',
            'material', 'reference', 'image', 'base', 'spec', 'tag'
        ]
        requestObj = filter(query_list=query_list, updateObj=requestObj)
        if project_app(requestObj={
                'title': requestObj['title']
        }).project_check():
            return raise_status(400, 'project标题重复')
        if not requestObj.get('base'):
            requestObj['base'] = None
        else:
            requestObj['base'] = ObjectId(requestObj['base'])
            try:
                PROJECT.objects.get({
                    '_id': requestObj['base'],
                    'delete': False
                })
            except PROJECT.DoesNotExist:
                return raise_status(400, '无效的引用信息')
        try:
            project_model = project_app(requestObj=requestObj).project_create()
        except Exception as e:
            logging.error('Request Error: {}\nStack: {}\n'.format(
                e, traceback.format_exc()))
            return raise_status(500, '后台异常')
        lab_list = []
        for lab in labs:
            index = str(labs.index(
                lab)) if labs.index(lab) >= 10 else '0' + str(labs.index(lab))
            key_list = list(lab.keys())
            value_list = list(lab.values())
            lab_list.append({
                'id': str(project_model._id) + index,
                'filename': key_list[0],
                'name': value_list[0]
            })
        try:
            project_app(requestObj={
                '_id': project_model._id
            },
                        updateObj={
                            'labs': lab_list
                        }).project_update_set()
        except Exception as e:
            logging.error('Request Error: {}\nStack: {}\n'.format(
                e, traceback.format_exc()))
            return raise_status(500, '后台异常')
        if project_model.base is None:
            base = None
        else:
            if request.args.get('embed'):
                if project_model.base.base is None:
                    base_reference = None
                else:
                    base_reference = str(project_model.base.base._id)
                base = {
                    'id': str(project_model.base._id),
                    'creator': str(project_model.base.creator),
                    'description': project_model.base.description,
                    'title': project_model.base.title,
                    'requirement': project_model.base.requirement,
                    'material': project_model.base.material,
                    'timeConsume': project_model.base.timeConsume,
                    'tag': project_model.base.tag.name,
                    'reference': project_model.base.reference,
                    'labs': project_model.base.labs,
                    'image': project_model.base.image,
                    'base': base_reference,
                    'spec': project_model.base.spec,
                    'createdAt': project_model.base.createdAt,
                    'updatedAt': project_model.base.updatedAt
                }
            else:
                base = str(project_model.base._id)
        data = {
            'id': str(project_model._id),
            'creator': str(project_model.creator),
            'title': project_model.title,
            'description': project_model.description,
            'requirement': project_model.requirement,
            'material': project_model.material,
            'timeConsume': project_model.timeConsume,
            'tag': project_model.tag.name,
            'labs': lab_list,
            'reference': project_model.reference,
            'image': project_model.image,
            'base': base,
            'spec': project_model.spec,
            'createdAt': project_model.createdAt,
            'updatedAt': project_model.updatedAt
        }
    except Exception as e:
        logging.error('Request Error: {}\nStack: {}\n'.format(
            e, traceback.format_exc()))
        return raise_status(500, '后台异常')
    return jsonify(data)
Ejemplo n.º 7
0
        group_con = auth.read_group_list()
        lock_con = auth.read_user_lock_list()
        force_pass_ch_con = auth.read_force_pass_ch_list()

        for user in group_con.keys():
            grp = ""
            if 'grp_' + hashlib.md5(user).hexdigest() in form:
                grp = str(form.getfirst(hashlib.md5(user).hexdigest()))
            if grp != "":
                sys.stderr.write(str({user: grp}) + "\n")
                group_con.update({user: grp})

            lock_tmp = 0
            if 'lock_' + hashlib.md5(user).hexdigest() in form:
                lock_tmp = auth.filter(
                    str(form.getfirst('lock_' +
                                      hashlib.md5(user).hexdigest())))
            lock_con.update({user: lock_tmp})
            sys.stderr.write(str({user: lock_tmp}) + "\n")

            fpc_tmp = 0
            if 'fpc_' + hashlib.md5(user).hexdigest() in form:
                fpc_tmp = auth.filter(
                    str(form.getfirst('fpc_' + hashlib.md5(user).hexdigest())))
            force_pass_ch_con.update({user: fpc_tmp})
            sys.stderr.write(str({user: fpc_tmp}) + "\n")

        auth.reg_user_list(group_con)
        auth.update_user_lock_list(lock_con)
        auth.update_force_pass_ch_list(force_pass_ch_con)
Ejemplo n.º 8
0
            exit()

        print_html("パスワード変更を受理しました。<p>Emailでの通知をお待ちください。")


if __name__ == '__main__':

    # crate table aws.user_reg_table (status text,email text,code text);
    # Extract form values
    form = cgi.FieldStorage()
    regcode = ""
    passwd = ""
    addr = ""
    # Accept code and Reject code
    if 'regcode' in form:
        regcode = auth.filter(str(form.getfirst('regcode')))
    # Passsword
    if 'passwd' in form:
        passwd = auth.filter(str(form.getfirst('passwd')))
    # Email address
    if 'addr' in form:
        addr_temp = str(form.getfirst('addr'))
        if email_validator(addr_temp) == 1:
            addr = addr_temp

    # print_err(regcode + " / " + passwd + " / " + addr)

    #
    if regcode == "" and addr != "":
        delete_allcode(addr)
        reg_request(addr)
Ejemplo n.º 9
0
# Config
config = ConfigParser.RawConfigParser()
config.read('config')

if config.has_option('all', 'http_or_https'):
    http_or_https = config.get('all', 'http_or_https')
else:
    http_or_https = "http"

#--------------
# Form value
form = cgi.FieldStorage()
if 'userid' in form:
    if 'passwd' in form:
        user_id = auth.filter(str(form.getfirst('userid')))
        passwd = str(form.getfirst('passwd'))
        user_id_md5 = hashlib.md5(user_id).hexdigest()
        passwd_sha = auth.password_hash(user_id, passwd)

        cursor.execute(
            "select user_id_md5 from errortable where user_id_md5 = '" +
            user_id_md5 + "';")
        summary = cursor.fetchall()
        error_retry = len(summary) + 1

        if error_retry > 5:
            msg = '<p style="color: red;font-weight: bold;">5回以上パスワードの入力に失敗しましたのでロックしました</p>'
            sys.stderr.write("Login Error :" + user_id + " / " +
                             str(error_retry) + " more attempts.")
            sql = "update usertable set lock=1 where md5(user_id)='" + user_id_md5 + "';"