2020-02-04 06:18:37 +00:00
|
|
|
from flask import Flask, abort, request
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2020-02-05 03:59:31 +00:00
|
|
|
import ldap_functions
|
2020-02-04 06:18:37 +00:00
|
|
|
import secrets
|
|
|
|
|
|
|
|
HTTP_UNAUTHORIZED = 401
|
|
|
|
|
|
|
|
def check_auth():
|
|
|
|
auth_header = request.headers.get('Authorization', '')
|
|
|
|
if auth_header != 'Token ' + secrets.AUTH_TOKEN:
|
|
|
|
abort(HTTP_UNAUTHORIZED)
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def index():
|
|
|
|
return '<i>SEE YOU SPACE SAMURAI...</i>'
|
|
|
|
|
2020-02-05 03:59:31 +00:00
|
|
|
@app.route('/check-username-exists', methods=['GET'])
|
|
|
|
def check_username_exists():
|
|
|
|
check_auth()
|
|
|
|
|
|
|
|
username = request.form['username']
|
|
|
|
|
|
|
|
return ldap_functions.check_username_exists(username)
|
|
|
|
|
2020-02-04 06:18:37 +00:00
|
|
|
@app.route('/create-user', methods=['POST'])
|
|
|
|
def create_user():
|
|
|
|
check_auth()
|
|
|
|
|
|
|
|
first = request.form['first']
|
|
|
|
last = request.form['last']
|
|
|
|
username = request.form['username']
|
|
|
|
email = request.form['email']
|
|
|
|
password = request.form['password']
|
|
|
|
|
2020-02-05 03:59:31 +00:00
|
|
|
ldap_functions.create_user(first, last, username, email, password)
|
2020-02-04 06:18:37 +00:00
|
|
|
return ''
|
|
|
|
|
|
|
|
@app.route('/set-password', methods=['POST'])
|
|
|
|
def set_password():
|
|
|
|
check_auth()
|
|
|
|
|
|
|
|
username = request.form['username']
|
|
|
|
password = request.form['password']
|
|
|
|
|
2020-02-05 03:59:31 +00:00
|
|
|
ldap_functions.set_password(username, password)
|
2020-02-04 06:18:37 +00:00
|
|
|
return ''
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(debug=True, host='0.0.0.0')
|