Example #1
0
    def setUp(self):
        LmfdbTest.setUp(self)
        self.users = self.C.userdb.users
        self.users.remove("$test_user")
        self.test_user = new_user("$test_user", "testpw")

        self.tc.post('/users/login',
                     data=dict(name='$test_user', password='******'))
Example #2
0
    def setUp(self):
        LmfdbTest.setUp(self)
        self.users = self.C.userdb.users
        self.users.remove("$test_user")
        self.test_user = new_user("$test_user", "testpw")

        self.tc.post('/users/login', data=dict(
            name='$test_user',
            password='******'
        ))
Example #3
0
def register_token(token):
    delete_old_tokens()
    token_exists = get_user_token_coll().find({'_id': token}).count() == 1
    if not token_exists:
        flask.abort(401)
    bread = base_bread() + [('Register', url_for(".register_new"))]
    if request.method == "GET":
        return render_template("register.html",
                               title="Register",
                               bread=bread,
                               next=request.referrer or "/",
                               token=token)
    elif request.method == 'POST':
        name = request.form['name']
        if not allowed_usernames.match(name):
            flask.flash(
                """Oops, usename '%s' is not allowed.
                  It must consist of lower/uppercase characters,
                  no spaces, numbers or '.', '_' and '-'.""" % name, "error")
            return flask.redirect(url_for(".register_new"))

        pw1 = request.form['password1']
        pw2 = request.form['password2']
        if pw1 != pw2:
            flask.flash("Oops, passwords do not match!", "error")
            return flask.redirect(url_for(".register_new"))

        if len(pw1) <= 3:
            flask.flash(
                "Oops, password too short. Minimum 4 characters please!",
                "error")
            return flask.redirect(url_for(".register_new"))

        full_name = request.form['full_name']
        email = request.form['email']
        next = request.form["next"]

        if pwdmanager.user_exists(name):
            flask.flash("Sorry, user ID '%s' already exists!" % name, "error")
            return flask.redirect(url_for(".register_new"))

        newuser = pwdmanager.new_user(name, pw1)
        newuser.full_name = full_name
        newuser.email = email
        newuser.save()
        login_user(newuser, remember=True)
        flask.flash("Hello %s! Congratulations, you are a new user!" %
                    newuser.name)
        get_user_token_coll().remove({'_id': token})
        logger.debug("removed login token '%s'" % token)
        logger.info("new user: '******' - '%s'" % (newuser.get_id(), newuser.name))
        return flask.redirect(next or url_for(".info"))
Example #4
0
def register_token(token):
    delete_old_tokens()
    token_exists = get_user_token_coll().find({"_id": token}).count() == 1
    if not token_exists:
        flask.abort(401)
    bread = base_bread() + [("Register", url_for(".register_new"))]
    if request.method == "GET":
        return render_template(
            "register.html", title="Register", bread=bread, next=request.referrer or "/", token=token
        )
    elif request.method == "POST":
        name = request.form["name"]
        if not allowed_usernames.match(name):
            flask.flash(
                """Oops, usename '%s' is not allowed.
                  It must consist of lower/uppercase characters,
                  no spaces, numbers or '.', '_' and '-'."""
                % name,
                "error",
            )
            return flask.redirect(url_for(".register_new"))

        pw1 = request.form["password1"]
        pw2 = request.form["password2"]
        if pw1 != pw2:
            flask.flash("Oops, passwords do not match!", "error")
            return flask.redirect(url_for(".register_new"))

        if len(pw1) <= 3:
            flask.flash("Oops, password too short. Minimum 4 characters please!", "error")
            return flask.redirect(url_for(".register_new"))

        full_name = request.form["full_name"]
        email = request.form["email"]
        next = request.form["next"]

        if pwdmanager.user_exists(name):
            flask.flash("Sorry, user ID '%s' already exists!" % name, "error")
            return flask.redirect(url_for(".register_new"))

        newuser = pwdmanager.new_user(name, pw1)
        newuser.full_name = full_name
        newuser.email = email
        newuser.save()
        login_user(newuser, remember=True)
        flask.flash("Hello %s! Congratulations, you are a new user!" % newuser.name)
        get_user_token_coll().remove({"_id": token})
        logger.debug("removed login token '%s'" % token)
        logger.info("new user: '******' - '%s'" % (newuser.get_id(), newuser.name))
        return flask.redirect(next or url_for(".info"))