login/logout working properly

This commit is contained in:
Matthias Seidl 2020-11-20 16:03:30 +01:00
parent 6eb0da2197
commit ce71145baf
4 changed files with 17 additions and 5 deletions

14
app.py
View File

@ -5,6 +5,7 @@ import urllib
import base64
import hashlib
import json
import os
def fetch_token(name):
return session['token']
@ -69,8 +70,10 @@ def home():
path = request.args.get('path')
if not path:
path = '/'
resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
files = resp.json()
if user:
resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
files = resp.json()
return render_template('home.html', user=user, files=files)
@app.route('/edit')
@ -112,11 +115,14 @@ def update():
@app.route('/upload', methods=['POST'])
def upload():
file = request.files
path = request.form.get('path')
head, tail = os.path.split(path)
path = head + '/' + file['file'].filename
image_string = base64.b64encode(file['file'].read())
payload = {"content": "", "message": "WEB API add file"}
payload['content'] = image_string.decode('UTF-8')
resp = oauth.gitea.request('POST', urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), 'static/test.png')), data=json.dumps(payload), headers={'Content-type': 'application/json'})
print(resp.json())
resp = oauth.gitea.request('POST', urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)), data=json.dumps(payload), headers={'Content-type': 'application/json'})
return 'OK'
if __name__ == "__main__":

View File

@ -49,6 +49,7 @@ function uploadFile(file) {
let formData = new FormData()
formData.append('file', file)
formData.append('path', document.getElementById('path').value)
fetch(url, {
method: 'POST',

View File

@ -12,6 +12,6 @@
</ul>
{% else %}
<a href="/login">login</a>
not logged in!
{% endif %}
{% endblock %}

View File

@ -27,7 +27,12 @@
<span class="navbar-text">
Logged in as: {{ user.username }} <span><img width='50px' src='{{ user.avatar_url }}'></span> <a class="nav-link" href="/logout">Logout</a>
</span>
{% else %}
<span class="navbar-text">
<a href="/login">login</a>
</span>
{% endif %}
</ul>
</div>