Ejemplo n.º 1
0
def change_password_if_code_is_correct(code, email, password):
    """
    The params are the user input values
    :param code:string
    :param email: string
    :param password: string
    :return:
    """
    last_code = UniqueCode.last_code(email)
    if code == last_code:
        if len(password) < 4:
            flash("Password must be at least 4 characters long")
            return flask.render_template("reset_pass.html",
                                         code_active=True,
                                         email=email,
                                         code=code)
        user = User.find(email)
        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()

        flash("Password was reset successfully!")
        return flask.redirect('login')
    else:
        flask.flash("Code seems wrong. Did you check your email?")
        return flask.render_template("reset_pass.html",
                                     code_active=True,
                                     message=True,
                                     email=email)
Ejemplo n.º 2
0
def change_password_if_code_is_correct(code, email, password):
    """
    The params are the user input values
    :param code:string
    :param email: string
    :param password: string
    :return:
    """
    last_code = UniqueCode.last_code(email)
    if code == last_code:
        if len(password) < 4:
            flash("Password must be at least 4 characters long")
            return flask.render_template("reset_pass.html",
                                         code_active=True,
                                         email=email,
                                         code=code)
        user = User.find(email)
        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()

        flash("Password was reset successfully!")
        return flask.redirect('login')
    else:
        flask.flash("Code seems wrong. Did you check your email?")
        return flask.render_template("reset_pass.html",
                                     code_active=True,
                                     message=True,
                                     email=email)
Ejemplo n.º 3
0
    def setUp(self):
        # Superclass does prepare the DB before each of the tests
        super(Dbtest, self).setUp()

        # Some common test fixtures
        self.mir = User.find("*****@*****.**")
        assert self.mir
        self.de = Language.find("de")
Ejemplo n.º 4
0
    def setUp(self):
        # Superclass does prepare the DB before each of the tests
        super(Dbtest, self).setUp()

        # Some common test fixtures
        self.mir = User.find("*****@*****.**")
        assert self.mir
        self.de = Language.find("de")
Ejemplo n.º 5
0
    def test_user_session(self):
        user = User.find("*****@*****.**")
        with zeeguu.app.app_context():
            s = Session.find_for_user(user)
            s2 = Session.find_for_id(s.id)
            assert (s2.user == user)

            s3 = Session.find_for_id(3)
            assert not s3
Ejemplo n.º 6
0
    def test_password_hash(self):
        p1 = "test"
        p2 = "pass"
        with zeeguu.app.app_context():
            user = User.find("*****@*****.**")
            hash1 = util.password_hash(p1, user.password_salt)
            hash2 = util.password_hash(p2, user.password_salt)
            assert hash1 != hash2

            assert user.authorize("*****@*****.**", "pass") != None
Ejemplo n.º 7
0
    def test_login_with_session(self):
        self.logout()
        result = self.api_post("/login_with_session", dict(session_id="101"))
        assert (result.data == "FAIL")
        result = self.api_get("/m_recognize")
        assert "Redirecting..." in result.data

        user = User.find("*****@*****.**")
        with zeeguu.app.app_context():
            actual_session = str(Session.find_for_user(user).id)
            result = self.api_post("/login_with_session",
                                   dict(session_id=actual_session))
            assert result.data == "OK"

            result = self.api_get("/m_recognize")
            assert "Redirecting..." not in result.data