diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index e7273b94..e4a51b26 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -2967,7 +2967,7 @@ end member = course.course_members.where(:user_id => user.id, :role => member_role).first # 如果已是课堂成员且是学生身份and不在指定的分班则移动到该分班 if member.present? && member.role == 4 && member.course_group_id != course_group.try(:id).to_i - member.update_column("course_group_id", course_group.try(:id).to_i) + member.update_attributes(course_group_id: course_group.try(:id).to_i) member_count += 1 elsif !member.present? member = CourseMember.new(:role => member_role, :user_id => user.id) @@ -2988,9 +2988,9 @@ end @status = 1 @message = "已导入/更新#{member_count}个成员" end - rescue + rescue Exception => e @status = 0 - @message = "文件内容无法读取" + @message = e.message end else @status = 0 @@ -3032,18 +3032,12 @@ end # 用户不存在则创建账号 if !user.present? && school.present? department = school.departments.where(:name => list[2]).first - user = User.new - user.admin = false - user.activate - user.login = prefix + list[0].to_s.strip - user.lastname = list[1].to_s.strip - user.nickname = list[1].to_s.strip - user.professional_certification = 1 - user.certification = 1 - user.grade = 0 - user.password = "12345678" - user.phone = list[5].blank? ? nil : list[5] - if user.save + user_params = {status: 1, login: prefix + list[0].to_s.strip, lastname: list[1].to_s.strip, + nickname: list[1].to_s.strip, professional_certification: 1, certification: 1, grade: 0, + password: "12345678", phone: list[5].blank? ? nil : list[5], mail: "#{prefix+list[0].to_s.strip}@qq.com", profile_completed: 1} + user = User.create(user_params) + user = User.find(prefix + list[0].to_s.strip) + if user ue = UserExtensions.new(:user_id => user.id, :gender => 0, :school_id => school_id, :location => school.province, :location_city => school.city, :identity => list[3].to_i, :student_id => list[0].to_s.strip, :department_id => department.try(:id)) if list[3] && list[3].to_i == 0 ue.technical_title = ["教授", "副教授", "讲师", "助教"].include?(list[4]) ? list[4] : "讲师" diff --git a/app/models/course_group.rb b/app/models/course_group.rb index c5b66d87..2986e6ac 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -1,6 +1,6 @@ class CourseGroup < ActiveRecord::Base # attr_accessible :title, :body - belongs_to :course + belongs_to :course, :counter_cache => true has_many :course_members has_many :members has_many :memberships, :class_name => 'Member' diff --git a/app/models/user.rb b/app/models/user.rb index dbb77124..58f293d6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -300,7 +300,7 @@ class User < Principal attr_accessor :password, :password_confirmation attr_accessor :last_before_login_on # Prevents unauthorized assignments - attr_protected :login, :admin, :password, :password_confirmation, :hashed_password + # attr_protected :login, :admin, :password, :password_confirmation, :hashed_password LOGIN_LENGTH_LIMIT = 30 MAIL_LENGTH_LIMIT = 60 @@ -308,15 +308,15 @@ class User < Principal #validates_presence_of :login, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_presence_of :login, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false - validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false + #validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false validates_uniqueness_of :phone, :if => Proc.new { |user| user.phone_changed? && user.phone.present? }, :case_sensitive => false # Login must contain letters, numbers, underscores only #validates_format_of :login, :with => /\A[a-z0-9_\-]*\z/i validates_length_of :login, :maximum => LOGIN_LENGTH_LIMIT validates_length_of :firstname, :maximum => 30 validates_length_of :lastname, :maximum => 30 - validates_format_of :mail, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :allow_blank => true - validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true + #validates_format_of :mail, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :allow_blank => true + #validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true validates_confirmation_of :password, :allow_nil => true # validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true validate :validate_password_length @@ -673,9 +673,9 @@ class User < Principal base_reload(*args) end - def mail=(arg) - write_attribute(:mail, arg.to_s.strip) - end + # def mail=(arg) + # write_attribute(:mail, arg.to_s.strip) + # end def identity_url=(url) if url.blank?