Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
xayyuu committed Jan 8, 2018
1 parent c4903b1 commit 2c505b3
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
基于https://github.com/sixu05202004/flaskblog 的源代码进行二次开发,暂时先用这个结构,会逐渐过渡,替换掉其中许多内容
基于https://github.com/sixu05202004/flaskblog 的源代码(在此感谢原作者,如有版权问题,请通知我,我会立即删除相关内容)进行二次开发,暂时先用这个结构,未来将逐渐过渡,优化整体内容

如果有任何问题,欢迎联系: [email protected]
如有任何问题,欢迎联系: [email protected]
9 changes: 9 additions & 0 deletions auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#coding=utf-8


# for auth
from flask import Blueprint

auth = Blueprint('auth', __name__)

from . import views
37 changes: 37 additions & 0 deletions auth/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from flask import Flask, render_template, url_for, redirect, request, flash, session, g, abort
from myapp import app
from model import article_tags, Category, Post, Tag, Comment, pageby, db
from werkzeug import secure_filename
from werkzeug.contrib.atom import AtomFeed
from flask_cache import Cache
from random import shuffle
from HTMLParser import HTMLParser
from re import sub
from sys import stderr
from traceback import print_exc
import os
import json
import time
from datetime import datetime
from form import CommentForm
from config import CATALOG

from . import auth


@auth.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != app.config['USERNAME']:
error = 'Invalid username'
flash(error)
elif request.form['password'] != app.config['PASSWORD']:
error = 'Invalid password'
flash(error)
else:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('newpost'))
return render_template('auth/login.html')
9 changes: 5 additions & 4 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
basedir = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_DATABASE_URI = 'sqlite:///'+ os.path.join(basedir, 'data.sqlite')

# proj code : zhuzi
SECRET_KEY =os.environ.get("SECRET_KEY_ZHUZI")
USERNAME = os.environ.get("USERNAME_ZHUZI")
PASSWORD = os.environ.get("PASSWORD_ZHUZI")

SECRET_KEY = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
USERNAME = 'admin'
PASSWORD = 'admin1234'

UPLOAD_FOLDER = './static/upload/'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
Expand All @@ -37,4 +38,4 @@
RECAPTCHA_PRIVATE_KEY = '6Ld4rwITAAAAAFE8nTS852QbsqCBx1mN8D4BqenE'

# 目錄
CATALOG = [u'Python', u'算法', u'运维', u'人工智能', u"文学"]
CATALOG = [u'Python', u'Algorithm', u'DevOps', u'AI', u"Life"]
Binary file modified data.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

markdown = functools.partial(markdown.markdown,
safe_mode='remove',
output_format="html")
output_format="html")
2 changes: 1 addition & 1 deletion manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:copyright: (c) 2013.
:license: BSD, see LICENSE for more details.
"""
from flask.ext.script import Server, Manager, prompt_bool
from flask_script import Server, Manager, prompt_bool
from myapp import app
from model import db
from config import CATALOG
Expand Down
7 changes: 5 additions & 2 deletions myapp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
from flask import Flask


app = Flask(__name__)
app.config.from_object('config')
from views import *

from auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint)

from auth.views import *
from views import *

if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
1 change: 0 additions & 1 deletion requirement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ Flask-Testing == 0.4.1
Flask-Script == 0.6.7
Flask-Uploads == 0.1.3
markdown >= 2.5.2
gevent
19 changes: 10 additions & 9 deletions templates/login.html → templates/auth/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
<meta name='robots' content='noindex,nofollow' />
</head>
<body class="login">
{% for message in get_flashed_messages() %}
<p id="message"> <span style="font-size:30px;font-weight:bold;">{{ message }}</span>
</p>
{% endfor %}


<div class=metanav>
{% if not session.logged_in %}
<a href="{{ url_for('login') }}">log in</a>
{% else %}
<a href="{{ url_for('logout') }}">log out</a>
{% endif %}
</div>
<div id="login">

<form action="{{ url_for('login') }}" method=post>
<form action="{{ url_for('auth.login') }}" method=post>
<p>
<label for="user_login">用户名<br />
<input type="text" name="username" id="username" class="input" value="" size="20" tabindex="10" /></label>
Expand Down Expand Up @@ -47,8 +45,11 @@
wp_attempt_focus();
if(typeof wpOnload=='function')wpOnload();
</script>
<p id="backtoblog"><a href="/" title="不知道自己在哪?">&larr; 首页&#039; Home</a></p>
<p id="backtoblog"><a href="/" title="返回首页">&larr; 首页&#039; Home</a></p>
</div>
<div class="clear"></div>



</body>
</html>
17 changes: 1 addition & 16 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def search(pageid=1):

searchword = request.args.get('s', '')
if not searchword:
return redirect(url_for('error_404'))
return redirect(url_for('index'))

searchresult = Post.query.search(searchword)

Expand Down Expand Up @@ -378,21 +378,6 @@ def error(content='404'):
return render_template('/error.html', content=content)


@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != app.config['USERNAME']:
error = 'Invalid username'
elif request.form['password'] != app.config['PASSWORD']:
error = 'Invalid password'
else:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('newpost'))
return render_template('login.html')


@app.route('/logout')
def logout():
session.pop('logged_in', None)
Expand Down

0 comments on commit 2c505b3

Please sign in to comment.