Skip to content

Instantly share code, notes, and snippets.

@jameswritescode
Created November 1, 2016 17:19
Show Gist options
  • Select an option

  • Save jameswritescode/82fad57e16f7eb8f487e30a11b2950ce to your computer and use it in GitHub Desktop.

Select an option

Save jameswritescode/82fad57e16f7eb8f487e30a11b2950ce to your computer and use it in GitHub Desktop.
class CreateUserService
attr_reader :current_user
def initialize(current_user)
@current_user = current_user
end
def execute(user_params)
raise "must be admin" unless current_user.is_admin?
opts = {
force_random_password: true,
password_expires_at: nil
}
user = User.new(user_params.merge(opts))
user.created_by_id = current_user.id
user.generate_password
user.generate_reset_token
user.skip_confirmation!
user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment