示例#1
0
def publish():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    name = request.POST.get("name", '').strip()
    title = request.POST.get("title", '').strip()
    cat = request.POST.get("cat",'').strip().replace(',', ',')
    tag = request.POST.get("tag",'').strip().replace(',', ',')
    private = request.POST.get("private",'') # '' or 'on'
    content = request.POST.get("content",'').strip()
    
    if not (name and title):
        return {'code': -3, 'msg': '请填写完整'}
    
    tag = '__%s,%s'%(username, tag) if tag else '__'+username
    
    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    '''%(title, cat, tag)
    m_date = datetime.datetime.now().strftime('%Y-%m-%d')
    path = 'raw/entry/%s-%s.md'%(m_date, name)
    m_file = open(path, 'w+')
    m_file.write('%s\n%s'%(head,content) )
    m_file.close()
    
    entryService.add_entry(True, path, True if private else False)
    return {'code': 0, 'msg': '发布成功'}
示例#2
0
def UpdateSave():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    raw_url = request.POST.get("raw_url", '')
    content = request.POST.get("content", '').strip()

    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(
        config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    if not entry:
        page_url = raw_url.replace(config.raw_url,
                                   '').replace(config.raw_suffix,
                                               config.url_suffix)
        entry = entryService.find_by_url(entryService.types.page,
                                         page_url).entry

    m_file = open(entry.path, 'w')
    m_file.write('%s\n%s' % (entry.header, content))
    m_file.close()
    file_name = entry.path.replace(config.entry_dir, '')
    if file_name.startswith('/'):
        file_name = file_name.replace('/', '', 1)
    if config.use_git:
        from git import Repo
        repo = Repo('./entry')
        #git_master = repo.heads.master
        git_index = repo.index
        git_index.add([file_name])
        git_index.commit('Update %s' % file_name)
    entryService.add_entry(False, entry.path, entry.private)
    return {'code': 0, 'msg': '更新成功'}
示例#3
0
文件: routes.py 项目: tyjsee/YouMd
def publish():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    name = request.POST.get("name", '').strip()
    title = request.POST.get("title", '').strip()
    cat = request.POST.get("cat", '').strip().replace(',', ',')
    tag = request.POST.get("tag", '').strip().replace(',', ',')
    private = request.POST.get("private", '')  # '' or 'on'
    content = request.POST.get("content", '').strip()

    if not (name and title):
        return {'code': -3, 'msg': '请填写完整'}

    tag = '__%s,%s' % (username, tag) if tag else '__' + username

    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    ''' % (title, cat, tag)
    m_date = datetime.datetime.now().strftime('%Y-%m-%d')
    path = 'raw/entry/%s-%s.md' % (m_date, name)
    m_file = open(path, 'w+')
    m_file.write('%s\n%s' % (head, content))
    m_file.close()

    entryService.add_entry(True, path, True if private else False)
    return {'code': 0, 'msg': '发布成功'}
示例#4
0
文件: utils.py 项目: JoneXiong/MoCrud
def flash(message, category='message'):
    """Flashes a message to the next request.  In order to remove the
    flashed message from the session and to display it to the user
    """
    from mole.sessions import get_current_session
    session = get_current_session()
    session['_flashes']=[]
    session['_flashes'].append((category, message))
示例#5
0
文件: auth.py 项目: liuyun073/MoleSys
    def login_user(self, user):
        from mole.sessions import get_current_session
        session = get_current_session()
        session['logged_in'] = True
        session['user_pk'] = user.get_id()
        session.permanent = True
#        g.user = user
        flash('You are logged in as %s' % user.username, 'success')
示例#6
0
文件: routes.py 项目: JoneXiong/YouMd
def language():
    session = get_current_session()
    session["language"] = str(request.GET.get('language', 'cn'))
    if session["language"] == 'en':
        config.en_trans.install()
    else:
        config.zh_trans.install()
    return Index()
