Esempio n. 1
0
def reset_password(email):
    """
    This endpoint can be used to rest a users password.
    To do this a uniquecode is required.
    """
    last_code = UniqueCode.last_code(email)
    code = request.form.get("code", None)
    if not (last_code == code):
        return make_error(400, "Invalid code")

    password = request.form.get("password", None)
    if len(password) < 4:
        return make_error(400, "Password should be at least 4 characters long")

    user = User.find(email)
    if user is None:
        return make_error(400, "Email unknown")
    user.update_password(password)
    db_session.commit()

    # Delete all the codes for this user
    for x in UniqueCode.all_codes_for(email):
        db_session.delete(x)
    db_session.commit()

    return "OK"
Esempio n. 2
0
def reset_password(email):
    """
    This endpoint can be used to rest a users password.
    To do this a uniquecode is required.
    """
    last_code = UniqueCode.last_code(email)
    code = request.form.get("code", None)
    if not (last_code == code):
        return make_error(400, "Invalid code")

    password = request.form.get("password", None)
    if len(password) < 4:
        return make_error(400, "Password should be at least 4 characters long")

    user = User.find(email)
    if user is None:
        return make_error(400, "Email unknown")
    user.update_password(password)
    db_session.commit()

    # Delete all the codes for this user
    for x in UniqueCode.all_codes_for(email):
        db_session.delete(x)
    db_session.commit()

    return "OK"
        def _upgrade_to_teacher(email):
            from zeeguu_core.model import User, Teacher
            db = zeeguu_core.db

            u = User.find(email)
            db.session.add(Teacher(u))
            db.session.commit()
Esempio n. 4
0
def send_code(email):
    """
    This endpoint generates a unique code that will be used to allow
    the user to change his/her password. The unique code is send to
    the specified email address.
    """
    from zeeguu_core.emailer.password_reset import send_password_reset_email

    try:
        User.find(email)
    except sqlalchemy.orm.exc.NoResultFound:
        return bad_request("Email unknown")

    code = UniqueCode(email)
    db_session.add(code)
    db_session.commit()

    send_password_reset_email(email, code)

    return "OK"
def test_performance():
    me = User.find('*****@*****.**')

    a = datetime.now()

    res = find_articles_for_user(me)
    print(len(res))

    for each in res[0:20]:
        print(f"{each.topics} {each.published_time} {each.title}")

    b = datetime.now()

    print(b - a)
Esempio n. 6
0
    def setUp(self, mock_invite_code):
        # idea from here:
        # https: // docs.pytest.org / en / latest / example / simple.html  # detect-if-running-from-within-a-pytest-run
        # allows the api translate_and_Bookmark to know that it's being called from the unit test
        # and use the reverse translator instead of the real translators

        app.testing = True
        self.app = app.test_client()
        zeeguu_core.db.create_all()

        response = self.app.post(f"/add_user/{TEST_EMAIL}", data=test_user_data)

        self.session = str(int(response.data))
        self.user = User.find(TEST_EMAIL)
Esempio n. 7
0
def reset_password(email):
    code = request.form.get("code", None)
    submitted_pass = request.form.get("password", None)

    user = User.find(email)
    last_code = UniqueCode.last_code(email)

    if submitted_code_is_wrong(last_code, code):
        return bad_request("Invalid code")
    if password_is_too_short(submitted_pass):
        return bad_request("Password is too short")
    if user is None:
        return bad_request("Email unknown")

    user.update_password(submitted_pass)
    delete_all_codes_for_email(email)

    db_session.commit()

    return "OK"
Esempio n. 8
0
from zeeguu_core.model import User

import sys


def forget_user(user):
    old_email = user.email
    old_name = user.name

    fake = Faker()
    user.name = "Forgotten Learner"
    user.email = fake.email()

    session = zeeguu_core.db.session
    session.add(user)
    session.commit()

    print(
        f"Before: {old_name} / {old_email} \nAfter: {user.name} / {user.email}"
    )


if __name__ == "__main__":

    if len(sys.argv) < 2:
        print(f"Usage: {sys.argv[0]} <email>")
        exit(-1)

    user = User.find(sys.argv[1])
    forget_user(user)
Esempio n. 9
0
from zeeguu_core.model import User
from zeeguu_core.word_scheduling.arts.words_to_study import bookmarks_to_study

me = User.find("*****@*****.**")

print(bookmarks_to_study(me))