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)
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)
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: token = generate_auth_token({ 'admin_id': result['admin_id'], 'password': result['password'], 'is_admin': True if result['role_id'] == 1 else False }) session['admin'] = token session['username'] = result['username'] return ResultDeal( data={ 'token': token, 'routes': result['routes'], 'menus': result['menus'], 'interface': result['interface'], 'info': { 'name': result['nickname'] if result['nickname'] else result['username'], 'user_id': result['admin_id'], 'avatarUrl': result['avatarUrl'], 'key': result['password'] } }) except Exception as e: print e return ResultDeal(msg=e.message, code=-1)
def ModifyAdmin(): params = { 'password': request.form.get('password'), 'nickname': request.form.get('nickname'), 'sex': int(request.form.get('sex')), 'avatarUrl': request.form.get('avatarUrl') } result = AdminModel().ModifyAdminRequest( admin_id=request.form.get('admin_id'), params=params) if type(result).__name__ == 'str': return ResultDeal(msg=result, code=-1) return ResultDeal(data=result)
def CreateAdmin(): params = { 'username': request.form.get('username'), 'password': request.form.get('password'), 'nickname': request.form.get('nickname', ''), 'sex': request.form.get('sex', 1), 'role_id': request.form.get('role_id', 1), 'avatarUrl': request.form.get('avatarUrl', '') } result = AdminModel().CreateAdminRequest(params) if type(result).__name__ == 'str': return ResultDeal(msg=result, code=-1) return ResultDeal(data=result)
def QueryAdminByParam(): params = {} if request.form.get('is_disabled'): params['is_disabled'] = True if request.form.get( 'is_disabled') == 'true' else False 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', None)) if type(result).__name__ == 'str': return ResultDeal(msg=result, code=-1) return ResultDeal(data=result)
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') } 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'] == 'SYS_ADMIN' 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})
def CreateDrop(): result = AdminModel().CreateDropRequest() if type(result).__name__ == 'str': return ResultDeal(msg=result, code=-1) return ResultDeal(data={'username': '******', 'password': '******'})
def LockAdmin(): result = AdminModel().LockAdminRequest( admin_id=request.form.getlist('admin_id'), isLock=True if request.form.get('isLock') == 'true' else False) return ResultDeal(data=result)