def getCurrentUser(request):
    res = {}

    if not request.session.session_key:
        res['result'] = 0
        res['message'] = 'No user online.'
    elif request.method == 'GET':
         user_id = request.session['user_id']
         res['result'] = 1
         res['data'] = UserAccess.getUserById(user_id)
    else:
        res['result'] = 0
        res['message'] = 'Wrong request.'

    return HttpResponse(json.dumps(res), content_type="application/json")
Beispiel #2
0
def getCurrentUser(request):
    res = {}

    if not request.session.session_key:
        res['result'] = 0
        res['message'] = 'No user online.'
    elif request.method == 'GET':
        user_id = request.session['user_id']
        res['result'] = 1
        res['data'] = UserAccess.getUserById(user_id)
    else:
        res['result'] = 0
        res['message'] = 'Wrong request.'

    return HttpResponse(json.dumps(res), content_type="application/json")
Beispiel #3
0
def assignProject(request):
    res = {}

    if request.method == 'POST':
        info = json.loads(request.body)
        user = UserAccess.getUserById(info['user_id'])
        if user:
            if info['op'] == 1:
                user['status'] = 1
                user['project_id'] = info['project_id']

                project_user_record = {
                    "id": uuid.uuid1().hex,
                    "project_id": info['project_id'],
                    "user_id": user["id"],
                    "start_time": datetime.now(),
                    "end_time": ""
                }
                ProjectUserRecordAccess.addProjectUserRecord(
                    project_user_record)

            else:
                user['status'] = 0
                user['project_id'] = ''

                user_record_list = ProjectUserRecordAccess.getAllProjectUserRecord(
                )
                for item in user_record_list:
                    if item['user_id'] == user['id'] and item['end_time'] == "":
                        user_record = item
                        user_record['end_time'] = datetime.now()
                        ProjectUserRecordAccess.editProjectUserRecord(
                            user_record)
                        break

            final = UserAccess.editUser(user)
            res['result'] = final['result']
            res['message'] = final['message']
        else:
            res['result'] = 0
            res['message'] = 'The user does not exist!'
    else:
        res['result'] = 0
        res['message'] = 'Wrong request.'

    return HttpResponse(json.dumps(res), content_type="application/json")
Beispiel #4
0
def deleteUser(request):
    res = {}

    if request.method == 'POST':
        info = json.loads(request.body)
        if UserAccess.getUserById(info['id']):
            final = UserAccess.deleteUserById(info['id'])
            res['result'] = final['result']
            res['message'] = final['message']
        else:
            res['result'] = 0
            res['message'] = 'The user does not exist!'
    else:
        res['result'] = 0
        res['message'] = 'Wrong request.'

    return HttpResponse(json.dumps(res), content_type="application/json")
def deleteUser(request):
    res = {}

    if request.method == 'POST':
        info = json.loads(request.body)
        if UserAccess.getUserById(info['id']):
            final = UserAccess.deleteUserById(info['id'])
            res['result'] = final['result']
            res['message'] = final['message']
        else:
            res['result'] = 0
            res['message'] = 'The user does not exist!'
    else:
        res['result'] = 0
        res['message'] = 'Wrong request.'

    return HttpResponse(json.dumps(res), content_type="application/json")
def assignTask(request):
    res = {}

    if request.method == 'POST':
        info = json.loads(request.body)
        vehicle = VehicleAccess.getVehicleById(info['vehicle_id'])
        user = UserAccess.getUserById(vehicle['user_id'])
        if vehicle:
            path = getPath(info['task'])
            if path:
                task = {
                    'origin' : info['task']['origin'],
                    'dest' : info['task']['dest'],
                    'path' : path
                }

                record = {
                    'id' : uuid.uuid1().hex,
                    'vehicle_id' : vehicle['id'],
                    'user_id' : user['id'],
                    'time' : datetime.now(),
                    'task' : task
                }
                TaskRecordAccess.addTaskRecord(record)
                res['result'] = 1
                res['data'] = path

                vehicle['accept'] = 1
                vehicle['task'] = task
                if user['status'] == 2:
                    user['status'] = 3
                    vehicle['status'] = 3
                UserAccess.editUser(user)
                VehicleAccess.editVehicle(vehicle)
            else:
                res['result'] = 0
                res['message'] = 'Can not get the path from baidu map.'
        else:
            res['result'] = 0
            res['message'] = 'The vehicle does not exist!'
    else:
        res['result'] = 0
        res['message'] = 'Wrong request.'

    return HttpResponse(json.dumps(res), content_type="application/json")
def assignProject(request):
    res = {}

    if request.method == 'POST':
        info = json.loads(request.body)
        user = UserAccess.getUserById(info['user_id'])
        if user:
            if info['op'] == 1:
                user['status'] = 1
                user['project_id'] = info['project_id']

                project_user_record = {
                    "id" : uuid.uuid1().hex,
                    "project_id" : info['project_id'],
                    "user_id" : user["id"],
                    "start_time" : datetime.now(),
                    "end_time" : ""
                }
                ProjectUserRecordAccess.addProjectUserRecord(project_user_record)
                
            else:
                user['status'] = 0
                user['project_id'] = ''

                user_record_list = ProjectUserRecordAccess.getAllProjectUserRecord()
                for item in user_record_list:
                    if item['user_id'] == user['id'] and item['end_time'] == "":
                        user_record = item
                        user_record['end_time'] = datetime.now()
                        ProjectUserRecordAccess.editProjectUserRecord(user_record)
                        break


            final = UserAccess.editUser(user)
            res['result'] = final['result']
            res['message'] = final['message']
        else:
            res['result'] = 0
            res['message'] = 'The user does not exist!'
    else:
        res['result'] = 0
        res['message'] = 'Wrong request.'

    return HttpResponse(json.dumps(res), content_type="application/json")
def logout(request):
    res = {}

    if not request.session.session_key:
        res['result'] = 0
        res['message'] = 'The user does not log in'
    elif request.method == 'GET':
        request.session.flush()
        res['result'] = 1
        user = UserAccess.getUserById(request.session['user_id'])
        vehicle = VehicleAccess.getVehicleById(request.session['vehicle_id'])
        user['status'] = 1
        vehicle['status'] = 1
        UserAccess.editUser(user)
        VehicleAccess.editVehicle(vehicle)
    else:
        res['result'] = 0
        res['message'] = 'Wrong request.'

    return HttpResponse(json.dumps(res), content_type="application/json")
Beispiel #9
0
def logout(request):
    res = {}

    if not request.session.session_key:
        res['result'] = 0
        res['message'] = 'The user does not log in'
    elif request.method == 'GET':
        request.session.flush()
        res['result'] = 1
        user = UserAccess.getUserById(request.session['user_id'])
        vehicle = VehicleAccess.getVehicleById(request.session['vehicle_id'])
        user['status'] = 1
        vehicle['status'] = 1
        UserAccess.editUser(user)
        VehicleAccess.editVehicle(vehicle)
    else:
        res['result'] = 0
        res['message'] = 'Wrong request.'

    return HttpResponse(json.dumps(res), content_type="application/json")