From 2b7ff3c76bba05508ac188ab8d0a7bb2902d0b71 Mon Sep 17 00:00:00 2001
From: yuanke <249218296@qq.com>
Date: Tue, 9 Aug 2016 09:23:06 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=84=E4=B8=AA=E9=A1=B5?=
=?UTF-8?q?=E9=9D=A2=E9=AA=8C=E8=AF=81=E7=BB=91=E5=AE=9A=E7=99=BB=E5=BD=95?=
=?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/api/mobile/apis/users.rb | 6 ++--
app/controllers/wechats_controller.rb | 28 ++++++++++++++-----
app/models/homework_common.rb | 2 +-
app/services/projects_service.rb | 7 ++++-
config/routes.rb | 1 +
public/assets/wechat/join_project.html | 7 +++++
.../wechat/controllers/activity.js | 4 +++
.../javascripts/wechat/controllers/class.js | 3 +-
.../wechat/controllers/class_list.js | 6 ++--
.../wechat/controllers/edit_class.js | 4 ++-
.../wechat/controllers/edit_class_member.js | 4 ++-
.../wechat/controllers/edit_project_member.js | 4 ++-
.../wechat/controllers/join_class.js | 4 ++-
.../wechat/controllers/join_project.js | 4 ++-
.../wechat/controllers/myresource.js | 4 ++-
.../wechat/controllers/new_class.js | 4 ++-
.../wechat/controllers/new_project.js | 4 ++-
.../javascripts/wechat/controllers/project.js | 2 ++
.../wechat/controllers/project_list.js | 6 ++--
.../wechat/controllers/review_class_member.js | 4 ++-
.../controllers/review_project_member.js | 4 ++-
.../wechat/controllers/send_class_list.js | 4 ++-
public/javascripts/wechat/others/factory.js | 17 +++++++++--
23 files changed, 104 insertions(+), 29 deletions(-)
diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb
index 9b1be37c3..34558563d 100644
--- a/app/api/mobile/apis/users.rb
+++ b/app/api/mobile/apis/users.rb
@@ -27,7 +27,8 @@ module Mobile
post 'wxbind' do
openid = session[:wechat_openid]
logger.debug "openid ============== #{openid}"
- raise "无法获取到openid,请在微信中打开本页面" unless openid
+ # raise "无法获取到openid,请在微信中打开本页面" unless openid
+ raise "请在微信中关注公众号'Trustie创新实践平台'后再打开本页面" unless openid
uw = UserWechat.where(openid: openid).first
raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw
@@ -56,7 +57,8 @@ module Mobile
openid = session[:wechat_openid]
logger.debug "openid ============== #{openid}"
- raise "无法获取到openid,请在微信中打开本页面" unless openid
+ # raise "无法获取到openid,请在微信中打开本页面" unless openid
+ raise "请在微信中关注Trustie创新实践平台后再打开本页面" unless openid
us = UsersService.new
diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb
index c5ef8c24e..cbeaf851d 100644
--- a/app/controllers/wechats_controller.rb
+++ b/app/controllers/wechats_controller.rb
@@ -284,7 +284,7 @@ class WechatsController < ActionController::Base
end
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!',
- content: "课程名称:#{course.name}\n班级名称:#{course.name}\n任课老师:#{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} }
+ content: "课程名称:#{course.syllabus.name}\n班级名称:#{course.name}\n任课老师:#{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} }
return request.reply.news(news) do |article, n, index| # article is return object
url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities#/class?id='+course.id.to_s}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect"
pic_url = "#{ROOT_URL}/images/wechat/class.jpg"
@@ -333,7 +333,9 @@ class WechatsController < ActionController::Base
code = params[:code] || session[:wechat_code]
openid = get_openid_from_code(code)
- raise "无法获取到微信openid" unless openid
+ # raise "无法获取到微信openid" unless openid
+
+ raise "请在微信中关注Trustie创新实践平台后再打开本页面" unless openid
uw = UserWechat.where(openid: openid).first
raise "还未绑定trustie帐户" unless uw
@@ -349,13 +351,25 @@ class WechatsController < ActionController::Base
end
end
+ def is_bind
+ begin
+ code = params[:code] || session[:wechat_code]
+ open_id = get_openid_from_code(code)
+ raise "还未绑定trustie帐户" unless user_binded?(open_id)
+ render :json => {status: 0}
+ rescue Exception=>e
+ render :json => {status: -1, message: e.message}
+ end
+ end
+
def bind
begin
code = params[:code] || session[:wechat_code]
openid = get_openid_from_code(code)
- raise "无法获取到openid,请在微信中打开本页面" unless openid
+ # raise "无法获取到openid,请在微信中打开本页面" unless openid
+ raise "请在微信中关注Trustie创新实践平台后再打开本页面" unless openid
raise "此微信号已绑定用户,不能重复绑定" if user_binded?(openid)
user, last_login_on = User.try_to_login(params[:username], params[:password])
@@ -399,9 +413,9 @@ class WechatsController < ActionController::Base
render 'wechats/open_wechat', layout: nil and return
end
- unless user_binded?(open_id)
- @path = '/login'
- else
+ # unless user_binded?(open_id)
+ # @path = '/login'
+ # else
if params[:state] == 'myclass'
@course_id = params[:id];
elsif params[:state] == 'myproject'
@@ -412,7 +426,7 @@ class WechatsController < ActionController::Base
if params[:code]
redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return
end
- end
+ # end
render 'wechats/user_activities', layout: nil
end
diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb
index a915b1545..79297cf81 100644
--- a/app/models/homework_common.rb
+++ b/app/models/homework_common.rb
@@ -63,7 +63,7 @@ class HomeworkCommon < ActiveRecord::Base
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
if count == 0
ws = WechatService.new
- ws.homework_message_notice(m.user_id, "homework", self.id, "#{m.user.show_name},#{l(:label_new_homework_template)}:", self.course.name, "新作业:"+ self.name.html_safe, "作业内容请点击“详情”查看。")
+ ws.homework_message_notice(m.user_id, "homework", self.id, "#{m.user.show_name},#{l(:label_new_homework_template)}", self.course.name, "新作业:"+ self.name.html_safe, "作业内容请点击“详情”查看。")
end
# end
end
diff --git a/app/services/projects_service.rb b/app/services/projects_service.rb
index 1b342c122..aead2b3c6 100644
--- a/app/services/projects_service.rb
+++ b/app/services/projects_service.rb
@@ -239,7 +239,12 @@ class ProjectsService
if apply_message
if user.member_of?(project)
message = "已经是该项目的成员了"
- applied_messages.update_all(:status=>7)
+ u_member = project.member_principals.includes(:roles, :principal).where("user_id=?",params[:user_id]).first
+ if u_member.member_roles[0].role_id == 5
+ applied_messages.update_all(:status=>5)
+ else
+ applied_messages.update_all(:status=>7)
+ end
else
applied_project = apply_message.applied
ap_role = applied_project.try(:role)
diff --git a/config/routes.rb b/config/routes.rb
index b7a743591..397530806 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1325,6 +1325,7 @@ RedmineApp::Application.routes.draw do
get :user_activities
post :bind
post :get_bind
+ post :is_bind
end
end
diff --git a/public/assets/wechat/join_project.html b/public/assets/wechat/join_project.html
index c2c0ec993..61be93cfd 100644
--- a/public/assets/wechat/join_project.html
+++ b/public/assets/wechat/join_project.html
@@ -9,6 +9,13 @@
取消
确定
diff --git a/public/javascripts/wechat/controllers/activity.js b/public/javascripts/wechat/controllers/activity.js
index 7066da4d9..179845863 100644
--- a/public/javascripts/wechat/controllers/activity.js
+++ b/public/javascripts/wechat/controllers/activity.js
@@ -2,6 +2,10 @@
app.controller('ActivityController',
['$anchorScroll', '$location','$scope', '$http', '$timeout', 'auth', 'rms', 'common','alertService',
function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common, alertService){
+
+ common.checklogin();
+
+
$scope.replaceUrl = function(url){
return url;
};
diff --git a/public/javascripts/wechat/controllers/class.js b/public/javascripts/wechat/controllers/class.js
index 04807b2dd..a32c581c9 100644
--- a/public/javascripts/wechat/controllers/class.js
+++ b/public/javascripts/wechat/controllers/class.js
@@ -1,4 +1,5 @@
-app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location','$routeParams','alertService','rms', function($scope, config, $http, auth, $location, $routeParams,alertService,rms){
+app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location','$routeParams','alertService','rms','common', function($scope, config, $http, auth, $location, $routeParams,alertService,rms,common){
+ common.checkLogin();
var vm = $scope;
var courseid = $routeParams.id;
diff --git a/public/javascripts/wechat/controllers/class_list.js b/public/javascripts/wechat/controllers/class_list.js
index 48e778f9d..d6b1ec68f 100644
--- a/public/javascripts/wechat/controllers/class_list.js
+++ b/public/javascripts/wechat/controllers/class_list.js
@@ -3,8 +3,10 @@
*/
-app.controller('ClassListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms',
- function ($scope, config, auth, $http, $location, alertService,rms) {
+app.controller('ClassListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms','common'
+ function ($scope, config, auth, $http, $location, alertService,rms,common) {
+ common.checkLogin();
+
var vm = $scope;
vm.syllabuses = rms.get('syllabuses') || [];
diff --git a/public/javascripts/wechat/controllers/edit_class.js b/public/javascripts/wechat/controllers/edit_class.js
index 0a09ce1e3..30c78e35a 100644
--- a/public/javascripts/wechat/controllers/edit_class.js
+++ b/public/javascripts/wechat/controllers/edit_class.js
@@ -1,6 +1,8 @@
-app.controller('EditClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){
+app.controller('EditClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){
+ common.checkLogin();
+
var vm = $scope;
vm.syllabus = rms.get('current_edit_syllobus');
diff --git a/public/javascripts/wechat/controllers/edit_class_member.js b/public/javascripts/wechat/controllers/edit_class_member.js
index b3c28ea0b..7b28e1f4a 100644
--- a/public/javascripts/wechat/controllers/edit_class_member.js
+++ b/public/javascripts/wechat/controllers/edit_class_member.js
@@ -1,6 +1,8 @@
-app.controller('EditClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){
+app.controller('EditClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){
+ common.checkLogin();
+
var vm = $scope;
// vm.current_edit_member = rms.get('current_edit_member');
diff --git a/public/javascripts/wechat/controllers/edit_project_member.js b/public/javascripts/wechat/controllers/edit_project_member.js
index 3fd24f04e..d5b8788d8 100644
--- a/public/javascripts/wechat/controllers/edit_project_member.js
+++ b/public/javascripts/wechat/controllers/edit_project_member.js
@@ -1,6 +1,8 @@
-app.controller('EditProjectMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){
+app.controller('EditProjectMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){
+ common.checkLogin();
+
var vm = $scope;
// vm.current_edit_member = rms.get('current_edit_member');
diff --git a/public/javascripts/wechat/controllers/join_class.js b/public/javascripts/wechat/controllers/join_class.js
index 3f1a28387..3992a8ae3 100644
--- a/public/javascripts/wechat/controllers/join_class.js
+++ b/public/javascripts/wechat/controllers/join_class.js
@@ -1,6 +1,8 @@
-app.controller('JoinClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','wx', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,wx){
+app.controller('JoinClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','wx','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,wx,common){
+ common.checkLogin();
+
var vm = $scope;
// vm.current_edit_member = rms.get('current_edit_member');
diff --git a/public/javascripts/wechat/controllers/join_project.js b/public/javascripts/wechat/controllers/join_project.js
index f27c535c5..915277d3b 100644
--- a/public/javascripts/wechat/controllers/join_project.js
+++ b/public/javascripts/wechat/controllers/join_project.js
@@ -1,6 +1,8 @@
-app.controller('JoinProjectController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','wx', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,wx){
+app.controller('JoinProjectController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','wx','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,wx,common){
+ common.checkLogin();
+
var vm = $scope;
// vm.current_edit_member = rms.get('current_edit_member');
diff --git a/public/javascripts/wechat/controllers/myresource.js b/public/javascripts/wechat/controllers/myresource.js
index b5489c065..706827b8e 100644
--- a/public/javascripts/wechat/controllers/myresource.js
+++ b/public/javascripts/wechat/controllers/myresource.js
@@ -1,4 +1,6 @@
-app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$location', 'rms', function($scope, $http, auth, config, $location,rms){
+app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$location', 'rms','common', function($scope, $http, auth, config, $location,rms,common){
+ common.checkLogin();
+
var vm = $scope;
// vm.menus = ['课件', '作业', '测验'];
vm.menus = ['课件', '作业'];
diff --git a/public/javascripts/wechat/controllers/new_class.js b/public/javascripts/wechat/controllers/new_class.js
index 5e9f339a1..0a8ea25b2 100644
--- a/public/javascripts/wechat/controllers/new_class.js
+++ b/public/javascripts/wechat/controllers/new_class.js
@@ -1,6 +1,8 @@
-app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms', function($scope, $http, auth, config, alertService, $location,rms){
+app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms','common', function($scope, $http, auth, config, alertService, $location,rms,common){
+ common.checkLogin();
+
var vm = $scope;
vm.alertService = alertService.create();
diff --git a/public/javascripts/wechat/controllers/new_project.js b/public/javascripts/wechat/controllers/new_project.js
index 6eb6a1caa..a73da1419 100644
--- a/public/javascripts/wechat/controllers/new_project.js
+++ b/public/javascripts/wechat/controllers/new_project.js
@@ -1,6 +1,8 @@
-app.controller('NewProjectController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms', function($scope, $http, auth, config, alertService, $location,rms){
+app.controller('NewProjectController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms','common', function($scope, $http, auth, config, alertService, $location,rms,common){
+ common.checkLogin();
+
var vm = $scope;
vm.alertService = alertService.create();
diff --git a/public/javascripts/wechat/controllers/project.js b/public/javascripts/wechat/controllers/project.js
index f4a3b5c5c..d1a641546 100644
--- a/public/javascripts/wechat/controllers/project.js
+++ b/public/javascripts/wechat/controllers/project.js
@@ -1,4 +1,6 @@
app.controller('ProjectController', ['$scope', 'config','$http','$timeout', 'auth','$location','$routeParams','alertService','rms','common', function($scope, config, $http,$timeout, auth, $location, $routeParams,alertService,rms,common){
+ common.checkLogin();
+
$scope.replaceUrl = function(url){
return url;
};
diff --git a/public/javascripts/wechat/controllers/project_list.js b/public/javascripts/wechat/controllers/project_list.js
index 6ff7495e4..395215b25 100644
--- a/public/javascripts/wechat/controllers/project_list.js
+++ b/public/javascripts/wechat/controllers/project_list.js
@@ -3,8 +3,10 @@
*/
-app.controller('ProjectListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms',
- function ($scope, config, auth, $http, $location, alertService,rms) {
+app.controller('ProjectListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms','common',
+ function ($scope, config, auth, $http, $location, alertService,rms,common) {
+ common.checkLogin();
+
var vm = $scope;
// vm.projects = rms.get('projects') || [];
vm.projects = [];
diff --git a/public/javascripts/wechat/controllers/review_class_member.js b/public/javascripts/wechat/controllers/review_class_member.js
index 44704c32d..d7f63a9bf 100644
--- a/public/javascripts/wechat/controllers/review_class_member.js
+++ b/public/javascripts/wechat/controllers/review_class_member.js
@@ -1,6 +1,8 @@
-app.controller('ReviewClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){
+app.controller('ReviewClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){
+ common.checkLogin();
+
var vm = $scope;
// vm.current_edit_member = rms.get('current_edit_member');
diff --git a/public/javascripts/wechat/controllers/review_project_member.js b/public/javascripts/wechat/controllers/review_project_member.js
index 2428c09d0..e74cf0286 100644
--- a/public/javascripts/wechat/controllers/review_project_member.js
+++ b/public/javascripts/wechat/controllers/review_project_member.js
@@ -1,6 +1,8 @@
-app.controller('ReviewProjectMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){
+app.controller('ReviewProjectMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){
+ common.checkLogin();
+
var vm = $scope;
// vm.current_edit_member = rms.get('current_edit_member');
diff --git a/public/javascripts/wechat/controllers/send_class_list.js b/public/javascripts/wechat/controllers/send_class_list.js
index bc81cfc08..0e7b912c6 100644
--- a/public/javascripts/wechat/controllers/send_class_list.js
+++ b/public/javascripts/wechat/controllers/send_class_list.js
@@ -1,4 +1,6 @@
-app.controller('SendClassListController', ['$scope', '$http','$routeParams', 'config','auth','alertService', 'rms', function($scope, $http, $routeParams, config, auth, alertService,rms){
+app.controller('SendClassListController', ['$scope', '$http','$routeParams', 'config','auth','alertService', 'rms','common', function($scope, $http, $routeParams, config, auth, alertService,rms,common){
+ common.checkLogin();
+
var vm = $scope;
var send_id = $routeParams.id;
diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js
index 7ac0a3bdb..4af20c452 100644
--- a/public/javascripts/wechat/others/factory.js
+++ b/public/javascripts/wechat/others/factory.js
@@ -93,7 +93,7 @@ app.factory('rms', function(){
return {save: save, get: get};
});
-app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx', function($http, auth, $routeParams,rms,config,wx){
+app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$location', function($http, auth, $routeParams,rms,config,wx,$location){
var addCommonReply = function(id, type, data, cb){
if(!data.comment || data.comment.length<=0){
@@ -390,5 +390,18 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx', func
});
};
- return {init: init, addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise, wxConfig: wxConfig};
+ var checkLogin = function(){
+ $http.post(
+ '/wechat/is_bind',
+ {} ///不用传code了,都由服务器来处理
+ ).then(function(response){
+ console.log(response.data);
+ if(response.data.status != 0){
+ $location.path("/login");
+ return;
+ }
+ });
+ };
+
+ return {init: init, addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise, wxConfig: wxConfig, checkLogin: checkLogin};
}]);