socialforge/app/services/users_service.rb

67 lines
2.2 KiB
Ruby
Raw Normal View History

2014-12-03 17:28:19 +08:00
class UsersService
2014-12-09 16:40:52 +08:00
include ApplicationHelper
2014-12-04 15:53:47 +08:00
include AccountHelper
2014-12-03 17:28:19 +08:00
#将用户注册的功能函数写这里
#参数约定
#成功返回注册后的User实例失败直接抛异常
2014-12-04 15:53:47 +08:00
2014-12-03 17:28:19 +08:00
def register(params)
@user = User.new
@user.admin = false
@user.register
@user.login = params[:login]
2014-12-04 15:53:47 +08:00
@user.mail = params[:mail]
password = params[:password]
password_confirmation = params[:password_confirmation]
should_confirmation_password = params[:should_confirmation_password]
2014-12-06 11:27:52 +08:00
if !password.blank? && !password_confirmation.blank? && should_confirmation_password
2014-12-04 15:53:47 +08:00
@user.password,@user.password_confirmation = password,password_confirmation
elsif !password.blank? && !should_confirmation_password
@user.password = password
else
@user.password = ""
2014-12-03 17:28:19 +08:00
end
case Setting.self_registration
when '1'
2014-12-04 15:53:47 +08:00
@user = email_activation_register(@user)
2014-12-03 17:28:19 +08:00
when '3'
2014-12-04 15:53:47 +08:00
@user = automatically_register(@user)
2014-12-03 17:28:19 +08:00
else
2014-12-04 15:53:47 +08:00
@user = administrator_manually__register(@user)
2014-12-03 17:28:19 +08:00
end
if @user.id != nil
ue = @user.user_extensions ||= UserExtensions.new
ue.user_id = @user.id
ue.save
end
@user
end
2014-12-09 16:40:52 +08:00
#显示用户
#id用户id
def show_user
@user = User.find(params[:id])
img_url = url_to_avatar(@user)
gender = user.user_extensions.gender.nil? ? 0 : user.user_extensions.gender
work_unit = ""
if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1
work_unit = @user.user_extensions.school.name unless @user.user_extensions.school.nil?
elsif @user.user_extensions.identity == 3
work_unit = @user.user_extensions.occupation
elsif @user.user_extensions.identity == 2
work_unit = @user.firstname
end
location = ""
location << @user.user_extensions.location
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}
end
#编辑用户
def edit_user params
@user = User.find(params[:id])
file = params[:file]
end
2014-12-03 17:28:19 +08:00
end