ADD sync user info api

This commit is contained in:
jasder 2021-04-02 18:18:52 +08:00
parent 02d26df172
commit 50fb8d3983
2 changed files with 24 additions and 3 deletions

View File

@ -4,7 +4,7 @@ class UsersController < ApplicationController
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users]
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users]
before_action :require_login, only: %i[me list]
before_action :require_login, only: %i[me list sync_user_info]
before_action :connect_to_ci_db, only: [:get_user_info]
skip_before_action :check_sign, only: [:attachment_show]
@ -233,6 +233,26 @@ class UsersController < ApplicationController
render_ok
end
def sync_user_info
user = User.find_by_mail params[:email]
return render_forbidden unless user === current_user
sync_params = {
email: params[:email],
password: params[:password]
}
Users::UpdateInfoForm.new(sync_params).validate!
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
if interactor.success?
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_EDIT_INFO)
render_ok
else
render_error(interactor.error)
end
end
private
def load_user
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])

View File

@ -72,12 +72,12 @@ Rails.application.routes.draw do
end
resources :statistic, only: [:index] do
collection do
collection do
get :platform_profile
get :platform_code
get :active_project_rank
get :active_developer_rank
end
end
end
resources :sync_forge, only: [:create] do
collection do
@ -218,6 +218,7 @@ Rails.application.routes.draw do
post :sync_salt
get :trustie_projects
get :trustie_related_projects
post :sync_user_info
scope '/ci', module: :ci do
scope do