Esempio n. 1
0
def create_account(user_info):
    spassword = create_password(user_info.password)
    s = app.helpers.session.get_session()

    if 'is_active' in user_info:
        user_info.is_active = '1'
    else:
        user_info.is_active = '0'

    last_insert_rowid = db.insert('users',
                                  email=user_info.email, name=user_info.name, password=spassword, creator=s.userid, created=int(time.time()), comments=user_info.comments, is_active=user_info.is_active)
    last_user = get_user_by_id(last_insert_rowid)

    # initiate dictionary
    records = {}

    # se last_insert_rowid == True, assume que usuario foi criado com sucesso
    if last_insert_rowid:
        # set response message to OK
        records['Result'] = 'OK'
        records['Record'] = last_user
    else:
        records['Result'] = 'ERROR'
        records['Message'] = 'USUÁRIO NÃO CRIADO!'

    return json.dumps(records)
Esempio n. 2
0
def update_user(user_info):

    s = app.helpers.session.get_session()

    if 'is_active' in user_info:
        user_info.is_active = '1'
    else:
        user_info.is_active = '0'

    #FIXME: mudar para não precisar de updates separados
    if user_info.password:
        result = db.update('users',
                           where='id = $id',
                           vars={'id': user_info.id},
                           name=user_info.name, is_active=user_info.is_active, comments=user_info.comments, password=create_password(user_info.password), email=user_info.email, lastupdated=int(time.time()), lastupdatedby=s.userid)
    else:
        result = db.update('users',
                           where='id = $id',
                           vars={'id': user_info.id},
                           name=user_info.name, is_active=user_info.is_active, comments=user_info.comments, email=user_info.email, lastupdated=int(time.time()), lastupdatedby=s.userid)
    logger.info(result)
    # initiate dictionary
    records = {}

    # se result == True, assume que usuario foi atualizado com sucesso
    if result == 1:
        # set response message to OK
        records['Result'] = 'OK'
    else:
        records['Result'] = 'ERROR'
        records['Message'] = 'Nenhuma informação alterada'

    return json.dumps(records)