def delete_users(data):
    try:
        Users.objects(publicId=data['publicId']).delete()
        response_object = {
            'status': Const.SUCCESS,
            'message': 'User deleted successfully.'
        }
        return response_object, Const.SUCCESS_CODE
    except Exception as e:
        response_object = {'status': Const.FAIL, 'message': e}
        return response_object, Const.FAILURE_CODE
Exemple #2
0
def update_users(data):
    try:
        Users.objects(publicId=data['publicId']).update(**data)
        response_object = {
            'status': Const.SUCCESS,
            'message': Const.USER_UPDATE_SUCCESS
        }
        return response_object, Const.SUCCESS_CODE

    except Exception as e:
        response_object = {
            'status': Const.FAIL,
            'message': e
        }
        return response_object, Const.FAILURE_CODE
Exemple #3
0
def insert_users(data):
    try:
        if data['password'] != data['confirmPassword']:
            response_object = {
                'status': Const.FAIL,
                'message': 'Mismatch password.'
            }
            return response_object, Const.FAILURE_CODE
        del data['confirmPassword']
        data['publicId'] = uuid.uuid4()
        salt = gen_salt()
        data['password'] = hash_password(data['password'], salt)
        data['passwordSalt'] = salt
        Users(**data).save()
        response_object = {
            'status': Const.SUCCESS,
            'message': Const.USER_INSERT_SUCCESS
        }
        return response_object, Const.SUCCESS_CODE
    except Exception as e:
        response_object = {
            'status': Const.FAIL,
            'message': e
        }
        return response_object, Const.FAILURE_CODE
def insert_users(data):
    try:
        if not Users.objects(username=data['username'].upper()):
            data['publicId'] = uuid.uuid4()
            data['username'] = data['username'].upper()
            salt = gen_salt()
            data['password'] = hash_password('optel', salt)
            data['passwordSalt'] = salt
            Users(**data).save()
            response_object = {
                'status': Const.SUCCESS,
                'message': 'User created successfully.'
            }
            return response_object, Const.SUCCESS_CODE
        else:
            response_object = {
                'status': Const.FAIL,
                'message': 'Username already exists.'
            }
            return response_object
    except Exception as e:
        response_object = {'status': Const.FAIL, 'message': e}
        return response_object, Const.FAILURE_CODE
Exemple #5
0
def save_new_user(data):
    user = Users.query.filter_by(email=data['email']).first()
    if not user:
        new_user = Users(public_id=str(uuid.uuid4()),
                         email=data['email'],
                         registered_on=datetime.datetime.utcnow())
        save_changes(new_user)
        response_object = {
            'status': 'success',
            'message': 'Successfully registered.'
        }
        return response_object, 201
    else:
        response_object = {
            'status': 'fail',
            'message': 'User already exists. Please Log in.',
        }
        return response_object, 409
Exemple #6
0
def user_login(data):
    for item in Users.objects(email=data['email']):
        verify = verify_password(data['password'], item['password'].encode('utf-8'),  item['passwordSalt'])
        print(verify)
        if not verify:
            response_object = {
                'status': Const.FAIL,
                'message': 'Incorrect username or password.'
            }
            return response_object, Const.FAILURE_CODE
        token = generate_active_token(str(item['publicId']), item['role'])
        response_object = {
            'status': Const.SUCCESS,
            'token': token,
            'publicId': str(item['publicId']),
            'role': item['role'],
            'message': 'Successfully logged in.'
        }
        return response_object, Const.SUCCESS_CODE
    response_object = {
        'status': Const.FAIL,
        'message': 'Incorrect username or password.'
    }
    return response_object, Const.FAILURE_CODE
def login_user(data):
    for item in Users.objects(username=data['username'].upper()):
        verify = verify_password(data['password'],
                                 item['password'].encode('utf-8'),
                                 item['passwordSalt'])
        if not verify:
            response_object = {
                'status': Const.FAIL,
                'message': 'Incorrect username or password.'
            }
            return response_object
        token = generate_active_token(item['publicId'], item['userType'])
        response_object = {
            'status': Const.SUCCESS,
            'token': token,
            'publicId': str(item['publicId']),
            'message': 'Authentication Success.'
        }
        return response_object
    response_object = {
        'status': Const.FAIL,
        'message': 'Incorrect username or password.'
    }
    return response_object