Skip to content

Instantly share code, notes, and snippets.

@duk3luk3
Created September 16, 2013 15:54
Show Gist options
  • Save duk3luk3/6582552 to your computer and use it in GitHub Desktop.
Save duk3luk3/6582552 to your computer and use it in GitHub Desktop.
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