Esempio n. 1
0
def mp3():
    collected_mp3s = Content.query.all()
    my_mp3s = {}
    for c in collected_mp3s:
        my_mp3s[c.c_mp3] = str("/mp3/" + str(c.c_id))
    form = DownloadForm()
    if form.validate_on_submit():
        sb = form.sb.data
        mp3 = ""
        content = Content.query.filter_by(c_shebang=sb).first()
        if content is not None:
            mp3 = content.c_mp3
        else:
            mp3 = service.get_mp3(sb)
            content = Content(sb, mp3)
            db.add(content)
            db.commit()
        return send_file("../upload/"+mp3, mimetype="audio/mp3", as_attachment=True, attachment_filename=mp3)
    return render_template("mp3.html", title="Download MP3", form=form, my_mp3s=my_mp3s)
Esempio n. 2
0
def register():
    if current_user.is_authenticated:
        redirect("mp3")
    form = RegisterForm()
    if form.validate_on_submit():
        my_user = User.query.filter_by(u_username=form.username.data).first()
        if my_user is not None:
            flash("This username is alrdy in use")
            return redirect("register")
        else:
            if form.password.data != form.password2.data:
                flash("Your passwords are not equal")
                return redirect("register")
            else:
                my_user = User(form.username.data, form.password.data)
                db.add(my_user)
                db.commit()
                flash("Register completed... wait till the admin activates your account")
                #strange bug... user get logged in??
                logout_user()
                return redirect("register")
    return render_template("register.html", title="Register", form=form)