class UsersService 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 end