我希望能夠簡單地確定是否在我創建的iOS應用中正確提供了用戶憑據。驗證設計
我現在安裝它的方式是使用會話句柄控制器來處理並返回用戶令牌。問題是如果我還想通過網絡登錄(不只是通過捲曲或類似的檢查),它不驗證和吐出
{「success」:false,「message」:「Error with你的登錄名或密碼「}
所以我的問題是...我怎麼做認證,並仍然保持我的網絡登錄運作?這是我的相關文件。我的希望是我可以捲曲到像localhost:3000/auth_checks這樣的URL,並獲得一種類型的身份驗證響應,並繼續讓我的用戶通過localhost:3000/sign_in登錄。
從devise.rb
config.skip_session_storage = [:http_auth, :token_auth]
config.token_authentication_key = :auth_token
從routes.rb中
resources :clippings
root to: 'clippings#index'
#devise_for :users
resources :auth_checks
devise_for(:users, :controllers => { :sessions => "sessions" })
resources :posts do
end
從auth_checks_controller.rb
class AuthChecksController < ApplicationController
before_filter :authenticate_user!
# GET /auth_checks
# GET /auth_checks.json
def index
@auth_checks = AuthCheck.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @auth_checks }
end
end
# GET /auth_checks/1
# GET /auth_checks/1.json
def show
@auth_check = AuthCheck.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @auth_check }
end
end
# GET /auth_checks/new
# GET /auth_checks/new.json
def new
@auth_check = AuthCheck.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @auth_check }
end
end
# GET /auth_checks/1/edit
def edit
@auth_check = AuthCheck.find(params[:id])
end
# POST /auth_checks
# POST /auth_checks.json
def create
@auth_check = AuthCheck.new(params[:auth_check])
respond_to do |format|
if @auth_check.save
format.html { redirect_to @auth_check, notice: 'Auth check was successfully created.' }
format.json { render json: @auth_check, status: :created, location: @auth_check }
else
format.html { render action: "new" }
format.json { render json: @auth_check.errors, status: :unprocessable_entity }
end
end
end
# PUT /auth_checks/1
# PUT /auth_checks/1.json
def update
@auth_check = AuthCheck.find(params[:id])
respond_to do |format|
if @auth_check.update_attributes(params[:auth_check])
format.html { redirect_to @auth_check, notice: 'Auth check was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @auth_check.errors, status: :unprocessable_entity }
end
end
end
# DELETE /auth_checks/1
# DELETE /auth_checks/1.json
def destroy
@auth_check = AuthCheck.find(params[:id])
@auth_check.destroy
respond_to do |format|
format.html { redirect_to auth_checks_url }
format.json { head :no_content }
end
end
end
試試這個:http://stackoverflow.com/questions/13623562/phonegap-mobile-rails-authentication-devise-authentication-from-scratch/13632264#13632264 – Ashitaka