コード例 #1
0
def request_remove():
    try:
        body = request.json
        if body is None:
            return error_view(400, "invalid JSON in body")

        email = body.get('email')
        if email is None:
            return error_view(400, "invalid email value")

        user_request = UserRequest.get(email)
        user_request.delete()

        return user_request_deleted_view(user_request)

    except ObjectNotFound:
        return error_view(404, "object not found")
コード例 #2
0
def verify_requested_user():
    user_pending = None
    try:
        body = request.json
        if body is None:
            return error_view(400, "invalid JSON in body")

        email = body.get('email')
        if email is None:
            return error_view(400, "invalid email value")

        if not UserRequest.exists(email):
            return error_view(404, "a request with this email not found")

        if User.exists_from_email(email):
            return error_view(500, "a user with this email already exists")

        # switch user request to user pending
        user_request = UserRequest.get(email)
        user_request.delete()

        user_pending = UserPending.new(email)
        user_pending.insert()

        # send mail with token
        # send a mail with the token
        default_channel = Channel.get(Channel.DEFAULT)
        template = INVITE_TEMPLATE
        template.set_format(token=user_pending.token)
        send(user_pending.email, default_channel, template)
        return user_pending_created_view(user_pending)

    except ObjectNotFound as o:
        return error_view(404, str(o))

    except (MailSendingError, TelegramSendingError):
        # in case the mail cannot be sent, abort the invitation and delete the pending user in database
        if user_pending is not None:
            user_pending.delete()

        return error_view(500, f"error sending the invitation")