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

added option to disable login

parent 560f7269
Branches
Tags
No related merge requests found
......@@ -16,7 +16,8 @@ services:
- recaptcha_private= #Please enter here your private Key for google recaptcha
- recaptcha_public= #Please enter here your public Key for google recaptcha
- host=0.0.0.0 #With this variable you can set the access ip range. 127.0.0.1 means you can only access it from the local network and 0.0.0.0 means everyone can access it.
- GITHUB_CLIENT_ID= #You have to set these four variables, if not the shorter will not run. To get the github keys visit https://github.com/settings/developers and register a new oauth application. The callback path is /user/github-callback
- login=1 #set this to 0 if you want to disable the oauth login. If you do so, you also don't have to fill in the oauth credentials below.
- GITHUB_CLIENT_ID= #To get the github keys visit https://github.com/settings/developers and register a new oauth application. The callback path is /user/github-callback
- GITHUB_CLIENT_SECRET=
- GOOGLE_CLIENT_ID=
- GOOGLE_CLIENT_SECRET=
......
from flask import render_template, abort
def home(request, builddate, version, domain_prepared, recaptchaPublicKey, showDomainSelect, cookieNotice, domain_to_index, s):
def home(request, builddate, version, domain_prepared, recaptchaPublicKey, showDomainSelect, cookieNotice, domain_to_index, s, loginEnabled):
try:
loginbar = "Hello " + s.loads(request.cookies.get('username')) + ' (<a href="/user/links" style="color:white">your links</a>, <a href="/user/logout" style="color:white">logout</a>)'
except:
loginbar = '<a href="#" onClick="showLogin()" style="color:white">login</a>'
try:
return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect, loginbar=loginbar, cookieNotice=cookieNotice ,domain_prefilled=domain_to_index[request.headers["host"]]) #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, loginbar=loginbar, cookieNotice=cookieNotice ,domain_prefilled=domain_to_index[request.headers["host"]], loginEnabled=loginEnabled) #return the default site to create a new shorten link
except:
abort(500)
\ No newline at end of file
#!/usr/bin/env python3
#Import os Libraries
from waitress import serve #Used as webserver (Production)
from flask import Flask, request, redirect, make_response #Used to prepare the dynamic pages
from flask import Flask, request, redirect, make_response, abort #Used to prepare the dynamic pages
from os import environ #Used for getting the enviorement variables
from itsdangerous import URLSafeSerializer #used for signing the cookies
from random import choice#used for signing the cookies
......@@ -77,14 +77,21 @@ try:
except:
host="127.0.0.1"
try: #Try to get the oauth keys, if it fails, abort and print a message to console
GITHUB_CLIENT_ID = environ['GITHUB_CLIENT_ID']
GITHUB_CLIENT_SECRET = environ['GITHUB_CLIENT_SECRET']
GOOGLE_CLIENT_ID = environ['GOOGLE_CLIENT_ID']
GOOGLE_CLIENT_SECRET = environ['GOOGLE_CLIENT_SECRET']
try:
if(environ["login"] == "1"): loginEnabled = True
else: loginEnabled = False
except:
print("please set the oauth keys and run again.")
exit()
loginEnabled = False
if(loginEnabled):
try: #Try to get the oauth keys, if it fails, abort and print a message to console
GITHUB_CLIENT_ID = environ['GITHUB_CLIENT_ID']
GITHUB_CLIENT_SECRET = environ['GITHUB_CLIENT_SECRET']
GOOGLE_CLIENT_ID = environ['GOOGLE_CLIENT_ID']
GOOGLE_CLIENT_SECRET = environ['GOOGLE_CLIENT_SECRET']
except:
print("please set the oauth keys and run again.")
exit()
try: #check, if admin wants to show a cookie notice to the user.
if(environ["cookieNotice"] == 1):
......@@ -122,7 +129,7 @@ else:
@app.route('/', methods=['GET'])
def home_get():
return home(request, builddate, version, domain_prepared, recaptchaPublicKey, showDomainSelect, cookieNotice, domain_to_index, s)
return home(request, builddate, version, domain_prepared, recaptchaPublicKey, showDomainSelect, cookieNotice, domain_to_index, s, loginEnabled)
@app.route('/', methods=['POST']) #This function is used to create a new url
def home_post():
......@@ -139,16 +146,18 @@ def redirect_short_url(short_url):
@app.route('/user/login')
def loginPage():
return login(request, GITHUB_CLIENT_ID, cookieNotice, GOOGLE_CLIENT_ID, url_scheme, domain)
if(loginEnabled): return login(request, GITHUB_CLIENT_ID, cookieNotice, GOOGLE_CLIENT_ID, url_scheme, domain)
else: abort(404)
@app.route("/user/google-callback")
def authorizeGoogle():
return googleCallback(request, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, url_scheme, domain, s)
if(loginEnabled): return googleCallback(request, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, url_scheme, domain, s)
else: abort(404)
@app.route('/user/github-callback') #Github redirects to this link after the user authenticated. Then we use the Token we get from github and request via the github api the username and the userid
def authorizeGithub():
return githubCallback(request, GITHUB_CLIENT_SECRET, GITHUB_CLIENT_ID, s)
if(loginEnabled): return githubCallback(request, GITHUB_CLIENT_SECRET, GITHUB_CLIENT_ID, s)
else: abort(404)
@app.route('/user/logout')
def logout():
......@@ -163,11 +172,13 @@ def redirectOwnLinks():
@app.route('/user/links<pageNumber>')#This function gives the user the posibility to see and delete his links
def ownLinks(pageNumber):
return userProfile(request, cookieNotice, s, pageNumber, url_scheme)
if(loginEnabled): return userProfile(request, cookieNotice, s, pageNumber, url_scheme)
else: abort(404)
@app.route('/user/delete') #This function is called if a user deletes an entrie
def delete():
return deleteLink(request, s)
if(loginEnabled): return deleteLink(request, s)
else: abort(404)
@app.route('/user/makeqr', methods=['POST'])
def makeQrCode():
......
......@@ -19,7 +19,9 @@
</head>
<body>
{% if loginEnabled %}
<div id="loginbar">{{loginbar | safe}}</div>
{% endif %}
<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.
Please register or to comment