Rewrote the invitations controller

I think the gist I was following was pretty old. I still have no idea if
this will work.