parent
65e6444272
commit
11d1cac40d
@ -0,0 +1,37 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
|
||||||
|
module Trustie
|
||||||
|
module Gitlab
|
||||||
|
module Helper
|
||||||
|
def change_password(uid, en_pwd, salt)
|
||||||
|
options = {:encrypted_password=>en_pwd, :password_salt=>salt}
|
||||||
|
self.g.put("/users/ext/#{uid}", :body => options)
|
||||||
|
# g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt)
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_user(user)
|
||||||
|
u = nil
|
||||||
|
begin
|
||||||
|
u = self.g.get("/users?search=#{user.mail}").first
|
||||||
|
unless u
|
||||||
|
u = self.g.create_user(user.mail,
|
||||||
|
user.hashed_password,
|
||||||
|
name: user.show_name,
|
||||||
|
username: user.login,
|
||||||
|
confirm: "true")
|
||||||
|
user.gid = u.id
|
||||||
|
end
|
||||||
|
change_password(u.id, user.hashed_password, user.salt)
|
||||||
|
rescue => e
|
||||||
|
puts e
|
||||||
|
end
|
||||||
|
return u
|
||||||
|
end
|
||||||
|
|
||||||
|
def del_user(user)
|
||||||
|
## gitlab unimplement
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,37 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
#
|
||||||
|
#
|
||||||
|
require_relative 'helper'
|
||||||
|
module Trustie
|
||||||
|
module Gitlab
|
||||||
|
module ManageUser
|
||||||
|
include Helper
|
||||||
|
|
||||||
|
def self.included(base)
|
||||||
|
base.class_eval {
|
||||||
|
before_create :add_gitlab_user
|
||||||
|
before_destroy :delete_gitlab_user
|
||||||
|
before_save :change_gitlab_user
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_gitlab_user
|
||||||
|
add_user(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_gitlab_user
|
||||||
|
del_user(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_gitlab_user
|
||||||
|
change_password(self.gid, self.hashed_password, self.salt)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def g
|
||||||
|
@g ||= ::Gitlab.client
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue