ADD 其他平台(如trusitie平台)登录后将用户密码同步到gitea平台对应的用户

This commit is contained in:
Jasder 2020-04-22 15:59:40 +08:00
parent 3dbdb5ead4
commit 3b6cbacbd1
2 changed files with 15 additions and 1 deletions

View File

@ -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,19 @@ 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
private
def load_user
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])

View File

@ -148,6 +148,7 @@ Rails.application.routes.draw do
get :list
post :sync_token
get :projects
post :sync_gitea_pwd
end
scope module: :users do