Exemplo n.º 1
0
def google_authorized(response):
    if not response:
        return u'Failed to login using google OAuth'

    if 'next' in session:
        next_url = session.pop('next')
    else:
        next_url = url_for('main.index')
    session[GOOGLE_TOKEN_NAME] = (response.get('access_token'), '')

    result = UserController.register_google(response)
    if result.get(u'ok', False):
        user = result.get(u'user')

        login_request = UserController.login(user_info=user)
        if login_request:
            if result.get(u'created', False):
                # 새로운 회원으로 가입 되었을때
                playlist = PlaylistController.create_default_playlist(user=user)
                flash(u'%s, 가입을 진심으로 환영합니다!' % user.id_str)
                if not playlist.get(u'ok', True):
                    flash(u'기본 플레이리스트가 생성되지 않았습니다.\n%s' % playlist.get(u'msg', u''))

            else:
                # 기존 회원일때
                flash(u'%s, 재방문을 진심으로 환영합니다!' % user.id_str)
        else:
            flash(u'로그인에 실패하였습니다.')

    else:
        # 뭔가 잘못됨.
        flash(result.get(u'msg'))

    return redirect(next_url)
Exemplo n.º 2
0
def playlist(id_int=None):
    params = {}
    if id_int:
        requested_user = UserController.get_user_by_id_int(id_int)
        params['user'] = requested_user
    all_playlist = UserController.get_all_playlist(**params)

    opt = {
        'all_playlist': all_playlist,
        'requested_user': params.get('user', g.user),
    }

    return render_template("user/playlist.html", **opt)
Exemplo n.º 3
0
def archived(id_int=None):
    params = {}
    if id_int:
        params['user'] = UserController.get_user_by_id_int(id_int)
    user_playlist = UserController.get_archived_playlist(**params)
    all_media = user_playlist.media_list

    opt = {
        'playlist': user_playlist,
        'media_list': all_media,
    }

    return render_template('playlist/medialist.html', **opt)
def context_processor():
    return {
        'user': g.user,
        'archived_playlist': UserController.get_archived_playlist(),
        'playlist_number': PlaylistController.get_playlist_number(),
        'today': datetime.now().replace(microsecond=0),
    }
def bookmarklet():
    opt = {
        'is_login': False,
        'is_active': False,
        'done': False,
    }

    if g.user:
        opt['is_login'] = True

        if g.user.active:
            opt['is_active'] = True

    if request.method == 'GET':
        opt['address'] = request.args.get('url', '')

        media_tuple = MediaController.inspect_url(form_data=opt)
        opt['result'] = MediaController.route_parser(media_tuple=media_tuple)

    elif request.method == 'POST':
        inspected_data = MediaController.inspect_url(request.form)
        created_media, created_flag = MediaController.get_or_create(inspected_data)

        playlist = UserController.get_archived_playlist()
        success = PlaylistController.add_media(playlist=playlist, media=created_media)
        if success:
            opt['done'] = True
        else:
            opt['fail'] = True

    return render_template("media/bookmarklet.html", **opt)
def archive():
    if request.method == 'GET':
        opt = {
            'bookmarklet_address': url_for('media.bookmarklet', _external=True),
        }
        return render_template("media/archive.html", **opt)

    else:
        inspected_data = MediaController.inspect_url(request.form)
        created_media, created_flag = MediaController.get_or_create(inspected_data)

        playlist = UserController.get_archived_playlist()
        success = PlaylistController.add_media(playlist=playlist, media=created_media)
        if not success:
            flash(u'failed to archive')

        return redirect(url_for('user.archived'))
Exemplo n.º 7
0
def logout():
    UserController.logout()
    return redirect(url_for('main.index'))