示例#1
0
def manage():
    from muzicast.web.util import render_master_page
    if not 'user' in session:
        return redirect(url_for('main.index'))

    user = User.byUsername(session['user']['username'])
    return render_master_page('playlist-manager.html', title='Manage Playlists', playlists=Playlist.select(Playlist.q.user == user.id))
示例#2
0
def index():
    query = request.args.get('query', '')
    keylist = query.split()
    return render_master_page("search_results.html", title="Results for \"%s\""%query, results={
        'artists': artist_search(keylist),
        'albums' : album_search(keylist),
        'tracks' : track_search(keylist)
    })
示例#3
0
文件: user.py 项目: nikhilm/muzicast
def forgot_password_username():
    sq = user = None
    if not request.form['username']:
        flash("Enter username!", "error")
    else:
        try:
            user = User.byUsername(request.form['username'])
            sq = user.secret_question
        except SQLObjectNotFound:
            flash("No such user!", "error")

    if sq:
        return render_master_page('forgot_password_2.html', title='Answer secret question', user=user.username, secret_question=sq)
    else:
        return redirect(url_for('user.forgot_password'))
示例#4
0
文件: track.py 项目: nikhilm/muzicast
def index(id):
    try:
        track = Track.get(id)
        stats = list(TrackStatistics.select(TrackStatistics.q.track == track.id))
        if len(stats) > 0:
        	stats = stats[0]
        else:
        	stats = None

        url = request.environ['HTTP_HOST']
        pos = url.rfind(':' + request.environ['SERVER_PORT'])
        if pos != -1:
            url = url[:pos]
        # otherwise the host is just the host without a port,
        # which is just what we want
        return render_master_page("track.html", title='Muzicast: Track', track=track, url=url, port=STREAM_PORT, stats=stats)
    except SQLObjectNotFound:
        abort(404)
示例#5
0
文件: user.py 项目: nikhilm/muzicast
def login():
    success = False
    if request.method == 'POST':
        try:
            user = User.byUsername(request.form['username'])
            if user.password != sha1(request.form['password']).hexdigest():
                flash("Wrong password!", "error")
            else:
                # login successful
                session['user'] = {'username': user.username, 'current_playlist': -1}
                if user.current_playlist != -1:
                    set_active(user.current_playlist)
                success = True
        except SQLObjectNotFound:
            flash("No such user exists!", "error")

    if success:
        return redirect(url_for('main.index'))
    else:
        return render_master_page('login.html', title='Muzicast: Login')
示例#6
0
文件: user.py 项目: nikhilm/muzicast
def delete():
    if 'user' not in session:
        return redirect(url_for('user.login'))

    if request.method == 'POST':
        try:
            user = User.byUsername(session['user']['username'])
            if user.password != sha1(request.form['password']).hexdigest():
                flash("Wrong password!", "error")
            else:
                playlists = Playlist.select(Playlist.q.user == user)
                [pl.destroySelf() for pl in playlists]
                user.destroySelf()
                del session['user']
                if 'playlist' in session:
                    del session['playlist']
                flash("User account deleted!")
        except SQLObjectNotFound:
            flash("No such user exists!", "error")

    return render_master_page('user-edit.html', title='Muzicast: Change Password')
示例#7
0
文件: user.py 项目: nikhilm/muzicast
def forgot_password_reset():
    new_pass = None
    if not request.form['username'] or not request.form['secret_answer']:
        flash("Invalid inputs!", "error")
    else:
        try:
            user = User.byUsername(request.form['username'])
            given = sha1(request.form['secret_answer']).hexdigest()
            actual = user.secret_answer

            if given != actual:
                flash("Wrong answer!", "error")
            else:
                new_pass = generate_random_password()
                user.password = sha1(new_pass).hexdigest()
        except SQLObjectNotFound:
            flash("No such user!", "error")

    if new_pass:
        return render_master_page('password_reset.html', title='Password reset', new_password=new_pass)
    else:
        return redirect(url_for('user.forgot_password'))
示例#8
0
文件: user.py 项目: nikhilm/muzicast
def register():
    success = False
    user = None
    if request.method == 'POST':
        try:
            user = User.byUsername(request.form['username'])
            flash("Username '%s' is already taken!"%request.form['username'], "error")
        except SQLObjectNotFound:
            # username available
            if not request.form['username']:
                flash("Please enter a username", "error")
            elif not request.form['password']:
                flash("Please enter a password!", "error")
            elif not request.form['secret_answer']:
                flash("Please enter secret answer!", "error")
            else:
                user = User(username=request.form['username'],
                            password=sha1(request.form['password']).hexdigest(),
                            secret_question=request.form['secret_question'],
                            secret_answer=sha1(request.form['secret_answer']).hexdigest())
                success = True

    return render_master_page('register.html', title='Muzicast: Register', registration_successful=success, user=user)
示例#9
0
文件: user.py 项目: nikhilm/muzicast
def edit():
    if 'user' not in session:
        return redirect(url_for('user.login'))

    if request.method == 'POST':
        try:
            user = User.byUsername(session['user']['username'])
            if user.password != sha1(request.form['password']).hexdigest():
                flash("Wrong password!", "error")
            else:
                new_password = request.form['new-password']
                cnf = request.form['confirm-password']

                if new_password != cnf:
                    flash("New password and Confirm password are not the same!", "error")
                else:
                    user.password = sha1(new_password).hexdigest()
                    flash("Password changed! Please login again.")
                    del session['user']
        except SQLObjectNotFound:
            flash("No such user exists!", "error")

    return render_master_page('user-edit.html', title='Muzicast: Change Password')
示例#10
0
def index(id):
    try:
        artist = Artist.get(id)
        return render_master_page("artist.html", title="Artist", artist=artist)
    except SQLObjectNotFound:
        abort(404)
示例#11
0
文件: genre.py 项目: nikhilm/muzicast
def index(id):
    try:
        genre = Genre.get(id)
        return render_master_page("genre.html", title="genre", genre=genre)
    except SQLObjectNotFound:
        abort(404)
示例#12
0
文件: album.py 项目: nikhilm/muzicast
def index(id):
    try:
        album = Album.get(id)
        return render_master_page("album.html", title="Album", album=album)
    except SQLObjectNotFound:
        abort(400)
示例#13
0
文件: main.py 项目: nikhilm/muzicast
def index():
    #just do first run check
    if is_first_run():
        return redirect(url_for('admin.index'))

    return render_master_page('home.html', title='Muzicast', top_tracks=top_tracks, recently_played=recently_played)
示例#14
0
文件: user.py 项目: nikhilm/muzicast
def forgot_password():
    return render_master_page('forgot_password_1.html', title='Password reclamation')