def actionProfileUpdate(request):
    """Update record"""

    json_data = False

    if request.method == 'POST':
        json_data = json.loads(request.body)

    if json_data is False:
        return {'code': 'nodata'}, 404

    from app.account.models import User

    validateResult, validateCode = User.validateProfileUpdateJsonObject(json_data)

    if validateCode != 200:
        return validateResult, validateCode

    try:
        user = User.objects.get(pk=request.user.id)
    except User.DoesNotExist:
        return {'code': 'account/usernofound', 'values': [json_data['email']]}, 404

    #try:
    validateResult, validateCode = user.updateFromJsonObject(json_data)
    if validateCode != 200:
        return validateResult, validateCode

    user.backend = 'django.contrib.auth.backends.ModelBackend'
    user.save()
    #except:
    #    return {'code': 'account/profile/fail/update'}, 404

    return {'code': 'ok', 'data': [user.getUserData()]}
def actionProfileUpdate(request):
    """Update record"""

    json_data = False

    if request.method == 'POST':
        json_data = json.loads(request.body)

    if json_data is False:
        return {'code': 'nodata'}, 404

    from app.account.models import User

    validateResult, validateCode = User.validateProfileUpdateJsonObject(json_data)

    if validateCode != 200:
        return validateResult, validateCode

    try:
        emailField = json_data['email']
        emailField = emailField.lower()
    except KeyError:
        emailField = ''

    if emailField == '':
        return {'code': 'account/noemail'}, 404

    try:
        with open('app/account/fixtures/users.json') as f:
            content = f.read()
            f.close()
    except IOError:
        content = '[]'
    records = json.loads(content)

    user = False

    for record in records:
        if record['email'] == emailField:
            user = record
            try:
                firstname = json_data['firstname']
            except KeyError:
                firstname = ''
            try:
                lastname = json_data['lastname']
            except KeyError:
                lastname = ''
            try:
                username = json_data['username']
            except KeyError:
                username = emailField[:30]

            user['firstname'] = firstname
            user['lastname'] = lastname
            user['username'] = username

    if user == False:
        return {'code': 'account/usernofound', 'values': [emailField]}, 404

    return {'code': 'ok', 'data': [user]}