Created
September 16, 2013 15:54
-
-
Save duk3luk3/6582552 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) | |
#check params set properly | |
if !(force_random ^ params[:password].present?) | |
render_api_error!('400 Either password or force_random must be set',400) | |
end | |
attrs[:password_expires_at] = Time.now if expired | |
if force_random | |
attrs[:force_random_password] = true | |
else | |
attrs[:password] = params[:password] | |
end | |
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