socialforge/app/services/users_service.rb

67 lines
2.2 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class UsersService
include ApplicationHelper
include AccountHelper
#将用户注册的功能函数写这里
#参数约定
#成功返回注册后的User实例失败直接抛异常
def register(params)
@user = User.new
@user.admin = false
@user.register
@user.login = params[:login]
@user.mail = params[:mail]
password = params[:password]
password_confirmation = params[:password_confirmation]
should_confirmation_password = params[:should_confirmation_password]
if !password.blank? && !password_confirmation.blank? && should_confirmation_password
@user.password,@user.password_confirmation = password,password_confirmation
elsif !password.blank? && !should_confirmation_password
@user.password = password
else
@user.password = ""
end
case Setting.self_registration
when '1'
@user = email_activation_register(@user)
when '3'
@user = automatically_register(@user)
else
@user = administrator_manually__register(@user)
end
if @user.id != nil
ue = @user.user_extensions ||= UserExtensions.new
ue.user_id = @user.id
ue.save
end
@user
end
#显示用户
#id用户id
def show_user(params)
@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
end