def search_customer():
    """Method that the health authority uses to search through the users.

    Returns:
        Redirects the view to the home page of the health authority.
        If this method is accessed by an unathorized user, it redirects the
        view to the index page
    """
    if current_user is not None and current_user.type == 'authority':
        form = AuthorityForm()
        customer = None
        if request.method == 'POST':
            track_type = form.data['track_type']
            customer_ident = form.data['customer_ident']
            if track_type == 'SSN':
                customer = CustomerManager.retrieve_by_ssn(ssn=customer_ident)
            elif track_type == 'Email':
                customer = CustomerManager.retrieve_by_email(
                    email=customer_ident)
            else:
                customer = CustomerManager.retrieve_by_phone(
                    phone=customer_ident)
            if customer is None:
                flash("The customer doesn't exist")
                return redirect(
                    url_for('auth.authority',
                            id=current_user.id,
                            positive_id=0))
        return redirect(
            url_for('auth.authority',
                    id=current_user.id,
                    positive_id=customer.id))
    else:
        return redirect(url_for('home.index'))
Beispiel #2
0
def get_user_by_phone(user_phone):
    """
    Get a user by its current id
    :param user_phone: user it
    :return: json response
    """
    user = CustomerManager.retrieve_by_phone(user_phone)
    if user is None:
        response = {'status': 'User not present'}
        return jsonify(response), 404

    return jsonify(user.serialize()), 200