添加gitlab远程登录接口

This commit is contained in:
nwb 2014-07-16 15:05:16 +08:00
parent 62af03debd
commit 297fe9a3f4
3 changed files with 123 additions and 1 deletions

View File

@ -53,6 +53,7 @@ class UsersController < ApplicationController
include CustomFieldsHelper include CustomFieldsHelper
include AvatarHelper include AvatarHelper
include WordsHelper include WordsHelper
include GitlabHelper
# added by liuping 关注 # added by liuping 关注
@ -362,6 +363,10 @@ class UsersController < ApplicationController
end end
def show def show
# 测试代码
#login_gitlab("admin@local.host","19840410")
# 测试结束
pre_count = 10 #limit pre_count = 10 #limit
case params[:type] case params[:type]
when "1" when "1"

View File

@ -0,0 +1,115 @@
# Gitlab5.3 API操作接口
# Add by nwb
module GitlabHelper
# gitlab版本库数据本地保存的根目录
ROOT_PATH="/home/git/repositories/"
PROJECT_PATH_CUT = 40
# gitlab版本库所在服务器
#REPO_IP_ADDRESS = Setting.repository_domain
REPO_IP_ADDRESS = "http://192.168.137.100"
GITLAB_API = "/api/v3"
def self.gitlab_token=(token)
Thread.current[:gitlab_token] = token
end
# gitlab的登录验证信息
# add by nwb
def self.gitlab_token
Thread.current[:gitlab_token] ||= nil
end
# 登录gitlab
# add by nwb
def login_gitlab(email,password)
url = REPO_IP_ADDRESS + GITLAB_API + "/session"
uri = URI.parse(url)
data = {email:email, password:password}
begin
res = Net::HTTP.post_form(uri, data)
if res.code == '201'
temp = ActiveSupport::JSON.decode(res.body)
gitlab_token= temp['private_token']
return true
else
return false
end
rescue =>err
return false
end
end
# 创建项目
# add by nwb
def create_project(name)
end
# 为指定用户创建版本库
# name版本库名称 user:版本库创建后所属的用户
def create_project_for_user(name,user)
end
# 创建用户
# loginname登录名称 username用户姓名
def create_user (loginname,username,password,email)
end
# 删除用户
def delete_user(user_id)
end
# 给用户添加一个可操作的项目
def add_project_to_user(project_name,user)
end
def post(url, params)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
end
begin
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-Type'] = 'application/json;charset=utf-8'
request['User-Agent'] = 'Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0'
request['X-ACL-TOKEN'] = 'xxx_token'
#request.set_form_data(params)
request.body = params.to_json
response = http.start { |http| http.request(request) }
puts response.body.inspect
return JSON.parse response.body
rescue =>err
return nil
end
end
def get(url, params)
uri = URI.parse(url)
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new uri.host, uri.port
if uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
end
begin
request = Net::HTTP::Get.new uri.request_uri
request['Content-Type'] = 'application/json;charset=utf-8'
request['User-Agent'] = 'Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0'
request['X-ACL-TOKEN'] = 'xxx_token'
response = http.start { |http| http.request request }
puts response.body.inspect
return JSON.parse response.body
rescue =>err
return nil
end
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140714081030) do ActiveRecord::Schema.define(:version => 20140715015540) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -379,6 +379,7 @@ ActiveRecord::Schema.define(:version => 20140714081030) do
t.text "description" t.text "description"
t.datetime "created_on" t.datetime "created_on"
t.integer "user_id", :default => 0 t.integer "user_id", :default => 0
t.integer "is_public", :default => 1
end end
add_index "documents", ["category_id"], :name => "index_documents_on_category_id" add_index "documents", ["category_id"], :name => "index_documents_on_category_id"
@ -768,6 +769,7 @@ ActiveRecord::Schema.define(:version => 20140714081030) do
t.boolean "hidden_repo", :default => false, :null => false t.boolean "hidden_repo", :default => false, :null => false
t.integer "attachmenttype", :default => 1 t.integer "attachmenttype", :default => 1
t.integer "user_id" t.integer "user_id"
t.integer "dts_test", :default => 0
end end
add_index "projects", ["lft"], :name => "index_projects_on_lft" add_index "projects", ["lft"], :name => "index_projects_on_lft"