Beispiel #1
0
def modify_info():
    form = ModifyForm()
    if request.method == "POST":
        file = request.files["file"]
        img = file.stream.read()

        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            try:
                src = os.path.join(app.config["UPLOAD_FOLDER"], filename)
                print src
                file.save(src)
            except:
                flash(u"上传失败")
            else:
                flash(u"上传完成")
            finally:
                try:
                    update = user_request(mode="update", picture=img, user_id=session["userid"])  # validate_userid
                    print update.commit()
                    print session["userid"]

                except:

                    print "update failed"
                else:
                    print "ok"
                return redirect(url_for("modify_info", filename=filename))
    return render_template("modify_info.html", form=form)
Beispiel #2
0
def img(userid=None):
    if not userid:
        userid = session["userid"]
    select = user_request(mode="select", user_id=userid)
    select.commit()
    if select.result:
        data = select.result[0][4]
    else:
        return "no picture"
    return Response(
        response=data, status=None, headers=None, mimetype="image/jpg", content_type=None, direct_passthrough=False
    )
Beispiel #3
0
def signup():
    form = SignupForm()
    if request.method == "POST":
        if form.validate_on_submit():
            try:
                insert = user_request(
                    mode="insert",
                    username=form.username.data.decode("utf-8"),
                    password=form.password.data,
                    email=form.email.data,
                )
                print form.username.data
                insert.commit()

            except MySQLdb.IntegrityError:
                flash("username or email exists")
            else:
                session["username"] = request.form["username"]
                return redirect(url_for("index"))
    return render_template("signup.html", form=form)