From 7efd2375ff940cb74e3aef6a7bcdd22f6cad9e83 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 10 Dec 2014 11:21:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/users_service.rb | 46 ++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 17ecc1598..cd955e18d 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -1,6 +1,7 @@ class UsersService include ApplicationHelper include AccountHelper + include AvatarHelper #将用户注册的功能函数写这里 #参数约定 #成功返回注册后的User实例,失败直接抛异常 @@ -60,7 +61,50 @@ class UsersService #编辑用户 def edit_user params @user = User.find(params[:id]) - file = params[:file] + fileio = params[:file] + @se = @user.extensions + if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1 + @se.school_id = params[:occupation] + elsif @user.user_extensions.identity == 3 + @se.occupation = params[:occupation] + elsif @user.user_extensions.identity == 2 + @user.firstname = params[:occupation] + end + @se.brief_introduction = params[:brief_introduction] + @se.gender = params[:gender] + @se.location = params[:province] if params[:province] + @se.location_city = params[:city] if params[:city] + if @se.save + unless fileio.nil? + file = fileio[:tempfile] + diskfile=disk_filename(@user.class.to_s,@user.id) + @image_file = fileio[:name] + @urlfile='/' << File.join("images","avatars",avatar_directory(@user.class.to_s),avatar_filename(@user.id,@image_file)) + + path = File.dirname(diskfile) + unless File.directory?(path) + FileUtils.mkdir_p(path) + end + File.rename(file.path, @urlfile) + begin + f = Magick::ImageList.new(diskfile) + # gif格式不再做大小处理 + if f.format != 'GIF' + width = 300.0 + proportion = (width/f[0].columns) + height = (f[0].rows*proportion) + f.resize_to_fill!(width,height) + f.write(diskfile) + end + + rescue Exception => e + logger.error "[Error] avatar : users_service#edit_user ===> #{e}" + end + end + return true + else + @se + end end end