mirror of
https://github.com/sigmasternchen/Diary
synced 2025-03-15 07:08:56 +00:00
I have no idea what I'm doing. But: Trust me, I'm an engineer.
This commit is contained in:
parent
9b79ba2719
commit
ea11ee089b
2 changed files with 14 additions and 4 deletions
15
server.py
15
server.py
|
@ -31,7 +31,11 @@ def index():
|
|||
if not loggedin():
|
||||
return redirect(url_for('login'))
|
||||
diaries=db.query(Diary).filter_by(owner=session['id']).all()
|
||||
return render_template('index.html',diaries=diaries)
|
||||
if request.args.get('error') == '1':
|
||||
error='you already used that name'
|
||||
else:
|
||||
error=''
|
||||
return render_template('index.html',diaries=diaries, error=error)
|
||||
|
||||
@app.route('/login',methods=['GET','POST'])
|
||||
def login():
|
||||
|
@ -49,12 +53,15 @@ def logout():
|
|||
setuser('','')
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/diary/?new',methods=['POST'])
|
||||
@app.route('/newdiary',methods=['POST'])
|
||||
def newdiary():
|
||||
if not loggedin():
|
||||
abort(403)
|
||||
d=Diary(session['id'], request.form['name'])
|
||||
db.add(d)
|
||||
d=db.query(Diary).filter_by(name=request.form['name'], owner=session['id']).first()
|
||||
if d:
|
||||
return redirect(url_for('index', error=1))
|
||||
nd=Diary(session['id'], request.form['name'])
|
||||
db.add(nd)
|
||||
db.commit()
|
||||
return redirect(url_for('diary', name=request.form['name']))
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
<script src="{{ url_for('static',filename='script.js') }}"></script>
|
||||
</head>
|
||||
<body>
|
||||
{% if error != '' %}
|
||||
<div style="border: red 1px solid; color: red;">{{ error }}</div>
|
||||
{% endif %}
|
||||
<p>
|
||||
<a href="{{ url_for('logout') }}">Logout</a>
|
||||
<form method="post" action="{{ url_for('newdiary')}}">
|
||||
|
|
Loading…
Reference in a new issue