commit
d3fee9b877
@ -0,0 +1,19 @@
|
||||
# encoding=utf-8
|
||||
module Mobile
|
||||
module Apis
|
||||
class Ecloud < Grape::API
|
||||
# before {authenticate!}
|
||||
content_type :json, 'application/json;charset=UTF-8'
|
||||
|
||||
resources :ecloud do
|
||||
|
||||
desc "ecloud接口测试"
|
||||
|
||||
post 'list' do
|
||||
EcloudService.new.list
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the oauth controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
@ -0,0 +1,2 @@
|
||||
module OauthHelper
|
||||
end
|
@ -0,0 +1,53 @@
|
||||
require 'base64'
|
||||
|
||||
class Oauth < ActiveRecord::Base
|
||||
attr_accessible :client_id, :client_secret, :redirect_uri, :access_token,
|
||||
:refresh_token, :token_created_at,:token_expires_in, :user_id
|
||||
|
||||
belongs_to :user
|
||||
|
||||
def gen_code
|
||||
code = Base64.urlsafe_encode64 Digest::MD5.hexdigest "#{Time.now}-#{Random.new_seed}"
|
||||
update_column(:code, code)
|
||||
code
|
||||
end
|
||||
|
||||
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}"
|
||||
|
||||
self.update_attributes(access_token: access_token,
|
||||
refresh_token: refresh_token,
|
||||
token_created_at: Time.now.to_i,
|
||||
token_expires_in: Time.now.to_i + 24*60*60,
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
def self.code_valid?(code)
|
||||
# 1. 是否存在
|
||||
oauth = Oauth.where(code: code).order("ID desc").first
|
||||
return false unless oauth
|
||||
|
||||
# 2. 是否超过10分钟
|
||||
return false if Time.now.to_i - oauth.created_at.to_i > 10*60
|
||||
|
||||
# 3. 是否有使用过
|
||||
return false if oauth.access_token.present?
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
def self.auth_code(code, client_id, client_secret)
|
||||
Oauth.where(code: code, client_id: client_id, client_secret: client_secret).order('id desc').first
|
||||
end
|
||||
|
||||
def self.auth(access_token)
|
||||
oauth = self.find_by_access_token(access_token)
|
||||
return nil unless oauth
|
||||
oauth.user
|
||||
end
|
||||
|
||||
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class OauthConfig < ActiveRecord::Base
|
||||
attr_accessible :client_id, :client_secret, :redirect_uri, :scope
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
class EcloudService
|
||||
|
||||
def list
|
||||
return {status: 0, message: "test"}
|
||||
end
|
||||
end
|
@ -1,9 +0,0 @@
|
||||
Gitlab.configure do |config|
|
||||
# config.endpoint = 'http://192.168.41.130:3000/trustie/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
|
||||
# config.private_token = 'cK15gUDwvt8EEkzwQ_63' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
|
||||
config.endpoint = 'http://gitfast.trustie.net/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
|
||||
config.private_token = 'fPc_gBmEiSANve8TCfxW' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
|
||||
# Optional
|
||||
# config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
|
||||
# config.sudo = 'user' # username for sudo mode, default: nil
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
class AddForbidCopyToShixun < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :shixuns, :forbid_copy, :boolean, :default => 0
|
||||
# add_column :shixuns, :forbid_copy, :boolean, :default => 0
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,44 @@
|
||||
class CreateOauths < ActiveRecord::Migration
|
||||
def change
|
||||
|
||||
create_table :oauths do |t|
|
||||
t.string :client_id
|
||||
t.string :client_secret
|
||||
t.string :code
|
||||
t.string :redirect_uri
|
||||
t.string :scope
|
||||
|
||||
t.string :access_token
|
||||
t.string :refresh_token
|
||||
t.integer :token_created_at
|
||||
t.integer :token_expires_in #过期时间
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
|
||||
add_column :oauths, :user_id, :integer, default: 0
|
||||
|
||||
add_index :oauths, :user_id
|
||||
|
||||
|
||||
create_table :oauth_configs do |t|
|
||||
t.string :client_id
|
||||
t.string :client_secret
|
||||
t.string :redirect_uri
|
||||
t.string :scope
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
|
||||
OauthConfig.create(
|
||||
client_id: '88d893c5a345313e7b8c6fcf23d3d024ee08d5e41ce120c3448b6eea77d8de30',
|
||||
client_secret: 'e9240cc5fc913741db5aea93f2986a8ea0631bb67f7c00e41e491b95d9619e64',
|
||||
redirect_uri: 'http://localhost:3000/oschina/login_cb',
|
||||
scope: ''
|
||||
)
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,40 @@
|
||||
class AddPassedScoreForUsers < ActiveRecord::Migration
|
||||
def up
|
||||
games = Game.where("final_score = 0 and status = 2 and answer_open = 0 and created_at > '2019-03-09 00:00:00'").includes(:challenge)
|
||||
puts "game_count: #{games.count}"
|
||||
games.find_each do |game|
|
||||
puts "#{game.id}"
|
||||
challenge = game.challenge
|
||||
# 选择题和实践题的分数
|
||||
score = challenge.choose_score
|
||||
user = game.user
|
||||
game.update_column(:final_score, score)
|
||||
# 奖励金币和提供记录
|
||||
grade = Grade.where(:user_id => user.id, :container_id => game.id, :container_type => "Game").first
|
||||
if grade.nil?
|
||||
Grade.create!(:user_id => user.id,
|
||||
:container_id => game.id,
|
||||
:container_type => "Game",
|
||||
:score => score,
|
||||
:created_at => game.end_time || Time.now,
|
||||
:updated_at => game.end_time || Time.now)
|
||||
user.update_column(:grade, (score + user.grade.to_i))
|
||||
end
|
||||
# 经验奖励
|
||||
experience = Experience.where(:user_id => user.id, :container_id => game.id, :container_type => "Game").first
|
||||
if experience.nil?
|
||||
Experience.create!(:user_id => user.id,
|
||||
:container_id => game.id,
|
||||
:container_type => "Game",
|
||||
:score => score,
|
||||
:created_at => game.end_time || Time.now,
|
||||
:updated_at => game.end_time || Time.now)
|
||||
user.update_column(:experience, (score + user.experience.to_i))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe OauthController, :type => :controller do
|
||||
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
FactoryGirl.define do
|
||||
factory :oauth_config do
|
||||
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
FactoryGirl.define do
|
||||
factory :oauth, class: 'Oauths' do
|
||||
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe OauthConfig, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Oauths, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in new issue