示例#7
0
文件: routes.py 项目: tyjsee/YouMd
def language():
    session = get_current_session()
    session["language"] = str(request.GET.get('language', 'cn'))
    if session["language"] == 'en':
        config.en_trans.install()
    else:
        config.zh_trans.install()
    return Index()
示例#8
0
文件: auth.py 项目: liuyun073/MoleSys
    def logout_user(self, user):
        from mole.sessions import get_current_session
        session = get_current_session()
        if self.clear_session:
            session.clear()
        else:
            session.pop('logged_in', None)
#        g.user = None
        flash('You are now logged out', 'success')
示例#9
0
def login():
    if request.method == 'POST':
        username = request.POST.get("username", '')
        password = request.POST.get("password", '')
        if password == config.admin_pwd and username == config.admin_user:
            session = get_current_session()
            session['username'] = username
            return {'code': 0, 'msg': 'OK'}
        else:
            return {'code': -1, 'msg': '用户名或密码错误'}
    else:
        return template('auth/login.html', config=config, media_prefix=media_prefix)
示例#10
0
def login():
    if request.method == "POST":
        username = request.POST.get("username", "")
        password = request.POST.get("password", "")
        if password == config.admin_pwd and username == config.admin_user:
            session = get_current_session()
            session["username"] = username
            return {"code": 0, "msg": "OK"}
        else:
            return {"code": -1, "msg": "用户名或密码错误"}
    else:
        return template("auth/login.html", config=config, media_prefix=media_prefix)
示例#11
0
def login():
    if request.method == 'POST':
        username = request.POST.get("username", '')
        password = request.POST.get("password", '')
        if password == config.admin_pwd and username == config.admin_user:
            session = get_current_session()
            session['username'] = username
            return {'code': 0, 'msg': 'OK'}
        else:
            return {'code': -1, 'msg': '用户名或密码错误'}
    else:
        return template('auth/login.html', config=config, media_prefix=media_prefix)
示例#12
0
文件: routes.py 项目: JoneXiong/YouMd
def PrivateRaw(url):
    session = get_current_session()
    username = session.get('username', '')
    
    url = config.raw_url + url
    raw = entryService.find_raw(url)
    if not raw == None:
        response.headers['Content-Type'] = 'text/plain'
        response.headers['Content-Encoding'] = 'utf-8'
        return raw.strip()
    params = entryService.archive(entryService.types.raw, url, private=True, username=username)
    if params.entries == None:
        return template('error', params=params, config=config)
    return template('private', params=params, config=config)
示例#13
0
文件: auth.py 项目: liuyun073/MoleSys
    def get_logged_in_user(self):
        from mole.sessions import get_current_session
        session = get_current_session()
        if session.get('logged_in'):
            if getattr(request, 'user', None):
                return request.user

            try:
                return self.User.select().where(
                    self.User.active==True, 
                    self.User.id==session.get('user_pk')
                ).get()
            except self.User.DoesNotExist:
                pass
示例#14
0
文件: utils.py 项目: JoneXiong/MoCrud
def get_flashed_messages(with_categories=False):
    """Pulls all flashed messages from the session and returns them.
    Further calls in the same request to the function will return
    the same messages.  By default just the messages are returned,
    but when `with_categories` is set to `True`, the return value will
    be a list of tuples in the form ``(category, message)`` instead.
    """
    from mole.sessions import get_current_session
    session = get_current_session()
    if session.has_key('_flashes'):
        flashes = session.pop('_flashes')
    else:
        flashes = []
    if not with_categories:
        return [x[1] for x in flashes]
    return flashes
示例#15
0
def DeletePost():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    raw_url = request.POST.get("raw_url",'')
    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    entryService.delete_entry(entry.path)
    os.remove(entry.path)
    
    if entry.private:
        entryService.del_private(entry.path)
    
    return {'code': 0, 'msg': '删除成功'}
