mirror of
https://github.com/wahyd4/Libr.git
synced 2026-08-23 11:46:02 +10:00
add json API based client login auth
This commit is contained in:
+3
-1
@@ -23,4 +23,6 @@
|
||||
|
||||
/public/assets/**
|
||||
|
||||
/export.md
|
||||
/export.md
|
||||
|
||||
/libr_development
|
||||
@@ -16,6 +16,7 @@ gem 'will_paginate'
|
||||
gem 'nokogiri'
|
||||
gem 'unicorn'
|
||||
gem 'devise'
|
||||
gem 'sqlite3'
|
||||
|
||||
|
||||
gem 'activesupport','4.0.0'
|
||||
|
||||
@@ -170,6 +170,7 @@ GEM
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
sprockets (~> 2.8)
|
||||
sqlite3 (1.3.8)
|
||||
tddium (1.16.2)
|
||||
highline
|
||||
json
|
||||
@@ -229,6 +230,7 @@ DEPENDENCIES
|
||||
selenium-webdriver
|
||||
simplecov
|
||||
slim
|
||||
sqlite3
|
||||
tddium
|
||||
thin
|
||||
unicorn
|
||||
|
||||
@@ -43,7 +43,7 @@ Build Status
|
||||
* 2013.4.16 开始添加微信公共账号feature
|
||||
* 2013.4.17 通过添加go_serv 微信公共账号,输入1 即可获取书籍信息。please give a try.
|
||||
* 2014.1.16 升级到Rails4,并为Libr 2做准备
|
||||
* 开始Libr2, 引入Devise,重新加入用户注册等功能,原有功能基本以不能再使用了。
|
||||
* 2014.1.17 开始Libr2, 引入Devise,重新加入用户注册等功能,原有功能基本以不能再使用了。
|
||||
|
||||
#### JSON API使用指南
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
||||
@@ -0,0 +1,4 @@
|
||||
/*
|
||||
Place all the styles related to the matching controller here.
|
||||
They will automatically be included in application.css.
|
||||
*/
|
||||
@@ -0,0 +1,17 @@
|
||||
class Api::V1::SessionsController < Devise::SessionsController
|
||||
|
||||
def create
|
||||
warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
|
||||
render :json => {:success => true}
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
sign_out(resource_name)
|
||||
end
|
||||
|
||||
def failure
|
||||
render :json => {:success => false, :errors => ["Login Failed"]}
|
||||
end
|
||||
|
||||
end
|
||||
@@ -36,7 +36,7 @@ class BookController < ApplicationController
|
||||
|
||||
def add_to_lib
|
||||
unless @current_user
|
||||
redirect_to '/login', notice: 'You need login to do the action.'
|
||||
redirect_to new_user_session_path, notice: 'You need login to do the action.'
|
||||
return
|
||||
end
|
||||
@current_user.create_book_instance params[:isbn], params[:is_public]
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
module Api::V1::SessionsHelper
|
||||
end
|
||||
+2
-2
@@ -13,7 +13,7 @@
|
||||
# gem 'pg'
|
||||
#
|
||||
development:
|
||||
adapter: postgresql
|
||||
adapter: sqlite3
|
||||
encoding: unicode
|
||||
database: libr_development
|
||||
pool: 5
|
||||
@@ -40,7 +40,7 @@ development:
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
adapter: postgresql
|
||||
adapter: sqlite3
|
||||
encoding: unicode
|
||||
database: libr_test
|
||||
pool: 5
|
||||
|
||||
@@ -222,6 +222,8 @@ Devise.setup do |config|
|
||||
# The "*/*" below is required to match Internet Explorer requests.
|
||||
# config.navigational_formats = ['*/*', :html]
|
||||
|
||||
config.navigational_formats = ["*/*", :html, :json]
|
||||
|
||||
# The default HTTP method used to sign out a resource. Default is :delete.
|
||||
config.sign_out_via = :delete
|
||||
|
||||
|
||||
+11
-1
@@ -39,10 +39,20 @@ Libr::Application.routes.draw do
|
||||
post 'api/books/return' => 'api#return_book'
|
||||
post 'api/books/borrow' => 'api#borrow_book'
|
||||
|
||||
devise_for :users
|
||||
|
||||
#for weixin
|
||||
get 'wx/query' => 'wei_xin#verify'
|
||||
post 'wx/query' => 'wei_xin#query'
|
||||
|
||||
devise_for :users
|
||||
|
||||
namespace :api do
|
||||
namespace :v1 do
|
||||
devise_for :users
|
||||
devise_scope :user do
|
||||
resources :sessions, :only => [:create, :destroy, :failure]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Api::V1::ApiController do
|
||||
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the Api::V1::ApiHelper. For example:
|
||||
#
|
||||
# describe Api::V1::ApiHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
describe Api::V1::SessionsHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Reference in New Issue
Block a user