Merge branch 'develop' of http://git.trustie.net/jasder/forgeplus into develop
This commit is contained in:
commit
d4b6b5f802
|
@ -71,13 +71,14 @@ class AccountsController < ApplicationController
|
|||
end
|
||||
|
||||
if sync_params.present?
|
||||
update_gitea = Gitea::User::UpdateService.call("", params[:old_user_login], sync_params)
|
||||
Rails.logger.info("########________update_gitea__________###########__status:_#{update_gitea.status}")
|
||||
interactor = Gitea::User::UpdateInteractor.call(u.login, sync_params)
|
||||
if interactor.success?
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
render_ok({})
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
|
@ -98,20 +99,19 @@ class AccountsController < ApplicationController
|
|||
#修改密码
|
||||
def remote_password
|
||||
@user = User.find_by(login: params[:login])
|
||||
if @user && @user.update_attribute(:password, params[:password])
|
||||
sync_params = {
|
||||
password: params[:password],
|
||||
email: @user.mail
|
||||
}
|
||||
update_gitea = Gitea::User::UpdateService.call("", params[:login], sync_params)
|
||||
return render_error("未找到相关用户!") if @user.blank?
|
||||
|
||||
Rails.logger.info("########________update_gitea___status________###########__status:_#{update_gitea.status}")
|
||||
Rails.logger.info("######________password_update_success____######")
|
||||
sync_params = {
|
||||
password: params[:password].to_s,
|
||||
email: @user.mail
|
||||
}
|
||||
|
||||
render_ok({})
|
||||
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||
if interactor.success?
|
||||
@user.update_attribute(:password, params[:password])
|
||||
render_ok
|
||||
else
|
||||
Rails.logger.info("######________password_update_failed____######")
|
||||
render_error("更新失败")
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -205,6 +205,8 @@ class AccountsController < ApplicationController
|
|||
end
|
||||
|
||||
successful_authentication(@user)
|
||||
# TODO用户密码未同步
|
||||
Gitea::User::UpdateInteractor.call(@user.login, {email: @user.mail, password: password.to_s}) unless @user.is_sync_pwd?
|
||||
|
||||
# session[:user_id] = @user.id
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class UsersController < ApplicationController
|
||||
|
||||
before_action :load_user, only: [:show, :homepage_info, :sync_token]
|
||||
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd]
|
||||
before_action :check_user_exist, only: [:show, :homepage_info]
|
||||
before_action :require_login, only: %i[me list projects]
|
||||
skip_before_action :check_sign, only: [:attachment_show]
|
||||
|
@ -118,6 +118,28 @@ class UsersController < ApplicationController
|
|||
@projects = paginate(scope)
|
||||
end
|
||||
|
||||
# TODO 其他平台登录时同步修改gitea平台对应用户的密码
|
||||
# 该方法主要用于:别的平台初次部署对接forge平台,同步用户后,gitea平台对应的用户密码与forge平台用户密码不一致是问题
|
||||
def sync_gitea_pwd
|
||||
return render_error("未找到相关的用户") if @user.blank?
|
||||
|
||||
sync_params = {
|
||||
email: @user.mail,
|
||||
password: params[:password].to_s
|
||||
}
|
||||
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||
interactor.success? ? render_ok : render_error(interactor.error)
|
||||
end
|
||||
|
||||
# TODO
|
||||
# 同步trusite平台用户的salt信息,只需同步一次,同步完成后,该方法可以删除
|
||||
def sync_salt
|
||||
user = User.find_by_login params[:login]
|
||||
return if user.blank?
|
||||
user.update_column(:salt, params[:salt])
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
def load_user
|
||||
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class Gitea::User::UpdateForm
|
||||
include ActiveModel::Model
|
||||
EMAIL_REGEX = /^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9_\-.]+(\.[a-zA-Z0-9_-]+)+$/
|
||||
|
||||
attr_accessor :username, :email, :admin, :allow_create_organization, :allow_git_hook, :allow_import_local,
|
||||
:full_name, :location, :login_name, :max_repo_creation, :must_change_password, :password, :prohibit_login,
|
||||
:source_id, :website
|
||||
|
||||
validates :username, presence: true
|
||||
validates :email, presence: true, format: { with: EMAIL_REGEX, multiline: true }
|
||||
end
|
|
@ -0,0 +1,49 @@
|
|||
module Gitea::User
|
||||
class UpdateInteractor
|
||||
def self.call(username, params={})
|
||||
interactor = new(username, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(username, params)
|
||||
@username = username
|
||||
@params = params
|
||||
end
|
||||
|
||||
def success?
|
||||
@error.nil?
|
||||
end
|
||||
|
||||
def result
|
||||
@result
|
||||
end
|
||||
|
||||
def run
|
||||
Gitea::User::UpdateForm.new(valid_params).validate!
|
||||
response = Gitea::User::UpdateService.new(username, params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
Rails.logger.info "Exception ===========> #{exception.message}"
|
||||
fail!(exception.message)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
attr_reader :params, :username
|
||||
|
||||
def fail!(error)
|
||||
@error = error
|
||||
end
|
||||
|
||||
def render_result(response)
|
||||
@result = response
|
||||
end
|
||||
|
||||
def valid_params
|
||||
@params.merge(username: username)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,5 @@
|
|||
class Gitea::User::UpdateService < Gitea::ClientService
|
||||
# attr_reader :admin_user, :params
|
||||
attr_reader :token, :old_login, :params
|
||||
attr_reader :edit_username, :params
|
||||
# 只有管理员才能修改用户信息
|
||||
# params:
|
||||
# admin boolean
|
||||
|
@ -18,10 +17,10 @@ class Gitea::User::UpdateService < Gitea::ClientService
|
|||
# source_id integer($int64)
|
||||
# website string
|
||||
|
||||
def initialize(token, old_login, params={})
|
||||
@token = token
|
||||
@params = params
|
||||
@old_login = old_login
|
||||
def initialize(edit_username, params={}, token=nil)
|
||||
@token = token
|
||||
@params = params
|
||||
@edit_username = edit_username
|
||||
end
|
||||
|
||||
def call
|
||||
|
@ -31,7 +30,7 @@ class Gitea::User::UpdateService < Gitea::ClientService
|
|||
private
|
||||
|
||||
def url
|
||||
"/admin/users/#{old_login}"
|
||||
"/admin/users/#{edit_username}"
|
||||
end
|
||||
|
||||
def data_params
|
||||
|
|
|
@ -148,6 +148,8 @@ Rails.application.routes.draw do
|
|||
get :list
|
||||
post :sync_token
|
||||
get :projects
|
||||
post :sync_gitea_pwd
|
||||
post :sync_salt
|
||||
end
|
||||
|
||||
scope module: :users do
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# TODO 该字段用于trusite用户登录时,同步用户密码到gitea平台, 默认为未同步
|
||||
class AddIsSyncPwdToUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :users, :is_sync_pwd, :boolean, :default => true
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue