コード例 #1
0
def search_user(filter_user: FilterUser):
    if filter_user.email == '' and filter_user.fiscal_code == '' and filter_user.phone == '':
        return None, 'At least one in fiscal code, email or phone number is required'

    if filter_user.phone != None and filter_user.phone != '' and len(
            filter_user.phone) < 9:
        return None, 'Invalid phone number'

    if filter_user.fiscal_code != None and filter_user.fiscal_code != '' and len(
            filter_user.fiscal_code) != 16:
        return None, 'Invalid fiscal code'

    #if filter_user.firstname != "":
    #    q = q.filter(func.lower(User.firstname) == func.lower(filter_user.firstname))
    #if filter_user.lastname != "":
    #    q = q.filter(func.lower(User.lastname) == func.lower(filter_user.lastname))
    if filter_user.email != None and filter_user.email != '':
        user = User.get(email=filter_user.email)
    if filter_user.phone != None and filter_user.phone != '':
        user = User.get(phone=filter_user.phone)
    if filter_user.fiscal_code != None and filter_user.fiscal_code != '':
        user = User.get(fiscal_code=filter_user.fiscal_code)

    if user == None:
        return None, 'No user found'
    else:
        return user, 'OK'
コード例 #2
0
 def tearDown(self):
     with self.app.test_request_context():
         self.assertIsNotNone(self.operator)
         Restaurant.delete(self.operator.restaurant_id)
         User.delete(self.operator.id)
         for res_id in self.reservation_ids:
             Reservation.delete_customer_reservation(res_id)
 def setUp(self) -> None:
     self.app = create_app()
     # create some test user
     self.user_id = User.create(**user_data,
                                fiscal_code="aaaaaaaaaaabb",
                                phone=str(
                                    random.randint(1111111111, 9999999999)),
                                password="******")
     self.user = User.get(id=self.user_id)
 def test_get(self):
     with self.app.test_request_context():
         all = User.all()
         self.assertIsNotNone(all)
         u = User.filter("and_(User.id > 1, User.id < 3)")
         self.assertIsNotNone(u)
         u = User.filter("and_(User.id < -1, User.id < -3)")
         self.assertIsNone(u)
         u = User.get(id=-1)
         self.assertIsNone(u)
コード例 #5
0
def loader(user_id):
    if not currently_logged_in.get(str(user_id)):
        user = User.get(id=user_id)
        if user:
            user.is_authenticated = True
        currently_logged_in[str(user_id)] = user or AnonymousUser()
    return currently_logged_in.get(str(user_id))
コード例 #6
0
    def create(email,
               firstname,
               lastname,
               password,
               dateofbirth,
               name,
               lat,
               lon,
               phone,
               extra_info=None):
        """Creates a new restaurant by the given parameters and returns the User object.
        If the User creation cannot be performed the db is reverted to a consistent state.

        Raises:
            Exception: if the creation cannot be performed

        Returns:
            User: the restaurant operator
        """
        body_restaurant = {
            'name': str(name),
            'lat': float(lat),
            'lon': float(lon),
            'phone': str(phone),
            'extra_info': str(extra_info)
        }

        req = safe_post(f"{Restaurant.BASE_URL}/restaurants/new",
                        json=body_restaurant)
        if req.status_code != 201:
            raise Exception(str(req))

        restaurant_id = req.json()
        ret = User.create(email=email, firstname=firstname, \
                lastname=lastname, password=password, dateofbirth=dateofbirth, \
                restaurant_id=restaurant_id)
        logging.warning(f"{ret}")
        if not ret:
            # user creation didn't go well, reverting restaurant db
            Restaurant.delete(restaurant_id)
            return None

        return User.get(id=ret)
    def setUpClass(cls):
        cls.user_list = [{
            'email': "*****@*****.**",
            'firstname': "user1",
            'lastname': "user1",
            'fiscal_code': "Fake1",
            'password': "******",
            'dateofbirth': datetime(year=1996, month=1, day=2)
        }, {
            'email': "*****@*****.**",
            'firstname': "user2",
            'lastname': "user2",
            'fiscal_code': "Fake2",
            'is_admin': True,
            'password': "******",
            'dateofbirth': datetime(year=1996, month=1, day=3)
        }, {
            'email': "*****@*****.**",
            'firstname': "user3",
            'lastname': "user3",
            'fiscal_code': "Fake3",
            'password': "******",
            'restaurant_id': 2,
            'dateofbirth': datetime(year=1996, month=1, day=4)
        }, {
            'email': "*****@*****.**",
            'firstname': "user4",
            'lastname': "user4",
            'fiscal_code': "Fake4",
            'password': "******",
            'dateofbirth': datetime(year=1996, month=1, day=5)
        }]

        cls.app = create_app()

        for user in cls.user_list:
            User.create(**user)

        for endpoint, endpoint_func in test_endpoints.items():
            cls.app.add_url_rule(f"/{endpoint}", endpoint, endpoint_func)
def edit_user(user_id):
    if current_user.id != int(user_id):
        return render_template("error.html",
                               error_message="You aren't supposed to be here!")

    form = UserProfileEditForm(obj=User.get(id=int(user_id)))
    if request.method == 'POST':
        try:
            if not form.validate_on_submit:
                raise FormValidationError("Can't validate the form")
            edit_user_data(int(user_id), form)
            return redirect('/users/edit/' + user_id)
        except GoOutSafeError:
            return render_template("useredit.html", form=form)
        except Exception as e:
            return render_template("error.html", error_message=str(e))
    return render_template("useredit.html", form=form)
コード例 #9
0
def home(page: int):
    reservations, more = Reservation.get_paged_reservations(
        restaurant_id=current_user.restaurant_id, page=page)
    users = []
    for reservation in reservations:
        user = User.get(id=reservation.user_id)
        users.append(user)
    res = zip(reservations, users)
    if not reservations and page > 1:
        return "", 404
    else:
        return render_template("reservations.html",
                               reservations=res,
                               current_page=page,
                               morepages=more,
                               customers=Reservation.get_seated_customers(
                                   restaurant_id=current_user.restaurant_id),
                               today=False)
def create_user():
    form = UserForm()
    if request.method == 'POST':
        try:
            if not form.validate_on_submit:
                raise FormValidationError("Can't validate the form")
            dateofbirth = datetime(form.dateofbirth.data.year,
                                   form.dateofbirth.data.month,
                                   form.dateofbirth.data.day)
            id = User.create(email=form.email.data, \
                firstname=form.firstname.data, lastname=form.lastname.data, \
                password=form.password.data, fiscal_code=form.fiscal_code.data, \
                phone=str(form.phone.data), dateofbirth=dateofbirth)
            login()
            return redirect('/')
        except FormValidationError:
            return render_template('create_user.html', form=form)
        except Exception as e:
            return render_template("error.html", error_message=str(e))

    return render_template('create_user.html', form=form)
コード例 #11
0
def mark_user(user_id: int):
    """ Mark a user as positive.
    Args:
        userid (int): Id of the customer
    Returns:
        str: '' in case of success, a error message string in case of failure.
    """
    user = User.get(id=user_id)
    user_dict = None
    if user == None:
        message = 'Error! Unable to mark the user. User not found'
    elif user.is_positive == False:
        user.is_positive = True
        user.reported_positive_date = datetime.now()
        user.submit()
        message = ''

        requests.get(
            f"http://{os.environ.get('GOS_NOTIFICATION')}/notifications/contact_tracing/{user_id}"
        )
    else:
        message = 'You\'ve already marked this user as positive!'

    return message, user
 def tearDown(self) -> None:
     with self.app.test_request_context():
         User.delete(self.user_id)
 def tearDown(self) -> None:
     User.delete(self.user_id)
 def tearDown(self) -> None:
     print(
         f"Deleting operator with id {self.operator.id} and r-id {self.operator.restaurant_id}"
     )
     Restaurant.delete(self.operator.restaurant_id)
     User.delete(self.operator.id)
def _users():
    users = User.all()
    return render_template("users.html", users=users)
    def setUp(self) -> None:

        self.app = create_app()
        with self.app.test_request_context():
            self.user_id = User.create(**user_data, fiscal_code="aaaaaaaaaaaaa", phone=str(random.randint(1111111111, 9999999999)), password="******")
            self.assertIsNotNone(self.user_id)
 def test_create(self):
     with self.app.test_request_context():
         u = User.get(id=self.user_id)
         self.assertIsNotNone(u)