Пример #1
0
 def save(self, theme, language):
     user = User(username=self.username.data,
                 email=self.email.data,
                 password=self.password.data,
                 date_joined=datetime.utcnow(),
                 language=language,
                 theme=theme)
     return user.save()
Пример #2
0
def createall():
    """
    Creates the database with some example content
    Attention: This will delete your whole database (if one exists)
    """

    # Be sure that there isn't a existing one.
    db.drop_all()

    db.create_all()

    user1 = User(username="******", password="******", email="*****@*****.**",
                 theme=current_app.config["DEFAULT_THEME"],
                 language=current_app.config["BABEL_DEFAULT_LOCALE"],
                 is_admin=True)
    user1.save()

    user2 = User(username="******", password="******", email="*****@*****.**",
                 theme="bootstrap2", language="de", is_admin=False)

    user2.save()

    post = Post(title="Example 1", content="Example Content",
                date_created=datetime.datetime.utcnow())
    post.save(user1)

    comment = Comment(content="Test Comment",
                      date_created=datetime.datetime.utcnow())
    comment.save(user2, post)
Пример #3
0
def login():
    """
    Logs the user in
    """

    if current_user is not None and current_user.is_authenticated():
        return redirect(url_for("user.profile"))

    form = LoginForm(request.form)
    if form.validate_on_submit():
        user, authenticated = User.authenticate(form.login.data,
                                                form.password.data)

        if user and authenticated:
            login_user(user, remember=form.remember_me.data)
            return redirect(request.args.get("next") or
                            url_for("blog.index"))

        flash(_("Wrong username or password"), "danger")
    return render_template("auth/login.html", form=form)