From e1d0dc46614ad472a383948c89827093712ed29a Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Mon, 3 Dec 2018 09:06:31 +0800 Subject: [PATCH] =?UTF-8?q?token=E5=8E=BB=E9=99=A4session=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/oauth_controller.rb | 7 ++++--- app/models/oauth.rb | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index 7a21b11ba..c8be77e45 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -4,7 +4,7 @@ class OauthController < ApplicationController include ApplicationHelper before_filter :user_setup - before_filter :require_login, only: [:authorize, :token] + before_filter :require_login, only: [:authorize] skip_before_filter :verify_authenticity_token, only: [:token] @@ -49,7 +49,8 @@ class OauthController < ApplicationController ## 检查通过,生成code oauth = Oauth.create!(client_id: config.client_id, client_secret: config.client_secret, - redirect_uri: config.redirect_uri + redirect_uri: config.redirect_uri, + user_id: User.current.id ) code = oauth.gen_code @@ -110,7 +111,7 @@ class OauthController < ApplicationController ## 生成 token # - oauth.gen_token(User.current.id) + oauth.gen_token oauth.reload diff --git a/app/models/oauth.rb b/app/models/oauth.rb index 163ff3e34..d00c798aa 100644 --- a/app/models/oauth.rb +++ b/app/models/oauth.rb @@ -14,7 +14,7 @@ class Oauth < ActiveRecord::Base code end - def gen_token(user_id) + def gen_token access_token = Digest::MD5.hexdigest "#{Time.now}-#{Random.new_seed}" refresh_token = Digest::MD5.hexdigest "#{Random.new_seed}-#{Time.now}-#{Random.new_seed}" @@ -22,7 +22,6 @@ class Oauth < ActiveRecord::Base refresh_token: refresh_token, token_created_at: Time.now.to_i, token_expires_in: Time.now.to_i + 24*60*60, - user_id: user_id ) end