示例#16
0
文件: routes.py 项目: tyjsee/YouMd
def SaveHead():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    title = request.POST.get("title", '').strip()
    cat = request.POST.get("cat", '').strip().replace(',', ',')
    tag = request.POST.get("tag", '').strip().replace(',', ',')
    private = request.POST.get("private", '')
    content = request.POST.get("content", '').strip()
    raw_url = request.POST.get("raw_url", '')

    if not title:
        return {'code': -3, 'msg': '请填写完整'}

    url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix,
                                                      config.url_suffix)
    url = config.entry_url + url
    params = entryService.find_by_url(entryService.types.entry, url)
    entry = params.entry
    if not entry:
        return {'code': -4, 'msg': '对象不存在'}

    tag = '__%s,%s' % (username, tag) if tag else '__' + username

    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    ''' % (title, cat, tag)

    m_file = open(entry.path, 'w+')
    m_file.write('%s\n%s' % (head, content))
    m_file.close()

    entryService.update_entry(
        entry, {
            'title': title,
            'tags': tag and tag.split(',') or [],
            'cats': cat and cat.split(',') or [],
            'private': bool(private)
        })
    return {'code': 0, 'msg': '修改成功'}
示例#17
0
def PrivateRaw(url):
    session = get_current_session()
    username = session.get('username', '')

    url = config.raw_url + url
    raw = entryService.find_raw(url)
    if not raw == None:
        response.headers['Content-Type'] = 'text/plain'
        response.headers['Content-Encoding'] = 'utf-8'
        return raw.strip()
    params = entryService.archive(entryService.types.raw,
                                  url,
                                  private=True,
                                  username=username)
    if params.entries == None:
        return template('error', params=params, config=config)
    return template('private', params=params, config=config)
示例#18
0
文件: routes.py 项目: tyjsee/YouMd
def DeletePost():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    raw_url = request.POST.get("raw_url", '')
    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(
        config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    entryService.delete_entry(entry.path)
    os.remove(entry.path)

    if entry.private:
        entryService.del_private(entry.path)

    return {'code': 0, 'msg': '删除成功'}
示例#19
0
def SaveHead():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    title = request.POST.get("title", '').strip()
    cat = request.POST.get("cat",'').strip().replace(',', ',')
    tag = request.POST.get("tag",'').strip().replace(',', ',')
    private = request.POST.get("private",'')
    content = request.POST.get("content",'').strip()
    raw_url = request.POST.get("raw_url",'')
    
    if not title:
        return {'code': -3, 'msg': '请填写完整'}
    
    url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix, config.url_suffix)
    url = config.entry_url + url
    params = entryService.find_by_url(entryService.types.entry, url)
    entry = params.entry
    if not entry:
        return {'code': -4, 'msg': '对象不存在'}
    
    tag = '__%s,%s'%(username, tag) if tag else '__'+username
    
    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    '''%(title, cat, tag)

    m_file = open(entry.path, 'w+')
    m_file.write('%s\n%s'%(head,content) )
    m_file.close()
    
    entryService.update_entry(entry, {
                                      'title': title,
                                      'tags': tag and tag.split(',') or [],
                                      'cats': cat and cat.split(',') or [],
                                      'private': bool(private)
                                      })
    return {'code': 0, 'msg': '修改成功'}
