def test_authenticate_correct_user(self): authenticate = UserModel.authenticate('*****@*****.**', 'teste@1234') assert authenticate == UserModel.query.filter_by( email='*****@*****.**').first() authenticate = UserModel.authenticate('*****@*****.**', 'teste@1234') assert authenticate == UserModel.query.filter_by( email='*****@*****.**').first()
def get(self): posted_data = request.get_json() access_level = users.find_one({"username":posted_data["username"]})["access"] if UserModel.authenticate(**posted_data): return UserModel.authenticate(**posted_data) access_token = create_access_token(identity={"username":posted_data["username"], "access level":access_level}, expires_delta= datetime.timedelta(minutes=60)) return ({"access token":access_token, "message":"succesful", "status code":200})
def post(self): data = request.get_json() email = data['email'].strip() password = encrypt(data['password']) user = UserModel.authenticate(email, password) if user: access = create_jwt({ 'id_user': user.id, 'email': user.email, 'first_name': user.first_name, 'last_name': user.last_name, 'active': user.active }) return { 'id_user': user.id, 'email': user.email, 'first_name': user.first_name, 'last_name': user.last_name, 'active': user.active, 'jwt': access }, 200 else: return {'message': 'Invalid credentials'}, 400
def post(self): data = request.get_json() email = data['email'] password = data['password'] if email == '': return {'message': 'Email não informado'}, 401 if password == '': return {'message': 'Senha não informada'}, 401 user = UserModel.authenticate(email, password) if user is not None: token = create_jwt({ 'email': user.email, 'name': user.name, 'role': user.role, 'id': user.id, 'cpf': user.cpf, }) return {'name': user.name, 'token': token} else: return {'message': 'Invalid credentials'}, 401
def post(self): data = request.get_json() email = data['email'].strip() password = encrypt(data['password']) user = UserModel.authenticate(email, password) if user: if user.type_user == 'insured': user_data = InsuredModel.get_by_user_id(user.id) user_data_json = { 'id': user_data.id, 'first_name':user_data.first_name, 'last_name': user_data.last_name, 'cpf':user_data.cpf, } elif user.type_user == 'provider': user_data = ProviderModel.get_by_user_id(user.id) user_data_json = { 'id': user_data.id, 'business_name':user_data.business_name, 'fantasy_name': user_data.fantasy_name, 'cnpj':user_data.cnpj, } else: user_data = CollaboratorModel.get_by_user_id(user.id) user_data_json ={ 'id': user_data.id, 'first_name':user_data.first_name, 'last_name': user_data.last_name, 'registration':user_data.registration, } access = create_jwt({ 'id_insured': user.id, 'email': user.email, 'status': user.status, 'type_user':user.type_user }) return { 'id_insured': user.id, 'email': user.email, 'status': user.status, 'type_user':user.type_user, 'created_date':user.created_date.strftime("%d/%m/%Y"), 'jwt': access, 'user_data':user_data_json }, 200 else: return {'message': 'Invalid credentials'}, 400
def authenticate(facebookId, unused): return UserModel.authenticate(facebookId)
def test_no_authenticate_wrong_password(self): authenticate = UserModel.authenticate('*****@*****.**', 'wrong-pass') assert authenticate is None
def test_no_authenticate_wrong_user(self): authenticate = UserModel.authenticate('wrong_user@wrong_user.com', '1234') assert authenticate is None