socialforge/lib/trustie/gitlab/helper.rb

49 lines
1.2 KiB
Ruby
Raw Normal View History

2015-10-21 17:13:07 +08:00
#coding=utf-8
module Trustie
module Gitlab
module Helper
def change_password(uid, en_pwd, salt)
return unless uid
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
2015-10-21 17:13:07 +08:00
def find_user(user)
us = self.g.get("/users?search=#{user.mail}")
if Array === us
us.each do |u|
return u if u.email == user.mail
2015-11-01 21:49:07 +08:00
end
end
return nil
end
2015-11-01 21:49:07 +08:00
def add_user(user)
u = nil
begin
u = find_user(user)
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
2015-10-21 17:13:07 +08:00
end
return u
end
2015-10-21 17:13:07 +08:00
def del_user(user)
return unless user.gid
self.g.delete_user(user.gid)
end
2015-10-21 17:13:07 +08:00
end
end
end