mirror of
https://github.com/wahyd4/Libr.git
synced 2026-08-09 12:56:14 +10:00
32 lines
840 B
Ruby
32 lines
840 B
Ruby
class Api::V1::SessionsController < Devise::SessionsController
|
|
|
|
|
|
before_filter :allow_cors
|
|
#skip_before_filter :verify_authenticity_token
|
|
|
|
def create
|
|
warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
|
|
render :json => {
|
|
success: true,
|
|
user: {
|
|
id: current_user.id,
|
|
token: current_user.auth_keys.last.value,
|
|
avatar: current_user.avatar,
|
|
name: current_user.preferred_name ? current_user.preferred_name : '匿名',
|
|
email: current_user.email,
|
|
douban_user: current_user.get_douban_user
|
|
}, status: :ok
|
|
|
|
}
|
|
end
|
|
|
|
def destroy
|
|
sign_out(resource_name)
|
|
end
|
|
|
|
def failure
|
|
render :json => {:success => false, :errors => '用户名或者密码错误,请重试'}, status: :forbidden
|
|
end
|
|
|
|
end
|