Exemplo n.º 1
0
def register():
    """Registers the user."""
    form = RegisterForm(request.form)
    if not (current_user.is_anonymous()):
        flash("you are logined")
        return render_template("logout.html")
    if request.method == "POST" and form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        password2 = form.password2.data
        email = form.email.data
        if User.query.filter_by(username=username).first():
            flash("The username is already taken")
        elif cmp(password, password2) != 0:
            flash("password mismatched")
        else:
            user = User(username, None, email)
            user.set_password(password)
            try:
                user.store_to_db()
                return render_template("account/registerok.html")
            except:
                flash("You were register failed, pls contact %s for help." % app.config["ADMIN"][1])
    else:
        return render_template("account/register.html", form=form)
    return render_template("account/register.html", form=form)
Exemplo n.º 2
0
def upload():
    form = UploadForm(request.form)
    if not form.validate:
        flash('form validation failed', 'error')
        return render_template('photo/upload.html', form = form)
    if request.method == 'POST' and 'photo' in request.files:
        filename = photos.save(request.files['photo'])
        rec = Photo(filename=filename, user=current_user.id)
        rec.store_to_db()
        flash("Photo saved.")
        return redirect(url_for('show', id=rec.id))
    return render_template('photo/upload.html', form = form)
Exemplo n.º 3
0
def wiki(name='MainPage'):
    if request.method == 'POST':
    #save
        if 'save' in request.form:
            wiki = Wiki.query.filter_by(title=name).first()
            form = WikiEditForm()
            if wiki:
                wiki.text = form.wikitext.data
                wiki.store_to_db()
            else: 
                wiki = Wiki(title=name, text=form.wikitext.data)
                try:
                    wiki.store_to_db()
                except:
                    app.logger.debug('failed')
            return redirect(url_for('wiki', name=name))
    #edit
        if 'edit' in request.form:
            wiki = Wiki.query.filter_by(title=name).first()
            if not wiki:
                flash("Creat a new page")
                form = WikiEditForm()
                form.set_default_text(text="Input text here")
                return render_template("wiki/edit.html", form=form, name = name)
            else:
                text = wiki.text
                form = WikiEditForm()
                form.set_default_text(text=text)
                return render_template("wiki/edit.html", form=form, name = name)
        if 'attach' in request.form:
            return render_template("wiki/attach.html", form=form, name = name)
        else:
            form = WikiShowForm()
            # get it from database
            wiki = Wiki.query.filter_by(title=name).first()
            # render to template
            return render_template("wiki/show.html", form=form, wiki=wiki, name=name)
    else:
        form = WikiShowForm()
        # get it from database
        wiki = Wiki.query.filter_by(title=name).first()
        # render to template
        return render_template("wiki/show.html", form=form, wiki=wiki, name=name)
Exemplo n.º 4
0
def new():
    if request.method == 'POST':
        if not request.form['title']:
            flash('Title is required', 'error')
        elif not request.form['text']:
            flash('Text is required', 'error')
        else:
            todo = Todo(request.form['title'], request.form['text'])
            todo.store_to_db()
            flash(u'Todo item was successfully created')
            return redirect(url_for('index'))
    return render_template('todo/new.html')
Exemplo n.º 5
0
def deluser():
    remove_form = RemoveUserForm(request.form)
    if request.method == "POST" and remove_form.validate_on_submit():
        username = remove_form.username.data
        user = User.query.filter_by(username=username).first()
        if not user:
            flash("The username has not taken")
        else:
            try:
                user.delete_from_db()
                flash("del user %s done." % user.username)
            except:
                flash("del user failed %s" % user.username, "error")
    return render_template("admin/deluser.html", remove_form=remove_form)
Exemplo n.º 6
0
def adduser():
    add_form = AddUserForm(request.form)
    if request.method == "POST" and add_form.validate_on_submit():
        username = add_form.username.data
        password = add_form.password.data
        email = add_form.email.data
        if User.query.filter_by(username=username).first():
            flash("The username is already taken")
        hash_pass = generate_password_hash(password, method="sha1", salt_length=8)
        user = User(username, hash_pass, email)
        try:
            user.store_to_db()
            flash("add user %s done." % user.username)
        except:
            flash("add user failed %s" % user.username, "error")
    return render_template("admin/adduser.html", add_form=add_form)
Exemplo n.º 7
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        # remember = form.remember.data
        remember = 1
        user = User.query.filter_by(username=username).first()
        if not len(form.errors):
            if user and user.check_password(password):
                loginuser = LoginUser(user.id, user.username)
                if login_user(loginuser, remember=remember):
                    flash("Logged in successfully!")
                    return redirect(request.args.get("next") or url_for("general.index"))
                else:
                    flash("Sorry, but you could not log in.", "error")
            else:
                flash("Incorrect username or password", "error")
    return render_template("account/login.html", form=form)
Exemplo n.º 8
0
def todos():
    return render_template("admin/todos.html", todos=Todo.query.order_by(Todo.pub_date.desc()).all())
Exemplo n.º 9
0
def deltodo():
    return render_template("admin/deltodo.html")
Exemplo n.º 10
0
def addtodo():
    return render_template("admin/addtodo.html")
Exemplo n.º 11
0
def users():
    users = User.query.all()
    return render_template("admin/users.html", users=users)
Exemplo n.º 12
0
def index():
    return render_template("admin/index.html")
Exemplo n.º 13
0
def index():
    return render_template('photo/index.html', photo = Photo.query.all())
Exemplo n.º 14
0
def help():
    return render_template("general/help.html")
Exemplo n.º 15
0
def forbidden(error):
    if request.is_xhr:
        return jsonify(error=_("Sorry, not allowed"))
    return render_template("error/403.html", error=error)
Exemplo n.º 16
0
def server_error(error):
    if request.is_xhr:
        return jsonify(error=_("Sorry, an error has occurred"))
    return render_template("error/500.html", error=error)
Exemplo n.º 17
0
def page_not_found(error):
    if request.is_xhr:
        return jsonify(error=_("Sorry, page not found"))
    return render_template("error/404.html", error=error)
Exemplo n.º 18
0
def show(id):
    photo = Photo.query.filter_by(id=id).first() 
    if photo is None:
        abort(404)
    return render_template('photo/show.html', photo=photo)
Exemplo n.º 19
0
def about():
    return render_template("general/about.html")
Exemplo n.º 20
0
def themes():
    themes = get_themes_list()
    return render_template("admin/themes.html", themes=themes)
Exemplo n.º 21
0
def settings():
    return render_template("general/settings.html")
Exemplo n.º 22
0
def database():
    return render_template("admin/database.html")
Exemplo n.º 23
0
def test():
    form = TestForm()
    return render_template("test/test.html", form = form)
Exemplo n.º 24
0
def reader():
    d = parse("https://github.com/yxm0513/flask-ims/commits/master.atom")
    return render_template('feed/reader.html', d=d)
Exemplo n.º 25
0
def index():
    return render_template('general/index.html')
Exemplo n.º 26
0
def unauthorized():
    return render_template("account/unauthorized.html")
Exemplo n.º 27
0
def jquery1():
    return render_template("test/jquery_antimate.html")
Exemplo n.º 28
0
def jquery2():
    return render_template("test/jquery_slide.html")
Exemplo n.º 29
0
def index():
    return render_template('todo/index.html',
        todos=Todo.query.order_by(Todo.pub_date.desc()).all()
    )