diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 6da45c10b..71b852e01 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -464,6 +464,10 @@ class ProjectsController < ApplicationController # by young # include CoursesHelper def member + # 消息"同意加入项目" + if params[:message_id] + message_invite(params[:message_id], params[:key]) + end # params[:login]为邮箱邀请用户加入,主要功能: # 1、自动注册 # 2、加入项目、创建角色 @@ -519,6 +523,14 @@ class ProjectsController < ApplicationController @members = paginateHelper @members end + def message_invite(message_id, key) + forge_message = ForgeMessage.find(message_id) + if key == forge_message.secret_key + Member.create(:role_ids => [4], :user_id => forge_message.user_id, :project_id => forge_message.project_id) + UserGrade.create(:user_id => forge_message.user_id, :project_id => forge_message.project_id) + end + end + #判断指定用户是否为课程教师 def isCourseTeacher(id) result = false diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 7b4b9d2e4..6a865b203 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -83,7 +83,7 @@ module ProjectsHelper elsif ivite_list.user.active? value = "邀请已发送,等待用户加入!" else - value = "账号尚未激活,等待用户应答!" + value = "邀请已发送,等待用户激活账号!" end end diff --git a/app/models/forge_message.rb b/app/models/forge_message.rb index 0c8b3384f..0dce57598 100644 --- a/app/models/forge_message.rb +++ b/app/models/forge_message.rb @@ -8,7 +8,7 @@ class ForgeMessage < ActiveRecord::Base TYPE_OF_WIKI_ACT = "Wiki" TYPE_OF_NEWS_ACT = "News" - attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed + attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed, :secret_key belongs_to :forge_message ,:polymorphic => true belongs_to :project diff --git a/app/models/mailer.rb b/app/models/mailer.rb index c9ab6e58e..e5ca8130e 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -89,7 +89,8 @@ class Mailer < ActionMailer::Base # 邀请信息消息 注:forge_message_id 为邀请人ID(特殊情况) def send_message(user, project) - ForgeMessage.create(:user_id => user.id, :project_id => project.id, :forge_message_type => "Project_Invite",:forge_message_id => User.current.id, :viewed => false) + key = newpass(6).to_s + ForgeMessage.create(:user_id => user.id, :project_id => project.id, :forge_message_type => "ProjectInvite",:forge_message_id => User.current.id, :viewed => false, :secret_key =>key) end # author: alan diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index 5ac9f7e8e..9d1532282 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -74,9 +74,10 @@ <% end %> <% end %> - <%# 课程消息 %> + <% unless @message_alls.nil? %> <% @message_alls.each do |ma| %> + <%# 课程消息 %> <% if ma.class == CourseMessage %> <% if ma.course_message_type == "News" %>