Exemplo n.º 1
0
def auth_user():
    if session.get('user_id', None) is not None:
        ret_json = calendar_app.error_dict(
            1, "Need to logout before logging in.")
    else:
        in_data = request.get_json()

        if in_data is None:
            ret_json = calendar_app.error_dict(4, "Request malformed.")
        else:
            try:
                ret_json = calendar_app.authorize_user(in_data['username'],
                                                       in_data['password'])

                if ret_json['success']:
                    session['user_id'] = ret_json['user_id']
                    session['user_tz'] = ret_json['tz']

                    ret_json = calendar_app.success_dict('auth', True)
            except (KeyError, TypeError):
                ret_json = calendar_app.error_dict(4, "Request malformed.")
            except Exception:
                ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 2
0
def create_user():
    if session.get('user_id', None) is not None:
        ret_json = calendar_app.error_dict(
            1, "Need to logout before registering new user.")
    else:
        in_data = request.get_json()

        if in_data is None:
            ret_json = calendar_app.error_dict(4, "Request malformed.")
        else:
            try:
                ret_json = calendar_app.add_user(in_data['username'],
                                                 in_data['password'],
                                                 in_data['timezone'])

                if ret_json['success']:
                    session['user_id'] = ret_json['user_id']
                    session['user_tz'] = in_data['timezone']
            except (KeyError, TypeError):
                ret_json = calendar_app.error_dict(
                    4, "Request malformed, missing data.")
            except Exception:
                ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 3
0
def edit_invite(invite_id):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            if request.method == 'POST':
                in_data = request.get_json()

                ret_json = calendar_app.edit_invite(
                    session['user_id'], invite_id,
                    in_data.get('event_name', None),
                    in_data.get('event_description', None),
                    in_data.get('start_time', None),
                    in_data.get('end_time', None),
                    in_data.get('event_timezone', None),
                    in_data.get('all_day_event', None))
            elif request.method == 'GET':
                ret_json = calendar_app.get_invite(session['user_id'],
                                                   session['user_tz'],
                                                   invite_id)
        except (KeyError, TypeError):
            ret_json = calendar_app.error_dict(
                4, "Request malformed. Missing data.")
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 4
0
def get_users_like(like):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            ret_json = calendar_app.get_users(like)
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 5
0
def get_event_guests(event_id):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            ret_json = calendar_app.get_guests(session['user_id'], event_id)
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 6
0
def get_invites(archive):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            ret_json = calendar_app.get_invites(session['user_id'],
                                                session['user_tz'], archive)
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 7
0
def restore_invite_data(invite_id):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            ret_json = calendar_app.restore_invite_event_data(
                session['user_id'], invite_id)
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 8
0
def create_calendar():
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            in_data = request.get_json()

            ret_json = calendar_app.add_calendar(session['user_id'],
                                                 in_data['calendar_name'],
                                                 in_data['calendar_color'])
        except (KeyError, TypeError):
            ret_json = calendar_app.error_dict(4, "Request malformed.")
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 9
0
def change_attendance_for_invite(invite_id):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            in_data = request.get_json()

            ret_json = calendar_app.edit_invite_attendance(
                session['user_id'], invite_id, in_data['attendance'])
        except (KeyError, TypeError):
            ret_json = calendar_app.error_dict(
                4, "Request malformed. Missing data.")
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 10
0
def invite_for_event(event_id):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            in_data = request.get_json()

            ret_json = calendar_app.invite_user(session['user_id'], event_id,
                                                in_data['user_id'], False)
        except (KeyError, TypeError):
            ret_json = calendar_app.error_dict(
                4, "Request malformed. Missing data.")
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 11
0
def share_calendar(calendar_id):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            in_data = request.get_json()

            ret_json = calendar_app.share_calendar(session['user_id'],
                                                   calendar_id,
                                                   in_data['user_id'],
                                                   in_data['write_permission'])
        except (KeyError, TypeError):
            ret_json = calendar_app.error_dict(
                4, "Request malformed, missing data.")
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 12
0
def logout_user():
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before logging out.")
    else:
        session.pop('user_id', None)
        session.pop('user_tz', None)

        ret_json = calendar_app.success_dict('logout', True)

    return jsonify(ret_json)
Exemplo n.º 13
0
def create_event(calendar_id):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            in_data = request.get_json()

            ret_json = calendar_app.add_event(
                session['user_id'], calendar_id, in_data['event_name'],
                in_data['event_description'],
                in_data['start_time'], in_data['end_time'],
                in_data.get('event_timezone', None), in_data['all_day_event'])
        except (KeyError, TypeError) as e:
            ret_json = calendar_app.error_dict(
                4, "Request malformed. Missing data.")
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)
Exemplo n.º 14
0
def edit_delete_share(share_id):
    if session.get('user_id', None) is None:
        ret_json = calendar_app.error_dict(
            1, "Need to log in before performing any action.")
    else:
        try:
            if request.method == 'POST':
                in_data = request.get_json()

                ret_json = calendar_app.edit_share_permission(
                    session['user_id'], share_id, in_data['write_permission'])
            elif request.method == 'DELETE':
                ret_json = calendar_app.delete_share(session['user_id'],
                                                     share_id)
        except (KeyError, TypeError):
            ret_json = calendar_app.error_dict(
                4, "Request malformed. Missing data.")
        except Exception:
            ret_json = calendar_app.error_dict(5, "Server error.")

    return jsonify(ret_json)