示例#1
0
def get_base_meta():
    note_config = Config.get()
    meta = dict()
    meta['note_title'] = note_config.get('note_title', '')
    meta['note_subtitle'] = note_config.get('note_subtitle', '')
    meta['note_description'] = note_config.get('note_description', '')
    meta['user_name'] = User.get_user_info('name')
    meta['year'] = datetime.now().year
    meta['ga_tracking_id'] = note_config.get('ga_tracking_id')
    meta['logged_in'] = User.is_logged_in()
    return meta
示例#2
0
def error_page(page_path, message=None):
    meta = get_base_meta()
    menu = get_menu_list(page_path=page_path)
    if message is None:
        if User.is_logged_in():
            message = '문서가 없습니다.'
        else:
            message = '문서가 없거나 권한이 없는 문서입니다.'
    flash(message)
    return render_template('page.html',
                           meta=meta,
                           menu=menu,
                           pagename=page_path)
示例#3
0
文件: view.py 项目: ipari/ipari-note
def route_login():
    if User.is_logged_in():
        return redirect('/')

    form = LoginForm()
    if request.method == 'GET':
        form.referrer.data = request.referrer
        meta = get_base_meta()
        menu = get_menu_list()
        return render_template('login.html', form=form, meta=meta, menu=menu,
                               pagename='로그인')

    if User.login(form):
        if form.referrer:
            return redirect(form.referrer.data)
        return redirect('/')

    flash('입력한 값이 맞는지 확인해주세요.')
    return redirect('/login')
示例#4
0
def get_menu_list(page_path=None, page_exist=False, editable=True):
    items = []
    if User.is_logged_in():
        if page_path is not None and editable:
            # FIXME: 수정해야함
            base_url = 'note'
            url = f'/{base_url}/{page_path}/edit'
            if page_exist:
                items.append({'type': 'edit', 'url': url, 'label': '편집'})
            else:
                items.append({'type': 'write', 'url': url, 'label': '작성'})
        items.append({'type': 'list', 'url': '/note', 'label': '목록'})
        items.append({'type': 'tag', 'url': '/tags', 'label': '태그'})
        items.append({'type': 'config', 'url': '/config', 'label': '설정'})
        items.append({'type': 'logout', 'url': '/logout', 'label': '로그아웃'})
    else:
        items.append({'type': 'list', 'url': '/note', 'label': '목록'})
        items.append({'type': 'tag', 'url': '/tags', 'label': '태그'})
        items.append({'type': 'login', 'url': '/login', 'label': '로그인'})
    return items
示例#5
0
文件: view.py 项目: ipari/ipari-note
def view_update():
    if User.is_logged_in():
        update_all()
        return redirect('/')
    return error_page(page_path=None, message='로그인이 필요합니다.')
示例#6
0
def get_permission():
    if User.is_logged_in():
        return Permission.PRIVATE
    return Permission.PUBLIC
示例#7
0
def check_permission(permission=Permission.PRIVATE, from_encrypted_path=False):
    if permission == Permission.PUBLIC or User.is_logged_in():
        return True
    if permission == Permission.LINK_ACCESS and from_encrypted_path:
        return True
    return False