Esempio n. 1
0
def ModifyAdmin():
    result = AdminModel().ModifyAdminRequest(
        admin_id=request.form.get('admin_id'), params=request.form)

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    token = session.get('admin')
    info = get_auth_token(token)
    if info['admin_id'] == request.form.get('admin_id'):
        token = generate_auth_token({
            'admin_id':
            result['admin_id'],
            'password':
            result['password'],
            'is_admin':
            True if result['mark'] == default['role_mark'] else False
        })

        session['admin'] = token
        session['username'] = result['username']

        return ResultDeal(data={
            'user': result,
            'token': token,
            'is_self': True
        })

    return ResultDeal(data={'user': result, 'token': None, 'is_self': False})
Esempio n. 2
0
def DelAdmin():
    result = AdminModel().DelAdminRequest(request.form.getlist('admin_id[]'))

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    return ResultDeal(data=result)
Esempio n. 3
0
def CreateAdmin():
    result = AdminModel().CreateAdminRequest(request.form)

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    return ResultDeal(data=result)
Esempio n. 4
0
def DelAdmin():
    result = AdminModel().DelAdminRequest(
        admins=json.loads(request.form.get('admins')))

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    return ResultDeal(data=result)
Esempio n. 5
0
def LockAdmin():
    result = AdminModel().LockAdminRequest(
        admin_id=request.form.getlist('admin_id[]'),
        disable=request.form.get('disable'))

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    return ResultDeal(data=result)
Esempio n. 6
0
def LockAdmin():
    result = AdminModel().LockAdminRequest(
        admin_id=request.form.getlist('admin_id[]'),
        is_disabled=True
        if request.form.get('is_disabled') == 'true' else False)

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    return ResultDeal(data=result)
Esempio n. 7
0
def QueryAdminByParam():
    params = {}
    if request.form.get('disable') != None:
        params['disable'] = request.form.get('disable')
    if request.form.get('role_id'):
        params['role_id'] = request.form.get('role_id')

    result = AdminModel().QueryAdminByParamRequest(
        params=params,
        page=int(request.form.get('page')),
        page_size=int(request.form.get('page_size')),
        order_by=request.form.get('order_by'))

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    return ResultDeal(data=result)
Esempio n. 8
0
def Login():
    # 验证码校验
    captcha = request.form.get('code')
    sesson_captcha = session.get('Captcha')
    if not captcha:
        return ResultDeal(msg=u'请输入验证码', code=-1)

    if not sesson_captcha:
        return ResultDeal(msg=u'请刷新验证码', code=-1)

    if session.get('Captcha').lower() != captcha.lower():
        return ResultDeal(msg=u'验证码不正确', code=-1)

    result = AdminModel().GetAdminRequest(
        username=request.form.get('username'),
        password=request.form.get('password'))

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    try:
        user = result['user']

        token = generate_auth_token({
            'admin_id':
            user['admin_id'],
            'password':
            user['password'],
            'is_admin':
            True if user['mark'] == 'SYS_ADMIN' else False
        })

        session['admin'] = token
        session['username'] = user['username']

        return ResultDeal(
            data={
                'token': token,
                'routes': result['routes'],
                'menus': result['menus'],
                'interface': result['interface'],
                'info': user
            })
    except Exception as e:
        print e
        return ResultDeal(msg=e.message, code=-1)
Esempio n. 9
0
def CreateAdmin():
    params = {
        'username': request.form.get('username'),
        'password': request.form.get('password'),
        'nickname': request.form.get('nickname', ''),
        'email': request.form.get('email', ''),
        'sex': request.form.get('sex', 1),
        'role_id': request.form.get('role_id'),
        'avatarUrl': request.form.get('avatarUrl', '')
    }

    result = AdminModel().CreateAdminRequest(params)

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    return ResultDeal(data=result)
Esempio n. 10
0
def Login():
    # 验证码校验
    captcha = request.form.get('code')
    sesson_captcha = session.get('Captcha')

    if not sesson_captcha:
        return ResultDeal(msg=str('验证码已过期, 请刷新'), code=-1)

    if session.get('Captcha').lower() != captcha.lower():
        return ResultDeal(msg=str('验证码不正确'), code=-1)

    result = AdminModel().GetAdminRequest(
        username=request.form.get('username'),
        password=request.form.get('password'))

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    try:
        user = result['user']
        user['is_admin'] = user['mark'] == default['role_mark']

        token = generate_auth_token({
            'admin_id':
            user['admin_id'],
            'password':
            user['password'],
            'is_admin':
            user['mark'] == default['role_mark']
        })

        session['admin'] = token
        session['username'] = user['username']

        return ResultDeal(
            data={
                'token': token,
                'menus': result['menus'],
                'interface': result['interface'],
                'info': user
            })
    except Exception as e:
        print(e)
        return ResultDeal(msg=e, code=-1)
Esempio n. 11
0
def ModifyAdmin():
    params = {
        'password': request.form.get('password'),
        'nickname': request.form.get('nickname'),
        'email': request.form.get('email', ''),
        'sex': int(request.form.get('sex')),
        'avatarUrl': request.form.get('avatarUrl', ''),
        'role_id': request.form.get('role_id'),
        'is_disabled':
        True if request.form.get('is_disabled') == 'true' else False
    }

    result = AdminModel().ModifyAdminRequest(
        admin_id=request.form.get('admin_id'), params=params)

    if type(result).__name__ == 'str':
        return ResultDeal(msg=result, code=-1)

    token = session.get('admin')
    info = get_auth_token(token)
    if info['admin_id'] == request.form.get('admin_id'):
        token = generate_auth_token({
            'admin_id':
            result['admin_id'],
            'password':
            result['password'],
            'is_admin':
            True if result['mark'] == default['role_mark'] else False
        })

        session['admin'] = token
        session['username'] = result['username']

        return ResultDeal(data={
            'user': result,
            'token': token,
            'is_self': True
        })

    return ResultDeal(data={'user': result, 'token': None, 'is_self': False})