forked from Gitlink/forgeplus
add: update user image
This commit is contained in:
parent
dc91cd4346
commit
21d4751327
|
@ -773,7 +773,26 @@ class ApplicationController < ActionController::Base
|
|||
def base_url
|
||||
request.base_url
|
||||
end
|
||||
|
||||
def convert_image!
|
||||
@image = params[:image] || user_params[:image]
|
||||
return unless @image.present?
|
||||
max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M
|
||||
if @image.class == ActionDispatch::Http::UploadedFile
|
||||
render_error('请上传文件') if @image.size.zero?
|
||||
render_error('文件大小超过限制') if @image.size > max_size.to_i
|
||||
else
|
||||
image = @image.to_s.strip
|
||||
return render_error('请上传正确的图片') if image.blank?
|
||||
@image = Util.convert_base64_image(image, max_size: max_size.to_i)
|
||||
end
|
||||
rescue Base64ImageConverter::Error => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
|
||||
def avatar_path(object)
|
||||
ApplicationController.helpers.disk_filename(object.class, object.id)
|
||||
end
|
||||
|
||||
private
|
||||
def object_not_found
|
||||
|
|
|
@ -70,25 +70,6 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
|||
end
|
||||
|
||||
private
|
||||
def convert_image!
|
||||
return unless params[:image].present?
|
||||
max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M
|
||||
if params[:image].class == ActionDispatch::Http::UploadedFile
|
||||
@image = params[:image]
|
||||
render_error('请上传文件') if @image.size.zero?
|
||||
render_error('文件大小超过限制') if @image.size > max_size.to_i
|
||||
else
|
||||
image = params[:image].to_s.strip
|
||||
return render_error('请上传正确的图片') if image.blank?
|
||||
@image = Util.convert_base64_image(image, max_size: max_size.to_i)
|
||||
end
|
||||
rescue Base64ImageConverter::Error => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
|
||||
def avatar_path(organization)
|
||||
ApplicationController.helpers.disk_filename(organization.class, organization.id)
|
||||
end
|
||||
|
||||
def organization_params
|
||||
params.permit(:name, :description, :website, :location,
|
||||
|
|
|
@ -6,6 +6,7 @@ class UsersController < ApplicationController
|
|||
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard]
|
||||
before_action :require_login, only: %i[me list sync_user_info]
|
||||
before_action :connect_to_ci_db, only: [:get_user_info]
|
||||
before_action :convert_image!, only: [:update]
|
||||
skip_before_action :check_sign, only: [:attachment_show]
|
||||
|
||||
def connect_to_ci_db(options={})
|
||||
|
@ -73,7 +74,8 @@ class UsersController < ApplicationController
|
|||
|
||||
def update
|
||||
return render_not_found unless @user = User.find_by_id(params[:id]) || User.find_by(login: params[:id])
|
||||
@user.attributes = user_params
|
||||
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
|
||||
@user.attributes = user_params.except(:image)
|
||||
if @user.save
|
||||
render_ok
|
||||
else
|
||||
|
@ -278,7 +280,7 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:nickname,
|
||||
params.require(:user).permit(:nickname, :image,
|
||||
user_extension_attributes: [
|
||||
:gender, :location, :location_city,
|
||||
:occupation, :technical_title,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!--
|
||||
* @Date: 2021-03-01 10:35:21
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-05-31 18:39:17
|
||||
* @LastEditTime: 2021-06-01 10:06:08
|
||||
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
|
||||
-->
|
||||
# Users
|
||||
|
@ -67,6 +67,7 @@ await octokit.request('PATCH/PUT /api/users/:login.json')
|
|||
参数 | 类型 | 字段说明
|
||||
--------- | ----------- | -----------
|
||||
|user.nickname |string |用户昵称 |
|
||||
|user.image |string/file |用户头像 |
|
||||
|user.user_extension_attributes.gender |int |性别, 0男 1女 |
|
||||
|user.user_extension_attributes.province |string |省份 |
|
||||
|user.user_extension_attributes.city |string |城市 |
|
||||
|
|
|
@ -53,7 +53,7 @@ class Projects::ListMyQuery < ApplicationQuery
|
|||
|
||||
q = projects.ransack(name_or_identifier_cont: params[:search])
|
||||
|
||||
scope = q.result.includes(:project_category, :project_language,:owner, :repository)
|
||||
scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users)
|
||||
|
||||
sort = params[:sort_by] || "updated_on"
|
||||
sort_direction = params[:sort_direction] || "desc"
|
||||
|
|
|
@ -614,7 +614,7 @@ Success — a happy kitten is an authenticated kitten!
|
|||
<!--
|
||||
* @Date: 2021-03-01 10:35:21
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-05-31 18:39:17
|
||||
* @LastEditTime: 2021-06-01 10:06:08
|
||||
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
|
||||
-->
|
||||
<h1 id='users'>Users</h1><h2 id='1ae74893b1'>获取当前登陆用户信息</h2>
|
||||
|
@ -700,6 +700,11 @@ Success — a happy kitten is an authenticated kitten!
|
|||
<td>用户昵称</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>user.image</td>
|
||||
<td>string/file</td>
|
||||
<td>用户头像</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>user.user_extension_attributes.gender</td>
|
||||
<td>int</td>
|
||||
<td>性别, 0男 1女</td>
|
||||
|
|
Loading…
Reference in New Issue