示例#20
0
def publish():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    name = request.POST.get("name", '').strip()
    title = request.POST.get("title", '').strip()
    cat = request.POST.get("cat", '').strip().replace(',', ',')
    tag = request.POST.get("tag", '').strip().replace(',', ',')
    private = request.POST.get("private", '')  # '' or 'on'
    content = request.POST.get("content", '').strip()

    if not (name and title):
        return {'code': -3, 'msg': '请填写完整'}

    tag = '__%s,%s' % (username, tag) if tag else '__' + username

    head = '''---
layout: post
title: %s
category: %s
tags: [%s]
---
    ''' % (title, cat, tag)
    m_date = datetime.datetime.now().strftime('%Y-%m-%d')
    file_name = '%s-%s.md' % (m_date, name)
    path = os.path.join(config.entry_dir,
                        file_name)  #'raw/entry/%s-%s.md' % (m_date, name)
    m_file = open(path, 'w+')
    m_file.write('%s\n%s' % (head, content))
    m_file.close()
    if config.use_git:
        from git import Repo
        repo = Repo('./entry')
        #git_master = repo.heads.master
        git_index = repo.index
        git_index.add([file_name])
        git_index.commit('Add %s' % file_name)

    entryService.add_entry(True, path, True if private else False)
    return {'code': 0, 'msg': '发布成功'}
示例#21
0
文件: routes.py 项目: MaloneQQ/YouMd
def UpdateSave():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    raw_url = request.POST.get("raw_url",'')
    content = request.POST.get("content",'').strip()
    
    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    if not entry:
        page_url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix, config.url_suffix)
        entry = entryService.find_by_url(entryService.types.page, page_url).entry
    
    m_file = open(entry.path, 'w')
    m_file.write('%s\n%s'%(entry.header,content) )
    m_file.close()
    entryService.add_entry(False, entry.path, entry.private)
    return {'code': 0, 'msg': '更新成功'}
示例#22
0
文件: routes.py 项目: tyjsee/YouMd
def upload():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'success': 0, 'message': '请先登录', 'url': ''}

    uploadfile = request.files.get('editormd-image-file')

    tnow = datetime.datetime.now()
    parent_path = os.path.join(config.upload_path, tnow.strftime('%Y%m'))
    if not os.path.exists(parent_path):
        os.makedirs(parent_path)

    m_f = ("000" + str(tnow.microsecond / 1000))[-3:]
    filename = tnow.strftime("%d%H%M%S") + m_f + "_" + uploadfile.filename
    upload_path = os.path.join(parent_path, filename)
    with open(upload_path, 'w+b') as f:
        f.write(uploadfile.file.read())
    url = '%s/%s/%s' % (config.file_url, tnow.strftime('%Y%m'), filename)
    return {'success': 1, 'message': '上传成功', 'url': url}
示例#23
0
文件: routes.py 项目: MaloneQQ/YouMd
def upload():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'success': 0, 'message': '请先登录', 'url':''}
    
    uploadfile=request.files.get('editormd-image-file')
    
    tnow=datetime.datetime.now()
    parent_path = os.path.join(config.upload_path, tnow.strftime('%Y%m'))
    if not os.path.exists(parent_path):
        os.makedirs(parent_path)
    
    m_f=("000"+str(tnow.microsecond/1000))[-3:]
    filename= tnow.strftime("%d%H%M%S")+m_f+"_" + uploadfile.filename
    upload_path = os.path.join(parent_path, filename)
    with open(upload_path, 'w+b') as f:
        f.write(uploadfile.file.read())
    url = '%s/%s/%s'%(config.file_url, tnow.strftime('%Y%m'), filename)
    return {'success': 1, 'message': '上传成功', 'url': url}
示例#24
0
def _web_router(url):
    a_dict = {}
    a_key = {}
    a_sess = {}    # session变量 
    a_hdr = {}    # 头信息
    a_data = ""    # 数据
    
    # 构建请求参数
    a_dict['session'] = get_current_session();
    a_dict['SCRIPT_NAME'] = url;
    for a_key in request.GET.keys():
        a_dict[a_key] = request.GET.get(a_key)

    for a_key in request.POST.keys():
        a_dict[a_key] = request.POST.get(a_key)
    

    if g_web_proc.has_key('proc'):
        a_data = g_web_proc['proc'](a_dict)
    else:
        a_data = "hello!" + url
        
    return a_data
