2015-10-21 17:13:07 +08:00
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
module Trustie
|
|
|
|
module Gitlab
|
|
|
|
module Helper
|
|
|
|
def change_password(uid, en_pwd, salt)
|
2015-11-01 21:49:07 +08:00
|
|
|
return unless uid
|
2015-10-21 17:13:07 +08:00
|
|
|
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-11-01 21:49: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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2015-10-21 17:13:07 +08:00
|
|
|
def add_user(user)
|
|
|
|
u = nil
|
|
|
|
begin
|
2015-11-01 21:49:07 +08:00
|
|
|
u = find_user(user)
|
2015-10-21 17:13:07 +08:00
|
|
|
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)
|
2015-11-01 21:49:07 +08:00
|
|
|
return unless user.gid
|
|
|
|
self.g.delete_user(user.gid)
|
2015-10-21 17:13:07 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|