sorcery icon indicating copy to clipboard operation
sorcery copied to clipboard

Should we have a setup_activation method that saves to database?

Open weimeng opened this issue 11 years ago • 3 comments

Just raising this pull request as a discussion to see if we should be adding this behaviour, or leaving it to the individual to implement on their own.

The reason is that when I saw that there was a setup_activation method, I assumed that it also wrote to the database -- but this turned out not to be true.

I added the following instance method:

def setup_activation!
  setup_activation
  sorcery_adapter.save(:validate => false, :raise_on_failure => true)
end

Then I realised I could just have easily did the following in my own project:

user.setup_activation
user.save

Which should we prefer?

weimeng avatar Aug 05 '14 15:08 weimeng

I also just realised that the existing setup_activation method does not also send an activation email along with it. Should we think about doing this?

weimeng avatar Aug 05 '14 16:08 weimeng

Hi @weimeng,

thanks for contribution!

Currently setup_activation is used as a callback and is done before creating user, while sending email is done after user is created. That's why setup_activation does not have sending email itself. The name of this method is therefore quite confusing, because by calling it you probably expect to do everything what's needed, including sending e-mail.

I need to think about good solution. Maybe indeed it's good idea to have the bang method as well. I'll get back to this issue later this week.

arnvald avatar Aug 18 '14 15:08 arnvald

Glad to help! Let me know, I'll be happy to contribute further code to this as I'm using this functionality in a current project.

weimeng avatar Aug 18 '14 16:08 weimeng