Created
November 1, 2016 17:19
-
-
Save jameswritescode/82fad57e16f7eb8f487e30a11b2950ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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