Last active
December 23, 2015 06:29
-
-
Save duk3luk3/6593934 to your computer and use it in GitHub Desktop.
This file contains 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
post do | |
authenticated_as_admin! | |
required_attributes! [:email, :name, :username] | |
attrs = attributes_for_keys [:email, :name, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio] | |
#parse password strategy params | |
expired = params[:expired_password] && (params[:expired_password].to_i > 0) | |
force_random = params[:force_random_password] && (params[:force_random_password].to_i > 0) | |
if (params[:password] && !force_random) | |
attrs[:password] = params[:password] | |
elsif (force_random && !params[:password]) | |
attrs[:force_random_password] = true | |
else | |
render_api_error!('400 Either password or force_random_password must be set',400) | |
attrs[:password_expires_at] = Time.now if expired | |
user = User.new attrs, as: :admin | |
user.created_by_id = current_user.id if expired # this is necessary to make the new user notification work correctly. | |
if user.save | |
present user, with: Entities::User | |
else | |
not_found! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment