Ejemplo n.º 1
0
def change_password():
    response = request.Response()
    data = forms.get_form_data()
    if "old" not in data or "new" not in data:
        login_failure(response)
        return

    session = get_session()
    user_id = session["user_id"]
    user = database.get_user_by_id(user_id)

    current = user["password"]
    salt = user["salt"]
    maybe = data["old"]
    correct_pw = hashing.check_hash(maybe, salt, current)

    if not correct_pw:
        login_failure(response)
        return

    hash_data = hashing.generate_hash(data["new"])
    database.update_password(user_id, hash_data)

    response.data = "success"
    response.send()
Ejemplo n.º 2
0
def auth_test():
    response = request.Response()
    if is_authenticated():
        response.data = "Logged in"
    else:
        response.data = "Not logged in"
    response.send()
Ejemplo n.º 3
0
def login():
    response = request.Response()

    data = forms.get_form_data()
    if "username" not in data or "password" not in data:
        login_failure(response)
        return

    username = data["username"]
    password = data["password"]

    user = database.get_user_by_name(username)
    if not user:
        login_failure(response)
        return

    known = user["password"]
    salt = user["salt"]
    password = data["password"]
    success = hashing.check_hash(password, salt, known)

    if not success:
        login_failure(response)
        return

    new_session(response, user)
Ejemplo n.º 4
0
def meetings_actions():
    method = environ['REQUEST_METHOD']
    if method == 'GET':
        get_all_meetings()
    elif method == 'POST':
        create_meeting()
    else:
        res = request.Response()
        res.status = 400
        res.data = 'Bad request'
        res.send()
Ejemplo n.º 5
0
def get_all_meetings():
    meetings = zoom.get_meetings()
    resp_meetings = []

    for meeting in meetings:
        formatted = _meeting_to_ember(meeting)
        resp_meetings.append(formatted)

    response = request.Response()
    response.data = {'data': resp_meetings}
    response.send()
Ejemplo n.º 6
0
def create_meeting():
    response = request.Response()
    req_data = forms.get_form_data()

    if 'data' not in req_data or 'attributes' not in req_data['data']:
        _create_failure(response)
        return
    data = req_data['data']['attributes']

    if 'topic' not in data or 'start-time' not in data:
        _create_failure(response)
        return

    topic = data['topic']
    start = data['start-time']
    new_meeting = zoom.create_meeting(topic=topic, start_string=start)
    response.data = {'data': _meeting_to_ember(new_meeting)}
    response.send()
Ejemplo n.º 7
0
#!/usr/bin/env python3

from sys import path
# gives us access to the non-public facing modules
path.append("../private")

import request
import auth
import meetings
import re
from os import environ

response = request.Response()

unauth_routes = {
    "^/api/login/?$": auth.login,
    "^/api/auth-test/?$": auth.auth_test,
}

auth_routes = {
    "^/api/update-pass/?$": auth.change_password,
    "^/api/meetings": meetings.meetings_actions,
}


def find_handler(routes, url):
    for route, handler in routes.items():
        if re.match(route, url):
            return handler
    return False
Ejemplo n.º 8
0
def get_single_meeting():
    response = request.Response()
    request.status = 500
    request.data = 'not implemented yet'
    request.send()