示例#1
0
文件: views.py 项目: jiachenyu/kaka
def updateShenQingStatus(args):
    sQingId = args.get('ShenQingId', -1)
    sQing = ShenQing.query.get(sQingId)
    status = args.get('Status')
    if sQing:
        sQing.statusCode = status
        db.session.merge(sQing)
        db.session.commit()
        user = User.query.get(sQing.userId)
        machine = Machine.query.get(sQing.machineId)
        pushContent = {
            'Action': 'updateShenQingStatus',
            'Status': status,
            'Machine': machine.toJson()
        }
        pushMessageToSingle([user.pushToken],
                            TransmissionTemplateDemo(json.dumps(pushContent)))
        return jsonify({
            'Status': 'Success',
            'StatusCode': 0,
            'Msg': '操作成功!'
        }), 200
    else:
        return jsonify({
            'Status': 'Success',
            'StatusCode': -1,
            'Msg': '操作失败,申请ShenQingId={}不存在!'.format(sQingId)
        }), 400
示例#2
0
def login(args):
    passWord = args['Password']
    registerType = args['RegisterType']
    phone = args['Phone']
    email = args['Email']
    if registerType == 0 and not phone:
        return jsonify({'Status': 'Failed', 'StatusCode': -1, 'Msg': "Phone不能为空!"}), 400
    if registerType == 1 and not email:
        return jsonify({'Status': 'Failed', 'StatusCode': -1, 'Msg': "Email不能为空!"}), 400
    if registerType == 0:
        user = User.query.filter_by(phone=phone).first()
    else:
        user = User.query.filter_by(email=email).first()
    
    if not user:
        return jsonify({'Status': 'Failed', 'StatusCode': -1, 'Msg': '输入的Phone或Email不存在!'}), 400
    oldPushToken = user.pushToken if user else ''
    if user.checkPassWord(passWord):
        user.token = user.get_auth_token()
        user.pushToken = request.json.get('PushToken', '')
        db.session.merge(user)
        db.session.commit()
        userJson = user.toJson()
        userJson.pop('passWord', None),

        if oldPushToken != user.pushToken:
            pushContent = {'Phone': phone, 'Action': 're-loggin', 'Msg': u'user change phone to re-loggin'}
            pushMessageToSingle([oldPushToken], TransmissionTemplateDemo( json.dumps(pushContent) ))

        return jsonify({'Status': 'Success', 'StatusCode': 0, 'Msg': '登录成功!', 'User': userJson}), 200
    else:
        return jsonify({'Status': 'Failed', 'StatusCode': -1, 'Msg': '密码错误'}), 400 
示例#3
0
def applyPermission(args):
    userId = args.get('UserId', '')
    phone = args.get('Phone', '')
    user = User.getUserByIdOrPhoneOrMail(id=userId, phone=phone)
    applyDetail = args.get('ApplyDetail')
    macAddress = applyDetail.get('Mac', '')
    startTime = applyDetail.get('StartTime', '') if applyDetail.get(
        'StartTime', '') else None
    endTime = applyDetail.get('EndTime', '') if applyDetail.get('EndTime',
                                                                '') else None
    money = applyDetail.get('Money', 0.0)
    machine = Machine.query.filter_by(macAddress=macAddress).first()
    if not machine:
        return jsonify({
            'Status': 'Failed',
            'StatusCode': -1,
            'Msg': "MacAddress {} does't exist".format(macAddress)
        }), 400

    needPermission = applyDetail.get('Permission')
    reason = applyDetail.get('Reason')
    shenQing = ShenQing(user.id,
                        machine.id,
                        reason=reason,
                        needPermission=needPermission,
                        startTime=startTime,
                        endTime=endTime,
                        money=money)
    db.session.add(shenQing)
    db.session.commit()

    managerIds = [
        element.userId
        for element in QuanXian.query.filter_by(machineId=machine.id)
        if element.permission in [QuanXian.SuperAdmin, QuanXian.Admin]
    ]
    tokenList = filter(lambda x: len(x) > 0,
                       [User.query.get(id).pushToken for id in managerIds])
    logger.info("managerIds = {}\ntokens ={}".format(managerIds, tokenList))

    pushContent = request.get_json()
    pushContent.pop('Token', None)
    pushContent['UserName'] = user.userName
    pushContent['Phone'] = user.phone
    pushContent['Action'] = 'applyPermission'
    pushContent['ShenQingId'] = shenQing.id
    pushMessageToSingle(tokenList,
                        TransmissionTemplateDemo(json.dumps(pushContent)))

    return jsonify({
        'Status': 'Success',
        'StatusCode': 0,
        'Msg': '申请成功!',
        'ApplyDetail': shenQing.toJson()
    }), 200
