Skip to content
Snippets Groups Projects
Commit aee751f7 authored by Jonas Leder's avatar Jonas Leder
Browse files

shows if user is logged in and logout possible

parent f8f8b729
No related branches found
No related tags found
No related merge requests found
Pipeline #42 passed
......@@ -134,23 +134,32 @@ def grecaptcha_verify(request): #This function is used to verify the google reca
@app.route('/', methods=['GET'])
def home_get():
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect) #return the default site to create a new shorten link
try:
userID = request.cookies.get('userID')
loginbar = "Hello " + request.cookies.get('username') + ' (<a href="/logout" style="color:white">logout</a>)'
except:
userID = "null"
loginbar = '<a href="/login" style="color:white">login</a>'
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect, loginbar=loginbar) #return the default site to create a new shorten link
@app.route('/', methods=['POST']) #This function is used to create a new url
def home_post():
if not grecaptcha_verify(request) and not skipCaptcha:
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, snackbar="There was an error validating, that you are a human, please try again.", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect) #return the user the prefilled form with an error message, because no url to short was provided
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, snackbar="There was an error validating, that you are a human, please try again.", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect, loginbar=loginbar) #return the user the prefilled form with an error message, because no url to short was provided
try:
userID = request.cookies.get('userID')
loginbar = "Hello " + request.cookies.get('username') + ' (<a href="/logout" style="color:white">logout</a>)'
except:
userID = "null"
loginbar = '<a href="/login" style="color:white">login</a>'
if (request.form.get('url').replace(" ", "") == ""):
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, snackbar="Please enter a url to short, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect) #return the user the prefilled form with an error message, because no url to short was provided
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, snackbar="Please enter a url to short, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect, loginbar=loginbar) #return the user the prefilled form with an error message, because no url to short was provided
if (request.form.get('short').replace(" ", "") == ""):
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, snackbar="Please enter a short name, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect) #return the user the prefilled form with an error message, because no short link was provided
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, snackbar="Please enter a short name, before submitting this form", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect, loginbar=loginbar) #return the user the prefilled form with an error message, because no short link was provided
shorturl = (request.form.get('domain') + "/" + request.form.get('short')).lower()
url = request.form.get('url')
......@@ -170,9 +179,9 @@ def home_post():
'INSERT INTO WEB_URL (LONG_URL, SHORT_URL, USERNAME) VALUES (?, ?, ?)',
[url, shorturl, userID]
)
return render_template('home.html', short_url=shorturl, recaptchaPublicKey=recaptchaPublicKey, builddate=builddate, version=version, domain=domain_prepared, qrcode=makeQR("http://" + shorturl)) #return the shorten link to the user
return render_template('home.html', short_url=shorturl, recaptchaPublicKey=recaptchaPublicKey, builddate=builddate, version=version, domain=domain_prepared, qrcode=makeQR("http://" + shorturl), loginbar=loginbar) #return the shorten link to the user
else:
return render_template('home.html', builddate=builddate, version=version, recaptchaPublicKey=recaptchaPublicKey, domain=domain_prepared, snackbar="URL already used, please try another one", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], showDomainSelect=showDomainSelect) #return the user the prefilled form with an error message, because the url was already used
return render_template('home.html', builddate=builddate, version=version, recaptchaPublicKey=recaptchaPublicKey, domain=domain_prepared, snackbar="URL already used, please try another one", long_url_prefilled=request.form.get('url'), short_url_prefilled=request.form.get('short').lower(), domain_prefilled=domain_to_index[request.form.get('domain')], showDomainSelect=showDomainSelect, loginbar=loginbar) #return the user the prefilled form with an error message, because the url was already used
@app.route('/favicon.ico') #Redirect to the static url of the favicon
def favicon():
......@@ -216,11 +225,17 @@ def authorized(oauth_token):
userID = str(json.loads(githubResponse)['id'])
username = str(json.loads(githubResponse)['login'])
resp = make_response("Hello " + username + "(" + userID + ")")
resp = make_response(redirect('/'))
resp.set_cookie('userID', userID)
resp.set_cookie('username', username)
return resp
@app.route('/logout')
def logout():
resp = make_response("logout successfull")
resp.set_cookie('userID', "", max_age=0)
resp.set_cookie('username', "", max_age=0)
return resp
if __name__ == '__main__':
table_check()# This code checks whether database table is created or not
......
......@@ -176,6 +176,20 @@ visibility: visible;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
#loginbar {
min-width: 250px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
top: 30px;
right: 16px;
font-size: 17px;
}
@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
......
......@@ -14,6 +14,7 @@
</head>
<body>
<div id="loginbar">{{loginbar | safe}}</div>
<div class="login-page">
<div class="form">
{% if not short_url %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment