it’s not a perfect implementation, but it does its job for me:
https://github.com/paroga/user_discourse