示例#4
0
文件: views.py 项目: jiachenyu/kaka
def addUserPermission(args):
    userList = request.get_json().get("UserList")
    userId = userList.get('UserId', None)
    phone = userList.get('Phone', None)
    user = User.getUserByIdOrPhoneOrMail(userId, phone)
    if not user:
        if phone:
            return jsonify({
                'Status': 'Failed',
                'StatusCode': -1,
                'Msg': "User phone={} does't exist".format(phone)
            }), 400
        if userId:
            return jsonify({
                'Status': 'Failed',
                'StatusCode': -1,
                'Msg': "User id={} does't exist".format(userId)
            }), 400

    macAddress = userList.get('Mac', '')
    machine = Machine.getMachineByMac(macAddress)
    if not machine:
        return jsonify({
            'Status': 'Failed',
            'StatusCode': -1,
            'Msg': "MacAddress {} does't exist".format(macAddress)
        }), 400

    permisson = userList.get('Permission')
    startTime = userList.get('StartTime', None)
    endTime = userList.get('EndTime', None)
    money = userList.get('Money', 0.0)

    quanXian = QuanXian(user.id,
                        machine.id,
                        permission=permisson,
                        startTime=startTime,
                        endTime=endTime,
                        money=money)
    db.session.merge(quanXian)
    db.session.commit()

    pushContent = {
        'Action': 'addUserPermission',
        'Permission': permisson,
        'Mac': macAddress,
        'StartTime': startTime,
        'EndTime': endTime,
        'Money': money
    }
    pushMessageToSingle([user.pushToken],
                        TransmissionTemplateDemo(json.dumps(pushContent)))

    return jsonify({'Status': 'Success', 'StatusCode': 0, 'Msg': '操作成功!'}), 200
示例#5
0
文件: views.py 项目: jiachenyu/kaka
def updateUserPermission(args):
    userPermissonList = request.get_json().get("UserPermissionList")
    userId = userPermissonList.get('UserId', None)
    phone = userPermissonList.get('Phone', None)
    user = User.getUserByIdOrPhoneOrMail(userId, phone)
    if not user:
        if phone:
            return jsonify({
                'Status': 'Failed',
                'StatusCode': -1,
                'Msg': "User phone={} does't exist".format(phone)
            }), 400
        if userId:
            return jsonify({
                'Status': 'Failed',
                'StatusCode': -1,
                'Msg': "User id={} does't exist".format(userId)
            }), 400

    macAddress = userPermissonList.get('Mac', '')
    machine = Machine.getMachineByMac(macAddress)
    if not machine:
        return jsonify({
            'Status': 'Failed',
            'StatusCode': -1,
            'Msg': "MacAddress {} does't exist".format(macAddress)
        }), 400
    permission = userPermissonList.get('Permission')
    startTime = userPermissonList.get('StartTime', None)
    endTime = userPermissonList.get('EndTime', None)
    money = userPermissonList.get('Money', -1)

    quanXian = QuanXian.query.filter_by(
        userId=user.id, machineId=machine.id).order_by('id desc').first()
    quanXian.permission = permission
    if not quanXian:
        return jsonify({
            'Status':
            'Failed',
            'StatusCode':
            -1,
            'Msg':
            "User {} don't use machine {}".format(user.id, macAddress)
        }), 400
    if money != -1:
        quanXian.money = money
    if startTime != None:
        quanXian.startTime = startTime
    if endTime != None:
        quanXian.endTime = endTime

    db.session.merge(quanXian)
    db.session.commit()

    pushContent = {
        'Action': 'updateUserPermission',
        'Permission': permission,
        'Mac': macAddress,
        'Money': money,
        'StartTime': startTime,
        'EndTime': endTime
    }
    pushMessageToSingle([user.pushToken],
                        TransmissionTemplateDemo(json.dumps(pushContent)))

    return jsonify({'Status': 'Success', 'StatusCode': 0, 'Msg': '操作成功!'}), 200