def reset_password(id, id_type, current_password, new_password):
    user = get_profile_from_id(id, id_type, include_products=False)
    if user.check_password(current_password):
        user.set_password(new_password)
    else:
        raise PasswordResetError("invalid-password")

    return user
def reset_password(id, id_type, current_password, new_password):
    user = get_profile_from_id(id, id_type, include_products=False)
    if user.check_password(current_password):
        user.set_password(new_password)
    else:
        raise PasswordResetError("invalid-password")

    return user
Exemplo n.º 3
0
def refresh_status(profile_id):
    local_sleep(0.5) # client to webapp plus one trip to database
    id_type = request.args.get("id_type", "url_slug")  # url_slug is default    
    profile_bare_products = get_profile_from_id(profile_id, id_type, include_product_relationships=False)
    if profile_bare_products:
        status = profile_bare_products.get_refresh_status()
    else:
        abort_json(404, "This profile does not exist.")        
    return json_resp_from_thing(status)
def reset_password_from_token(reset_token, new_password):
    s = TimestampSigner(os.getenv("SECRET_KEY"), salt="reset-password")
    try:
        email = s.unsign(reset_token, max_age=60*60*24).lower()  # 24 hours

    except SignatureExpired:
        raise PasswordResetError("expired-token")

    except (BadTimeSignature, BadSignature):
        raise PasswordResetError("invalid-token")

    user = get_profile_from_id(email, "email", include_products=False)
    user.set_password(new_password)
    return user
def reset_password_from_token(reset_token, new_password):
    s = TimestampSigner(os.getenv("SECRET_KEY"), salt="reset-password")
    try:
        email = s.unsign(reset_token, max_age=60 * 60 * 24).lower()  # 24 hours

    except SignatureExpired:
        raise PasswordResetError("expired-token")

    except (BadTimeSignature, BadSignature):
        raise PasswordResetError("invalid-token")

    user = get_profile_from_id(email, "email", include_products=False)
    user.set_password(new_password)
    return user
Exemplo n.º 6
0
def get_user_for_response(id, request, expunge=True):
    id_type = unicode(request.args.get("id_type", "url_slug"))

    try:
        logged_in = unicode(getattr(current_user, id_type)) == id
    except AttributeError:
        logged_in = False

    retrieved_user = get_profile_from_id(id, id_type, show_secrets=logged_in)

    if retrieved_user is None:
        logger.debug(u"in get_user_for_response, user {id} doesn't exist".format(
            id=id))
        abort(404, "That user doesn't exist.")

    g.profile_slug = retrieved_user.url_slug

    if expunge and os.getenv("EXPUNGE", "False")=="True":
        logger.debug(u"expunging")

        db.session.expunge_all()

    return retrieved_user
Exemplo n.º 7
0
def get_user_for_response(id, request, include_products=True):
    id_type = unicode(request.args.get("id_type", "url_slug"))

    try:
        logged_in = unicode(getattr(current_user, id_type)) == id
    except AttributeError:
        logged_in = False

    retrieved_user = get_profile_from_id(
        id,
        id_type,
        show_secrets=logged_in,
        include_products=include_products
    )

    if retrieved_user is None:
        logger.debug(u"in get_user_for_response, user {id} doesn't exist".format(
            id=id))
        abort(404, "That user doesn't exist.")

    g.profile_slug = retrieved_user.url_slug

    return retrieved_user
Exemplo n.º 8
0
def refresh_status(profile_id):
    local_sleep(0.5) # client to webapp plus one trip to database
    id_type = request.args.get("id_type", "url_slug")  # url_slug is default    
    profile_bare_products = get_profile_from_id(profile_id, id_type, include_product_relationships=False)
    print profile_bare_products
    return json_resp_from_thing(profile_bare_products.get_refresh_status())
Exemplo n.º 9
0
 def __init__(self, url_slug, tagspace, tag):
     self.profile = get_profile_from_id(url_slug, "url_slug")
     self.tagspace = tagspace
     self.tag = tag
     self.products = products_matching_tag(self.profile.display_products, tagspace, tag)
Exemplo n.º 10
0
def profile_products_get(url_slug):

    action = request.args.get("action", "refresh")
    source = request.args.get("source", "webapp")
    timer = util.Timer()

    load_times = {}
    just_stubs = request.args.get("stubs", "False").lower() in ["1", "true"]
    if just_stubs:
        profile = get_profile_stubs_from_url_slug(url_slug)
        if not profile:
            abort_json(404, "This profile does not exist.")
        load_times["profile"] = timer.elapsed()
        product_list = [
            {"tiid": p.tiid, "genre": p.genre}
            for p in profile.products_not_removed
            if p.genre not in ["account"]
        ]
        load_times["product_list"] = timer.since_last_check()

    else:
        profile = get_profile_from_id(url_slug)
        if not profile:
            abort_json(404, "This profile does not exist.")

        markup = Markup(url_slug, embed=False)
        load_times["profile"] = timer.elapsed()

        product_list = profile.get_products_markup(
            markup=markup,
            show_keys=[
                # for rendering biblio
                "biblio",
                "embed_markup",

                "_tiid",
                "tiid",
                "markup",
                "countries_str",

                # for sorting
                "year",
                "title",
                "awardedness_score",
                "metrics_raw_sum",
                "authors",

                # misc
                "genre",
                "genre_icon"
            ]
        )
        load_times["product_list"] = timer.since_last_check()

    product_dicts_list = util.todict(product_list)
    resp = {
        "a_load_times": load_times,
        "is_refreshing": profile.is_refreshing,
        "list": product_dicts_list
    }
    return json_resp_from_thing(resp)