Code refactor.

Move authentication to users model. Add pre_commit callback to models
that want to do some validations before commit.