Sha256: 013c8a64aa71146e4e3d8393257ef27d6b9aa211447659a0a521a8c0fbe517aa
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
require_dependency "fwt_push_notification_server/application_controller" require 'digest' module FwtPushNotificationServer class DeviceTokensController < ApplicationController skip_before_filter :authenticate_user!, :if => lambda { if params[:token].blank? || params[:sig].blank? false else token = params[:token] device_name = params[:device_name] device_id = params[:device_id] config = FwtPushNotificationServer.config key = config[:api_key] params_string = "token=#{token}&device_name=#{device_name}&device_id=#{device_id}" !!(Digest::HMAC.hexdigest(params_string, key, Digest::SHA256) == params[:sig]) end } # GET /device_tokens def index @device_tokens = DeviceToken.page.per(100) end # POST /device_tokens def create @device_token = DeviceToken.find_or_create_by_token(params[:token]) @device_token.update_attributes({ :device_id => params[:device_id] || "", :device_name => params[:device_name] || "" }) if @device_token.present? @device_token.save status = 0 else status = -1 end render :json => { :status => status } end private # Only allow a trusted parameter "white list" through. def device_token_params params.permit(:token, :device_id, :device_name, :is_valid, :key, :sig) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fwt_push_notification_server-0.0.6 | app/controllers/fwt_push_notification_server/device_tokens_controller.rb |