login/logout working properly
This commit is contained in:
parent
6eb0da2197
commit
ce71145baf
10
app.py
10
app.py
|
|
@ -5,6 +5,7 @@ import urllib
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
def fetch_token(name):
|
def fetch_token(name):
|
||||||
return session['token']
|
return session['token']
|
||||||
|
|
@ -69,8 +70,10 @@ def home():
|
||||||
path = request.args.get('path')
|
path = request.args.get('path')
|
||||||
if not path:
|
if not path:
|
||||||
path = '/'
|
path = '/'
|
||||||
|
if user:
|
||||||
resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
|
resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
|
||||||
files = resp.json()
|
files = resp.json()
|
||||||
|
|
||||||
return render_template('home.html', user=user, files=files)
|
return render_template('home.html', user=user, files=files)
|
||||||
|
|
||||||
@app.route('/edit')
|
@app.route('/edit')
|
||||||
|
|
@ -112,11 +115,14 @@ def update():
|
||||||
@app.route('/upload', methods=['POST'])
|
@app.route('/upload', methods=['POST'])
|
||||||
def upload():
|
def upload():
|
||||||
file = request.files
|
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())
|
image_string = base64.b64encode(file['file'].read())
|
||||||
payload = {"content": "", "message": "WEB API add file"}
|
payload = {"content": "", "message": "WEB API add file"}
|
||||||
payload['content'] = image_string.decode('UTF-8')
|
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'})
|
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'})
|
||||||
print(resp.json())
|
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ function uploadFile(file) {
|
||||||
let formData = new FormData()
|
let formData = new FormData()
|
||||||
|
|
||||||
formData.append('file', file)
|
formData.append('file', file)
|
||||||
|
formData.append('path', document.getElementById('path').value)
|
||||||
|
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,6 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="/login">login</a>
|
not logged in!
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,12 @@
|
||||||
<span class="navbar-text">
|
<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>
|
Logged in as: {{ user.username }} <span><img width='50px' src='{{ user.avatar_url }}'></span> <a class="nav-link" href="/logout">Logout</a>
|
||||||
</span>
|
</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="navbar-text">
|
||||||
|
<a href="/login">login</a>
|
||||||
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue