修改用户个人信息
This commit is contained in:
parent
7efd2375ff
commit
70bc6acbd2
11
Gemfile.lock
11
Gemfile.lock
|
@ -130,6 +130,7 @@ GEM
|
||||||
htmlentities (4.3.2)
|
htmlentities (4.3.2)
|
||||||
i18n (0.6.1)
|
i18n (0.6.1)
|
||||||
ice_nine (0.11.0)
|
ice_nine (0.11.0)
|
||||||
|
iconv (1.0.4)
|
||||||
journey (1.0.4)
|
journey (1.0.4)
|
||||||
jquery-rails (2.0.3)
|
jquery-rails (2.0.3)
|
||||||
railties (>= 3.1.0, < 5.0)
|
railties (>= 3.1.0, < 5.0)
|
||||||
|
@ -185,6 +186,8 @@ GEM
|
||||||
pry-remote (0.1.8)
|
pry-remote (0.1.8)
|
||||||
pry (~> 0.9)
|
pry (~> 0.9)
|
||||||
slop (~> 3.0)
|
slop (~> 3.0)
|
||||||
|
puma (2.10.1)
|
||||||
|
rack (>= 1.1, < 2.0)
|
||||||
rack (1.4.5)
|
rack (1.4.5)
|
||||||
rack-accept (0.4.5)
|
rack-accept (0.4.5)
|
||||||
rack (>= 0.4)
|
rack (>= 0.4)
|
||||||
|
@ -233,6 +236,7 @@ GEM
|
||||||
sass-rails
|
sass-rails
|
||||||
rmagick (2.13.2)
|
rmagick (2.13.2)
|
||||||
ruby-openid (2.1.8)
|
ruby-openid (2.1.8)
|
||||||
|
ruby-prof (0.15.2)
|
||||||
rubyzip (1.1.6)
|
rubyzip (1.1.6)
|
||||||
sass (3.3.10)
|
sass (3.3.10)
|
||||||
sass-rails (3.2.6)
|
sass-rails (3.2.6)
|
||||||
|
@ -283,6 +287,8 @@ GEM
|
||||||
win32console (1.3.2-x86-mingw32)
|
win32console (1.3.2-x86-mingw32)
|
||||||
xpath (2.0.0)
|
xpath (2.0.0)
|
||||||
nokogiri (~> 1.3)
|
nokogiri (~> 1.3)
|
||||||
|
zip-zip (0.3)
|
||||||
|
rubyzip (>= 1.0.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
@ -306,6 +312,7 @@ DEPENDENCIES
|
||||||
guard-test (~> 1.0.0)
|
guard-test (~> 1.0.0)
|
||||||
htmlentities
|
htmlentities
|
||||||
i18n (~> 0.6.0)
|
i18n (~> 0.6.0)
|
||||||
|
iconv
|
||||||
jquery-rails (~> 2.0.2)
|
jquery-rails (~> 2.0.2)
|
||||||
kaminari
|
kaminari
|
||||||
mocha (~> 1.1.0)
|
mocha (~> 1.1.0)
|
||||||
|
@ -316,12 +323,15 @@ DEPENDENCIES
|
||||||
pry-byebug
|
pry-byebug
|
||||||
pry-rails
|
pry-rails
|
||||||
pry-remote
|
pry-remote
|
||||||
|
puma
|
||||||
rack-mini-profiler!
|
rack-mini-profiler!
|
||||||
rack-openid
|
rack-openid
|
||||||
rails (= 3.2.13)
|
rails (= 3.2.13)
|
||||||
rich (= 1.4.6)
|
rich (= 1.4.6)
|
||||||
rmagick (>= 2.0.0)
|
rmagick (>= 2.0.0)
|
||||||
ruby-openid (~> 2.1.4)
|
ruby-openid (~> 2.1.4)
|
||||||
|
ruby-prof (~> 0.15.1)
|
||||||
|
rubyzip
|
||||||
sass-rails (~> 3.2.3)
|
sass-rails (~> 3.2.3)
|
||||||
seems_rateable!
|
seems_rateable!
|
||||||
selenium-webdriver (~> 2.42.0)
|
selenium-webdriver (~> 2.42.0)
|
||||||
|
@ -329,3 +339,4 @@ DEPENDENCIES
|
||||||
spork-testunit (~> 0.0.8)
|
spork-testunit (~> 0.0.8)
|
||||||
therubyracer
|
therubyracer
|
||||||
uglifier (>= 1.0.3)
|
uglifier (>= 1.0.3)
|
||||||
|
zip-zip
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Mobile
|
||||||
API.logger
|
API.logger
|
||||||
end
|
end
|
||||||
|
|
||||||
def authticate!
|
def authenticate!
|
||||||
error!('Unauthorized. Invalid or expired token.', 401) unless current_user
|
error!('Unauthorized. Invalid or expired token.', 401) unless current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,27 @@ module Mobile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
desc "modify user"
|
||||||
|
params do
|
||||||
|
#optional :file, type: File, desc: 'avatar'
|
||||||
|
optional :occupation, type: String
|
||||||
|
optional :brief_introduction, type: String
|
||||||
|
optional :province, type: String
|
||||||
|
optional :city, type: String
|
||||||
|
optional :gender, type: Integer
|
||||||
|
end
|
||||||
|
put ':id' do
|
||||||
|
authenticate!
|
||||||
|
us = UsersService.new
|
||||||
|
begin
|
||||||
|
ue = us.edit_user params
|
||||||
|
{status: 0, data: ue}
|
||||||
|
rescue => e
|
||||||
|
{status: 1, message: e.message}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ class UsersService
|
||||||
password_confirmation = params[:password_confirmation]
|
password_confirmation = params[:password_confirmation]
|
||||||
should_confirmation_password = params[:should_confirmation_password]
|
should_confirmation_password = params[:should_confirmation_password]
|
||||||
if !password.blank? && !password_confirmation.blank? && should_confirmation_password
|
if !password.blank? && !password_confirmation.blank? && should_confirmation_password
|
||||||
@user.password,@user.password_confirmation = password,password_confirmation
|
@user.password, @user.password_confirmation = password, password_confirmation
|
||||||
elsif !password.blank? && !should_confirmation_password
|
elsif !password.blank? && !should_confirmation_password
|
||||||
@user.password = password
|
@user.password = password
|
||||||
else
|
else
|
||||||
|
@ -42,7 +42,7 @@ class UsersService
|
||||||
#id用户id
|
#id用户id
|
||||||
def show_user(params)
|
def show_user(params)
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
img_url = url_to_avatar(@user)
|
img_url = url_to_avatar(@user)
|
||||||
gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender
|
gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender
|
||||||
work_unit = ""
|
work_unit = ""
|
||||||
if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1
|
if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1
|
||||||
|
@ -55,7 +55,7 @@ class UsersService
|
||||||
location = ""
|
location = ""
|
||||||
location << (@user.user_extensions.location || '')
|
location << (@user.user_extensions.location || '')
|
||||||
location << (@user.user_extensions.location_city || '')
|
location << (@user.user_extensions.location_city || '')
|
||||||
{:id => @user.id,:img_url =>img_url,:nickname => @user.login,:gender => gender,:work_unit => work_unit,:mail => @user.mail,:location => location,:brief_introduction => @user.user_extensions.brief_introduction}
|
{:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction}
|
||||||
end
|
end
|
||||||
|
|
||||||
#编辑用户
|
#编辑用户
|
||||||
|
@ -75,36 +75,33 @@ class UsersService
|
||||||
@se.gender = params[:gender]
|
@se.gender = params[:gender]
|
||||||
@se.location = params[:province] if params[:province]
|
@se.location = params[:province] if params[:province]
|
||||||
@se.location_city = params[:city] if params[:city]
|
@se.location_city = params[:city] if params[:city]
|
||||||
if @se.save
|
raise @se.errors.full_message unless @se.save
|
||||||
unless fileio.nil?
|
unless fileio.nil?
|
||||||
file = fileio[:tempfile]
|
file = fileio[:tempfile]
|
||||||
diskfile=disk_filename(@user.class.to_s,@user.id)
|
diskfile=disk_filename(@user.class.to_s, @user.id)
|
||||||
@image_file = fileio[:name]
|
@image_file = fileio[:name]
|
||||||
@urlfile='/' << File.join("images","avatars",avatar_directory(@user.class.to_s),avatar_filename(@user.id,@image_file))
|
@urlfile='/' << File.join("images", "avatars", avatar_directory(@user.class.to_s), avatar_filename(@user.id, @image_file))
|
||||||
|
|
||||||
path = File.dirname(diskfile)
|
path = File.dirname(diskfile)
|
||||||
unless File.directory?(path)
|
unless File.directory?(path)
|
||||||
FileUtils.mkdir_p(path)
|
FileUtils.mkdir_p(path)
|
||||||
end
|
end
|
||||||
File.rename(file.path, @urlfile)
|
File.rename(file.path, @urlfile)
|
||||||
begin
|
begin
|
||||||
f = Magick::ImageList.new(diskfile)
|
f = Magick::ImageList.new(diskfile)
|
||||||
# gif格式不再做大小处理
|
# gif格式不再做大小处理
|
||||||
if f.format != 'GIF'
|
if f.format != 'GIF'
|
||||||
width = 300.0
|
width = 300.0
|
||||||
proportion = (width/f[0].columns)
|
proportion = (width/f[0].columns)
|
||||||
height = (f[0].rows*proportion)
|
height = (f[0].rows*proportion)
|
||||||
f.resize_to_fill!(width,height)
|
f.resize_to_fill!(width, height)
|
||||||
f.write(diskfile)
|
f.write(diskfile)
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
logger.error "[Error] avatar : users_service#edit_user ===> #{e}"
|
logger.error "[Error] avatar : users_service#edit_user ===> #{e}"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
else
|
|
||||||
@se
|
|
||||||
end
|
end
|
||||||
|
@se
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue