Instead of doing this through custom module, you cn use flag module with almost no coding to implement like functionality.