个人信息修改接口

This commit is contained in:
z9hang 2014-12-10 11:21:23 +08:00
parent c054852b4e
commit 7efd2375ff
1 changed files with 45 additions and 1 deletions

View File

@ -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