示例#25
0
def GetHead():
    session = get_current_session()
    username = session.get('username','')
    if not username:
        return {'code': -2, 'msg': '未登录'}
    
    raw_url = request.POST.get("raw_url",'')
    url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix, config.url_suffix)
    url = config.entry_url + url
    params = entryService.find_by_url(entryService.types.entry, url)
    entry = params.entry
    if entry:
        tags = [e for e in entry.tags if not e.startswith('__')]
        data = {
               'title': entry.name,
               'cat': entry.categories and ','.join(entry.categories) or '',
               'tag': tags and ','.join(tags) or '',
               'private': entry.private
               }
        ret = {'code': 0, 'msg': 'ok', 'data': data}
    else:
        ret = {'code': -1, 'msg': 'can not find'}
    return ret
示例#26
0
文件: routes.py 项目: tyjsee/YouMd
def UpdateSave():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    raw_url = request.POST.get("raw_url", '')
    content = request.POST.get("content", '').strip()

    entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(
        config.raw_suffix, config.url_suffix)
    entry = entryService.find_by_url(entryService.types.entry, entry_url).entry
    if not entry:
        page_url = raw_url.replace(config.raw_url,
                                   '').replace(config.raw_suffix,
                                               config.url_suffix)
        entry = entryService.find_by_url(entryService.types.page,
                                         page_url).entry

    m_file = open(entry.path, 'w')
    m_file.write('%s\n%s' % (entry.header, content))
    m_file.close()
    entryService.add_entry(False, entry.path, entry.private)
    return {'code': 0, 'msg': '更新成功'}
示例#27
0
文件: routes.py 项目: tyjsee/YouMd
def GetHead():
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'code': -2, 'msg': '未登录'}

    raw_url = request.POST.get("raw_url", '')
    url = raw_url.replace(config.raw_url, '').replace(config.raw_suffix,
                                                      config.url_suffix)
    url = config.entry_url + url
    params = entryService.find_by_url(entryService.types.entry, url)
    entry = params.entry
    if entry:
        tags = [e for e in entry.tags if not e.startswith('__')]
        data = {
            'title': entry.name,
            'cat': entry.categories and ','.join(entry.categories) or '',
            'tag': tags and ','.join(tags) or '',
            'private': entry.private
        }
        ret = {'code': 0, 'msg': 'ok', 'data': data}
    else:
        ret = {'code': -1, 'msg': 'can not find'}
    return ret
示例#28
0
def paste_upload():
    import base64
    session = get_current_session()
    username = session.get('username', '')
    if not username:
        return {'success': 0, 'message': '请先登录', 'url': ''}

    data = request.POST.get("image", '')
    head, body = data.split(',', 1)
    ftype = head.split('/')[1].replace(';base64', '')
    data = base64.b64decode(body)

    tnow = datetime.datetime.now()
    parent_path = os.path.join(config.upload_path, tnow.strftime('%Y%m'))
    if not os.path.exists(parent_path):
        os.makedirs(parent_path)

    m_f = ("000" + str(tnow.microsecond / 1000))[-3:]
    filename = tnow.strftime("%d%H%M%S") + m_f + '.' + ftype
    upload_path = os.path.join(parent_path, filename)
    with open(upload_path, 'w+b') as f:
        f.write(data)
    url = '%s/%s/%s' % (config.file_url, tnow.strftime('%Y%m'), filename)
    return {'success': 1, 'message': '上传成功', 'url': url}
示例#29
0
def logout():
    session = get_current_session()
    del session['username']
    return redirect(request.params.get('next') or '/')
示例#30
0
def logout():
    session = get_current_session()
    del session['username']
    return redirect(request.params.get('next') or '/')
示例#31
0
def logout():
    session = get_current_session()
    del session["username"]
    return redirect(request.params.get("next") or "/")
示例#32
0
文件: config.py 项目: wuchangqi/YouMd
def cur_user():
    from mole.sessions import get_current_session
    session = get_current_session()
    return session.get('username', '')