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

hide domain select, if only one domain is in use

parent c9cf56d9
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ domain_to_index = {}
domain_prepared = ""
builddate = ""
version = ""
showDomainSelect = False
try:
domain = os.environ["domains"].split(";") #Get the domains from the enviorement variable. If no enviorement variable is set set it to 127.0.0.1:5000 (for testing)
......@@ -57,10 +58,13 @@ except:
index = 0
for domains in domain: #Make from every domnain a entry for the select box later
domains = domains
domain_prepared = domain_prepared + '<option value="' + str(domains) + '">' + str(domains) + '</option>'
domain_to_index[domains] = str(index)
index = index + 1
if(index > 1):
showDomainSelect=True #Show only domain select, if there are more than one available
else:
domain_prepared = domain[0]
def table_check():
......@@ -107,19 +111,19 @@ def grecaptcha_verify(request):
@app.route('/', methods=['GET'])
def home_get():
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, recaptchaPublicKey=recaptchaPublicKey) #return the default site to create a new shorten link
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
@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) #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) #return the user the prefilled form with an error message, because no url to short was provided
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) #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) #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) #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) #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')
......@@ -141,7 +145,7 @@ def home_post():
)
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
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')]) #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) #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():
......
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