diff --git a/app/api/mobile/apis/activities.rb b/app/api/mobile/apis/activities.rb
index 49fdaff8f..661925012 100644
--- a/app/api/mobile/apis/activities.rb
+++ b/app/api/mobile/apis/activities.rb
@@ -9,7 +9,7 @@ module Mobile
params do
requires :page, type: Integer
- requires :openid, type: String
+ requires :token, type: String
end
post do
authenticate!
diff --git a/app/api/mobile/apis/issues.rb b/app/api/mobile/apis/issues.rb
index b767bd768..4a6417cb4 100644
--- a/app/api/mobile/apis/issues.rb
+++ b/app/api/mobile/apis/issues.rb
@@ -8,7 +8,8 @@ module Mobile
desc "get special issuse"
get ':id' do
- user = UserWechat.find_by_openid(params[:openid]).user
+ authenticate!
+ user = current_user
issue = Issue.find params[:id]
present :data, issue, with: Mobile::Entities::Issue,user: user
present :status, 0
diff --git a/app/api/mobile/apis/journal_for_messages.rb b/app/api/mobile/apis/journal_for_messages.rb
index 15a571a82..5f2d01185 100644
--- a/app/api/mobile/apis/journal_for_messages.rb
+++ b/app/api/mobile/apis/journal_for_messages.rb
@@ -7,7 +7,8 @@ module Mobile
desc "get special journal"
get ':id' do
- user = UserWechat.find_by_openid(params[:openid]).user
+ authenticate!
+ user = current_user
jour = JournalsForMessage.find params[:id]
present :data, jour, with: Mobile::Entities::Jours,user: user
present :status, 0
diff --git a/app/api/mobile/apis/messages.rb b/app/api/mobile/apis/messages.rb
index ae2f9a39c..bab82de8d 100644
--- a/app/api/mobile/apis/messages.rb
+++ b/app/api/mobile/apis/messages.rb
@@ -7,7 +7,8 @@ module Mobile
desc "get special topic"
get ':id' do
- user = UserWechat.find_by_openid(params[:openid]).user
+ authenticate!
+ user = current_user
message = Message.find params[:id]
present :data, message, with: Mobile::Entities::Message,user: user
present :status, 0
diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb
index 694ec0613..5b7159301 100644
--- a/app/api/mobile/apis/new_comment.rb
+++ b/app/api/mobile/apis/new_comment.rb
@@ -11,12 +11,12 @@ module Mobile
params do
requires :type, type: String
requires :content, type: String
- requires :openid, type: String
+ requires :token, type: String
end
post ':id' do
+ authenticate!
type = params[:type]
result = 1
- current_user = UserWechat.find_by_openid(params[:openid]).user
if params[:content]!="" && current_user
case type
when "HomeworkCommon"
diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb
index 8bdd460cc..d42177783 100644
--- a/app/api/mobile/apis/newss.rb
+++ b/app/api/mobile/apis/newss.rb
@@ -7,7 +7,8 @@ module Mobile
desc "get special news"
get ':id' do
- user = UserWechat.find_by_openid(params[:openid]).user
+ authenticate!
+ user = current_user
news = News.find params[:id]
present :data, news, with: Mobile::Entities::News,user: user
present :status, 0
diff --git a/app/api/mobile/apis/praise.rb b/app/api/mobile/apis/praise.rb
index 57dbd0729..834d1195b 100644
--- a/app/api/mobile/apis/praise.rb
+++ b/app/api/mobile/apis/praise.rb
@@ -9,12 +9,13 @@ module Mobile
params do
requires :type, type: String
- requires :openid, type: String
+ requires :token, type: String
end
post ':id' do
+ authenticate!
obj_id = params[:id]
obj_type = params[:type]
- user = UserWechat.find_by_openid(params[:openid]).user
+ user = current_user
pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id).first
if pts.blank?
praise_or_cancel(obj_type,obj_id,user,1)
diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb
index 5aee29fe2..e3041abcd 100644
--- a/app/api/mobile/apis/users.rb
+++ b/app/api/mobile/apis/users.rb
@@ -4,6 +4,20 @@ module Mobile
class Users < Grape::API
resource :users do
+ desc "查询是否已绑定"
+ params do
+ requires :openid, type: String, desc: 'wechat openid'
+ end
+ post 'isbind' do
+ openid = params[:openid]
+ uw = UserWechat.where(openid: openid).first
+ raise "还未绑定trustie帐户" unless uw
+
+ user = uw.user
+ ::ApiKey.delete_all(user_id: user.id)
+ key = ::ApiKey.create!(user_id: user.id)
+ present status: 0, token: key.access_token
+ end
desc "绑定微信用户"
params do
@@ -29,8 +43,7 @@ module Mobile
)
# ws = WechatService.new
# ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now))
- present status: 0
- present message: '绑定成功'
+ present status: 0, message: '您已成功绑定Trustie平台'
end
desc "注册用户"
diff --git a/app/api/mobile/apis/whomeworks.rb b/app/api/mobile/apis/whomeworks.rb
index a88d509a3..c8377aa0d 100644
--- a/app/api/mobile/apis/whomeworks.rb
+++ b/app/api/mobile/apis/whomeworks.rb
@@ -7,7 +7,8 @@ module Mobile
desc "get one homework"
get ':id' do
- user = UserWechat.find_by_openid(params[:openid]).user
+ authenticate!
+ user = current_user
homework = HomeworkCommon.find params[:id]
present :data, homework, with: Mobile::Entities::Whomework,user: user
present :status, 0
diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html
index 69ea8f1fa..fd5b44b2b 100644
--- a/public/assets/wechat/activities.html
+++ b/public/assets/wechat/activities.html
@@ -254,6 +254,7 @@
+
diff --git a/public/assets/wechat/app.html b/public/assets/wechat/app.html
index 6965d24f3..a3977ec5c 100644
--- a/public/assets/wechat/app.html
+++ b/public/assets/wechat/app.html
@@ -20,7 +20,7 @@
diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html
index 509e0171a..762bd090e 100644
--- a/public/assets/wechat/blog_detail.html
+++ b/public/assets/wechat/blog_detail.html
@@ -39,7 +39,7 @@
-
+
diff --git a/public/assets/wechat/course_discussion.html b/public/assets/wechat/course_discussion.html
index 2e7ed3151..69daf2b05 100644
--- a/public/assets/wechat/course_discussion.html
+++ b/public/assets/wechat/course_discussion.html
@@ -46,7 +46,7 @@
-
+
diff --git a/public/assets/wechat/course_notice.html b/public/assets/wechat/course_notice.html
index cca135681..6d2d49d23 100644
--- a/public/assets/wechat/course_notice.html
+++ b/public/assets/wechat/course_notice.html
@@ -45,7 +45,7 @@
-
+
diff --git a/public/assets/wechat/homework_detail.html b/public/assets/wechat/homework_detail.html
index 0fc39c735..974af2246 100644
--- a/public/assets/wechat/homework_detail.html
+++ b/public/assets/wechat/homework_detail.html
@@ -59,7 +59,7 @@
-
+
diff --git a/public/assets/wechat/issue.html b/public/assets/wechat/issue.html
deleted file mode 100644
index 558496ef0..000000000
--- a/public/assets/wechat/issue.html
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
- react js
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/public/assets/wechat/issue_detail.html b/public/assets/wechat/issue_detail.html
index 1d7f9a536..4438c453d 100644
--- a/public/assets/wechat/issue_detail.html
+++ b/public/assets/wechat/issue_detail.html
@@ -49,7 +49,7 @@
-
+
diff --git a/public/assets/wechat/jour_message_detail.html b/public/assets/wechat/jour_message_detail.html
index dc6b1409f..9fd09de2c 100644
--- a/public/assets/wechat/jour_message_detail.html
+++ b/public/assets/wechat/jour_message_detail.html
@@ -37,7 +37,7 @@
-
+
diff --git a/public/assets/wechat/login.html b/public/assets/wechat/login.html
index d34d0054c..309db29de 100644
--- a/public/assets/wechat/login.html
+++ b/public/assets/wechat/login.html
@@ -22,4 +22,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/public/assets/wechat/project_discussion.html b/public/assets/wechat/project_discussion.html
index 4831e1521..696ffd7d1 100644
--- a/public/assets/wechat/project_discussion.html
+++ b/public/assets/wechat/project_discussion.html
@@ -45,7 +45,7 @@
-
+
diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js
index d4275e9df..472a5a377 100644
--- a/public/javascripts/wechat/app.js
+++ b/public/javascripts/wechat/app.js
@@ -4,5 +4,24 @@ app.constant('config', {
rootPath: '/assets/wechat/',
rootUrl: '/',
apiUrl: '/api/v1/'
+});
-});
\ No newline at end of file
+
+app.run(['$rootScope', 'auth', '$location', function($rootScope, auth, $location){
+ $rootScope.$on('$routeChangeError', function(event, next, current){
+
+ if(next && next.templateUrl){
+ if(!next.templateUrl.endsWith("login.html") && !next.templateUrl.endsWith("reg.html")){
+ $location.path("/login");
+ }
+ }
+ });
+
+ $rootScope.$on('$routeChangeStart', function(event, next, current){
+ if(next && next.templateUrl){
+ if(!next.templateUrl.endsWith("login.html") && !next.templateUrl.endsWith("reg.html")){
+ }
+ }
+ });
+}
+]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/controllers/activity.js b/public/javascripts/wechat/controllers/activity.js
index e17b7c5b3..e44eb3ea2 100644
--- a/public/javascripts/wechat/controllers/activity.js
+++ b/public/javascripts/wechat/controllers/activity.js
@@ -1,11 +1,12 @@
app.controller('ActivityController',
- ['$anchorScroll', '$location','$scope', '$http', '$timeout', 'auth', 'rms', 'common',
- function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common){
+ ['$anchorScroll', '$location','$scope', '$http', '$timeout', 'auth', 'rms', 'common','alertService',
+ function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common, alertService){
$scope.replaceUrl = function(url){
return url;
};
+ $scope.alertService = alertService.create();
console.log("ActivityController load");
$scope.page = rms.get('page') || 0;
@@ -18,7 +19,7 @@ app.controller('ActivityController',
$http({
method: 'POST',
url: apiUrl+ "activities",
- data: {openid: auth.openid(), page: page}
+ data: {token: auth.token(), page: page}
}).then(function successCallback(response) {
if(response.data.page >0) {
$scope.activities = $scope.activities.concat(response.data.data);
@@ -38,18 +39,17 @@ app.controller('ActivityController',
};
if($scope.activities.length<=0){
- auth.getOpenId().then(
- function successCallback(response){
+ auth.isBind().then(
+ function(){
$scope.loadActData(0);
}, function errorCallback(response) {
- alert("获取openid出错:"+response);
+ $scope.alertService.showMessage("获取token出错",response);
}
);
} else {
$timeout(function(){
window.scrollTo(0, rms.get("yoffset"));
});
-
}
//跳到详情页
diff --git a/public/javascripts/wechat/controllers/blog.js b/public/javascripts/wechat/controllers/blog.js
index 8eb45b604..4c2403944 100644
--- a/public/javascripts/wechat/controllers/blog.js
+++ b/public/javascripts/wechat/controllers/blog.js
@@ -1,40 +1,16 @@
-
app.controller('BlogController',
['$scope', '$http', '$routeParams', 'auth', 'common',
function($scope, $http, $routeParams, auth, common){
- $scope.formData = {comment: ''};
- var loadData = function(id){
- common.loadCommonData(id, 'blog_comments').then(function successCallback(response) {
- console.log(response.data);
- $scope.blog = response.data.data;
- }, function errorCallback(response) {
+ common.init({
+ id: $routeParams.id,
+ scope: $scope,
+ type: 'blog_comments',
+ replyType: 'BlogComment',
+ loadCallback: function(data){
+ $scope.blog = data.data;
+ },
+ replyCallback: function(){
+ }
});
- };
-
- auth.getOpenId().then(
- function successCallback(response){
- loadData($routeParams.id);
- }, function errorCallback(response) {
- alert("获取openid出错:"+response);
- }
- );
-
- $scope.addBlogReply = function(data){
- console.log(data.comment);
- common.addCommonReply($routeParams.id, 'BlogComment', data, function(){
- $scope.formData = {comment: ''};
- loadData($routeParams.id);
- });
- };
-
- $scope.addPraise = function(act){
- console.log(act);
- common.addCommonPraise(act);
- };
-
- $scope.decreasePraise = function(act){
- console.log(act);
- common.decreaseCommonPraise(act);
- };
}]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/controllers/course_notice.js b/public/javascripts/wechat/controllers/course_notice.js
index 24b0fdbe1..77d2e6ab0 100644
--- a/public/javascripts/wechat/controllers/course_notice.js
+++ b/public/javascripts/wechat/controllers/course_notice.js
@@ -1,36 +1,16 @@
app.controller('CourseNoticeController', ['$scope', '$http', '$routeParams', 'auth', 'common',
function($scope, $http, $routeParams, auth, common){
- $scope.formData = {comment: ''};
- var loadData = function(id){
- common.loadCommonData(id, 'newss').then(function successCallback(response) {
- console.log(response.data);
- $scope.news = response.data.data;
- }, function errorCallback(response) {
+ common.init({
+ id: $routeParams.id,
+ scope: $scope,
+ type: 'newss',
+ replyType: 'News',
+ loadCallback: function(data){
+ $scope.news = data.data;
+ },
+ replyCallback: function(){
+ }
});
- };
- auth.getOpenId().then(
- function successCallback(response){
- loadData($routeParams.id);
- }, function errorCallback(response) {
- alert("获取openid出错:"+response);
- }
- );
-
- $scope.addNoticeReply = function(data){
- console.log(data.comment);
- common.addCommonReply($routeParams.id, 'News', data, function(){
- $scope.formData = {comment: ''};
- loadData($routeParams.id);
- });
- };
-
- $scope.addPraise = function(act){
- common.addCommonPraise(act);
- };
-
- $scope.decreasePraise = function(act){
- common.decreaseCommonPraise(act);
- };
}]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/controllers/discussion.js b/public/javascripts/wechat/controllers/discussion.js
index 4828cb39a..7e0811a0d 100644
--- a/public/javascripts/wechat/controllers/discussion.js
+++ b/public/javascripts/wechat/controllers/discussion.js
@@ -1,36 +1,14 @@
app.controller('DiscussionController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){
- $scope.formData = {comment: ''};
-
- var loadData = function(id){
- common.loadCommonData(id, 'messages').then(function successCallback(response) {
- console.log(response.data);
- $scope.discussion = response.data.data;
- }, function errorCallback(response) {
- });
- };
-
- auth.getOpenId().then(
- function successCallback(response){
- loadData($routeParams.id);
- }, function errorCallback(response) {
- alert("获取openid出错:"+response);
+ common.init({
+ id: $routeParams.id,
+ scope: $scope,
+ type: 'messages',
+ replyType: 'Message',
+ loadCallback: function(data){
+ $scope.discussion = data.data;
+ },
+ replyCallback: function(){
}
- );
-
- $scope.addDiscussionReply = function(data){
- console.log(data.comment);
- common.addCommonReply($routeParams.id, 'Message', data, function(){
- $scope.formData = {comment: ''};
- loadData($routeParams.id);
- });
- };
-
- $scope.addPraise = function(act){
- common.addCommonPraise(act);
- };
-
- $scope.decreasePraise = function(act){
- common.decreaseCommonPraise(act);
- };
+ });
}]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/controllers/homework.js b/public/javascripts/wechat/controllers/homework.js
index 795bf30e9..58f70db5a 100644
--- a/public/javascripts/wechat/controllers/homework.js
+++ b/public/javascripts/wechat/controllers/homework.js
@@ -1,36 +1,16 @@
app.controller('HomeworkController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){
- $scope.formData = {comment: ''};
-
- var loadData = function(id){
- common.loadCommonData(id, 'whomeworks').then(function successCallback(response) {
- console.log(response.data);
- $scope.homework = response.data.data;
- }, function errorCallback(response) {
- });
- };
-
- auth.getOpenId().then(
- function successCallback(response){
- loadData($routeParams.id);
- }, function errorCallback(response) {
- alert("获取openid出错:"+response);
+ common.init({
+ id: $routeParams.id,
+ scope: $scope,
+ type: 'whomeworks',
+ replyType: 'HomeworkCommon',
+ loadCallback: function(data){
+ console.log(data);
+ $scope.homework = data.data;
+ },
+ replyCallback: function(){
}
- );
+ });
- $scope.addHomeworkReply = function(data){
- console.log(data.comment);
- common.addCommonReply($routeParams.id, 'HomeworkCommon', data, function(){
- $scope.formData = {comment: ''};
- loadData($routeParams.id);
- });
- };
-
- $scope.addPraise = function(act){
- common.addCommonPraise(act);
- };
-
- $scope.decreasePraise = function(act){
- common.decreaseCommonPraise(act);
- };
}]);
diff --git a/public/javascripts/wechat/controllers/issue.js b/public/javascripts/wechat/controllers/issue.js
index 09602f9e1..ae0cc4450 100644
--- a/public/javascripts/wechat/controllers/issue.js
+++ b/public/javascripts/wechat/controllers/issue.js
@@ -1,36 +1,15 @@
app.controller('IssueController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){
- $scope.formData = {comment: ''};
- var loadData = function(id){
- common.loadCommonData(id, 'issues').then(function successCallback(response) {
- console.log(response.data);
- $scope.issue = response.data.data;
- }, function errorCallback(response) {
- });
- };
-
- auth.getOpenId().then(
- function successCallback(response){
- loadData($routeParams.id);
- }, function errorCallback(response) {
- alert("获取openid出错:"+response);
+ common.init({
+ id: $routeParams.id,
+ scope: $scope,
+ type: 'issues',
+ replyType: 'Issue',
+ loadCallback: function(data){
+ console.log(data);
+ $scope.issue = data.data;
+ },
+ replyCallback: function(){
}
- );
-
- $scope.addIssueReply = function(data){
- console.log(data.comment);
- common.addCommonReply($routeParams.id, 'Issue', data, function(){
- $scope.formData = {comment: ''};
- loadData($routeParams.id);
- });
-
- };
-
- $scope.addPraise = function(act){
- common.addCommonPraise(act);
- };
-
- $scope.decreasePraise = function(act){
- common.decreaseCommonPraise(act);
- };
+ });
}]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/controllers/journals.js b/public/javascripts/wechat/controllers/journals.js
index f379525d7..76b4f8cf6 100644
--- a/public/javascripts/wechat/controllers/journals.js
+++ b/public/javascripts/wechat/controllers/journals.js
@@ -1,37 +1,13 @@
app.controller('JournalsController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){
- $scope.formData = {comment: ''};
-
- var loadData = function(id){
- common.loadCommonData(id, 'journal_for_messages').then(function successCallback(response) {
- console.log(response.data);
- $scope.message = response.data.data;
- }, function errorCallback(response) {
- });
- };
-
- auth.getOpenId().then(
- function successCallback(response){
- loadData($routeParams.id);
- }, function errorCallback(response) {
- alert("获取openid出错:"+response);
+ common.init({
+ id: $routeParams.id,
+ scope: $scope,
+ type: 'journal_for_messages',
+ replyType: 'JournalsForMessage',
+ loadCallback: function(data){
+ $scope.message = data.data;
+ },
+ replyCallback: function(){
}
- );
-
- $scope.addJournalReply = function(data){
- console.log(data.comment);
- common.addCommonReply($routeParams.id, 'JournalsForMessage', data, function(){
- $scope.formData = {comment: ''};
- loadData($routeParams.id);
- });
- };
-
- $scope.addPraise = function(act){
- console.log(act);
- common.addCommonPraise(act);
- };
-
- $scope.decreasePraise = function(act){
- console.log(act);
- common.decreaseCommonPraise(act);
- };
+ });
}]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/controllers/login.js b/public/javascripts/wechat/controllers/login.js
index a760ce8ea..35b750e8c 100644
--- a/public/javascripts/wechat/controllers/login.js
+++ b/public/javascripts/wechat/controllers/login.js
@@ -1,5 +1,8 @@
app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams', 'alertService', 'config','auth','session',
function ($scope, $http, $location, $routeParams, alertService, config, auth,session) {
+ if(auth.isBind().then(function(){
+ $location.path("/activities");
+ }));
if($routeParams.code){
session.save('code', $routeParams.code);
@@ -21,7 +24,7 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams
console.log(apiUrl + "auth");
- auth.getOpenId().then(
+ auth.openid().then(
function(openid){
return $http.post(
config.apiUrl + "users/wxbind",
@@ -30,11 +33,12 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams
}
).then(
function(response) {
- vm.loginFailed = (response.data.status != 0);
console.log(response.data);
- vm.alertService.showMessage('出错了', response.data.message);
-
+ vm.loginFailed = (response.data.status != 0);
if (!$scope.loginFailed) { //绑定成功
+ vm.alertService.showMessage('提示', response.data.message, function(){
+ $location.path("/activities");
+ });
} else {
vm.alertService.showMessage('出错了', response.data.message);
}
@@ -47,7 +51,6 @@ app.controller('LoginController', ['$scope', '$http', '$location', '$routeParams
vm.showBox = function () {
vm.findPwdDialog.showMessage("提示", "请访问www.trustie.net获取密码,谢谢!");
}
-
vm.goReg = function () {
$location.path('/reg');
}
diff --git a/public/javascripts/wechat/directives/alert.js b/public/javascripts/wechat/directives/alert.js
index aa346cb8c..332ec65bf 100644
--- a/public/javascripts/wechat/directives/alert.js
+++ b/public/javascripts/wechat/directives/alert.js
@@ -2,14 +2,16 @@ app.directive('myAlert', ['config', function(config){
return {
templateUrl: config.rootPath+ 'templates/alert.html',
scope: {
- message: "=",
title: "=",
- visible: "="
+ message: "=",
+ visible: "=",
+ cb: "="
},
link: function(scope){
- scope.visible = false;
scope.dismiss = function(){
- scope.visible = false;
+ if(typeof scope.cb === 'function'){
+ scope.cb();
+ }
};
}
}
diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js
index 3cb601d2b..c4aca60f4 100644
--- a/public/javascripts/wechat/others/factory.js
+++ b/public/javascripts/wechat/others/factory.js
@@ -3,18 +3,21 @@ app.factory('alertService', function(){
this.title = null;
this.message = null;
this.visible = null;
+ this.cb = null;
}
- Alert.prototype.showMessage = function(title, msg){
+ Alert.prototype.showMessage = function(title, msg, cb){
this.message = msg;
this.title = title;
this.visible = true;
+ this.cb = cb;
}
Alert.prototype.dismiss = function(){
this.message = null;
this.title = null;
this.visible = false;
+ if(this.cb) {this.cb();}
}
return {
@@ -25,7 +28,7 @@ app.factory('alertService', function(){
});
-app.factory('auth', ['$http','$routeParams', '$q', 'session', function($http,$routeParams, $q, session){
+app.factory('auth', ['$http','$routeParams', '$q', 'session', 'config',function($http,$routeParams, $q, session,config){
var _openid = '';
if(typeof g_openid !== 'undefined'){
@@ -36,6 +39,34 @@ app.factory('auth', ['$http','$routeParams', '$q', 'session', function($http,$ro
_openid = session.get("openid");
}
+ //是否已经绑定
+ var isBind = function(){
+ var defer = $q.defer();
+
+ var token = getToken();
+ if(token && token.length>10){
+ defer.resolve(token);
+ } else {
+ getOpenId().then(function(openid){
+ return $http.post(
+ config.apiUrl+ 'users/isbind',
+ {openid: openid}
+ )
+ }).then(function(response){
+ if(response.data.status!=0){
+ defer.reject(response.data.message);
+ }else {
+ session.save("token", response.data.token);
+ defer.resolve(response.data.token);
+ }
+ }).catch(function(e){
+ defer.reject(e);
+ });
+ }
+
+ return defer.promise;
+ }
+
var getOpenId = function() {
var deferred = $q.defer();
console.log(_openid);
@@ -52,7 +83,7 @@ app.factory('auth', ['$http','$routeParams', '$q', 'session', function($http,$ro
deferred.reject(response.data.message);
} else{
_openid = response.data.openid;
- session.save("openid", _openid);
+ //session.save("openid", _openid);
deferred.resolve(_openid);
}
}, function errorCallback(response) {
@@ -64,7 +95,10 @@ app.factory('auth', ['$http','$routeParams', '$q', 'session', function($http,$ro
var openid = function(){
return _openid;
};
- return {getOpenId: getOpenId, openid: openid};
+ var getToken = function(){
+ return session.get("token");
+ }
+ return {isBind: isBind, token: getToken, openid: getOpenId};
}]);
app.factory("session", function(){
@@ -103,7 +137,7 @@ app.factory('common', ['$http', 'auth', '$routeParams', function($http, auth, $r
var userInfo = {
type: type,
content: temp,
- openid: auth.openid()
+ token: auth.token()
};
//回复按钮禁用
data.disabled = true;
@@ -126,7 +160,7 @@ app.factory('common', ['$http', 'auth', '$routeParams', function($http, auth, $r
var loadCommonData = function(id, type){
return $http({
method: 'GET',
- url: apiUrl+ type + "/" + id+"?openid="+auth.openid()
+ url: apiUrl+ type + "/" + id+"?token="+auth.token()
})
};
@@ -137,7 +171,7 @@ app.factory('common', ['$http', 'auth', '$routeParams', function($http, auth, $r
$http({
method: 'POST',
url: apiUrl + "praise/" + act.act_id,
- data:{openid:auth.openid(),type:act.act_type}
+ data:{token:auth.token(),type:act.act_type}
}).then(function successCallback(response) {
console.log(response.data);
}, function errorCallback(response) {
@@ -152,12 +186,36 @@ app.factory('common', ['$http', 'auth', '$routeParams', function($http, auth, $r
$http({
method: 'POST',
url: apiUrl + "praise/" + act.act_id,
- data:{openid:auth.openid(),type:act.act_type}
+ data:{token:auth.token(),type:act.act_type}
}).then(function successCallback(response) {
console.log(response.data);
}, function errorCallback(response) {
});
};
- return {addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise};
+ var init = function(args){
+ args.scope.formData = {comment: ''};
+ var loadData = function(id){
+ loadCommonData(id, args.type).then(function successCallback(response) {
+ args.loadCallback(response.data);
+ }, function errorCallback(response) {
+ });
+ };
+
+ loadData(args.id);
+ args.scope.addReply = function(data){
+ console.log(data.comment);
+ addCommonReply(args.id, args.replyType, data, function(){
+ args.scope.formData = {comment: ''};
+ loadData(args.id);
+ if(typeof args.replyCallback === 'function'){
+ args.replyCallback();
+ }
+ });
+ };
+ args.scope.addPraise = addCommonPraise;
+ args.scope.decreasePraise = decreaseCommonPraise;
+ }
+
+ return {init: init, addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise};
}]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js
index ded374930..b4a4e4067 100644
--- a/public/javascripts/wechat/others/routes.js
+++ b/public/javascripts/wechat/others/routes.js
@@ -1,5 +1,17 @@
app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', function ($routeProvider, $httpProvider, $locationProvider, config) {
var rootPath = config.rootPath;
+ var resolve = {
+ delay: ['auth',function(auth){
+ return auth.isBind();
+ }]
+ };
+ var makeRoute = function(path, ctrl){
+ return {
+ templateUrl: rootPath + path,
+ controller: ctrl,
+ resolve: resolve
+ }
+ }
//$locationProvider.html5Mode(true);
$routeProvider
.when('/login', {
@@ -10,42 +22,15 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func
templateUrl: rootPath + 'reg.html',
controller: 'RegController'
})
- .when('/activites', {
- templateUrl: rootPath + 'activities.html',
- controller: 'ActivityController'
- })
- .when('/issues/:id', {
- templateUrl: rootPath + 'issue_detail.html',
- controller: 'IssueController'
- })
- .when('/project_discussion/:id', {
- templateUrl: rootPath + 'project_discussion.html',
- controller: 'DiscussionController'
- })
- .when('/homework/:id', {
- templateUrl: rootPath + 'homework_detail.html',
- controller: 'HomeworkController'
- })
- .when('/course_notice/:id', {
- templateUrl: rootPath + 'course_notice.html',
- controller: 'CourseNoticeController'
- })
- .when('/course_discussion/:id', {
- templateUrl: rootPath + 'course_discussion.html',
- controller: 'DiscussionController'
- })
- .when('/journal_for_message/:id', {
- templateUrl: rootPath + 'jour_message_detail.html',
- controller: 'JournalsController'
- })
- .when('/blog_comment/:id', {
- templateUrl: rootPath + 'blog_detail.html',
- controller: 'BlogController'
- })
- .when('/add_class', {
- templateUrl: rootPath + 'add_class.html',
- controller: 'AddClassController'
- })
+ .when('/activites', makeRoute('activities.html', 'ActivityController'))
+ .when('/issues/:id', makeRoute('issue_detail.html', 'IssueController'))
+ .when('/project_discussion/:id', makeRoute('project_discussion.html', 'DiscussionController'))
+ .when('/homework/:id', makeRoute('homework_detail.html', 'HomeworkController'))
+ .when('/course_notice/:id', makeRoute('course_notice.html', 'CourseNoticeController'))
+ .when('/course_discussion/:id', makeRoute('course_discussion.html', 'DiscussionController'))
+ .when('/journal_for_message/:id', makeRoute('jour_message_detail.html', 'JournalsController'))
+ .when('/blog_comment/:id', makeRoute('blog_detail.html', 'BlogController'))
+ .when('/add_class', makeRoute('add_class.html', 'AddClassController'))
.otherwise({
redirectTo: '/activites'
});