Class: Auth::EndpointsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Auth::EndpointsController
- Includes:
- Concerns::DeviseConcern
- Defined in:
- app/controllers/auth/endpoints_controller.rb
Constant Summary collapse
- CONDITIONS_FOR_TOKEN_AUTH =
[:create,:update,:destroy,:edit,:new,:index]
- TCONDITIONS =
{:only => CONDITIONS_FOR_TOKEN_AUTH}
Instance Method Summary collapse
- #create ⇒ Object
-
#json ⇒ Object
responds only to json.
- #permitted_params ⇒ Object
Methods inherited from ApplicationController
#authenticate_resource!, #build_model_from_params, #check_for_create, #check_for_destroy, #check_for_update, #from_bson, #from_view, #get_model_class_name, #instantiate_classes, #not_found
Instance Method Details
#create ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/auth/endpoints_controller.rb', line 16 def create or_clause = [] or_clause << { "android_token" => @model.android_token } if @model.android_token or_clause << { "ios_token" => @model.ios_token } if @model.ios_token if or_clause.empty? returned_document = nil else returned_document = @model.class.where({ "$or" => or_clause }).find_one_and_update( { "$setOnInsert" => @model.attributes, }, { :upsert => true, :return_document => :after } ) if returned_document returned_document.set_android_endpoint returned_document.set_ios_endpoint end end respond_to do |format| if returned_document format.json do render json: returned_document.to_json, status: 201 end else format.json do render json: { }.to_json, status: 422 end end end end |
#json ⇒ Object
responds only to json. got to add the thing to subscribe them to a topic as well.
5 |
# File 'app/controllers/auth/endpoints_controller.rb', line 5 respond_to :json |
#permitted_params ⇒ Object
67 68 69 |
# File 'app/controllers/auth/endpoints_controller.rb', line 67 def permitted_params params.permit({:endpoint => [:android_token,:ios_token]},:api_key,:current_app_id) end |