重构老的代码,本地通过session来存放token, 所有的访问直接用老接口
This commit is contained in:
parent
f40794282f
commit
61c117b8cb
|
@ -9,7 +9,7 @@ module Mobile
|
|||
|
||||
params do
|
||||
requires :page, type: Integer
|
||||
requires :openid, type: String
|
||||
requires :token, type: String
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 "注册用户"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -254,6 +254,7 @@
|
|||
<div ng-if="has_more">
|
||||
<div id="more_activities" class="more-events mt10" ng-click="loadActData(page+1);">更多</div>
|
||||
</div>
|
||||
<my-alert message="alertService.message" title="alertService.title" visible="alertService.visible"></my-alert>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
|
||||
<script type="text/javascript">
|
||||
//window.g_openid = 'oCnvgvz8R7QheXE-R9Kkr39j8Ndg';
|
||||
window.g_openid = 'oCnvgvz8R7QheXE-R9Kkr39j8Ndg';
|
||||
window.g_debug = true; //调试标志,如果在本地请置为true
|
||||
window.apiUrl = 'http://localhost:3000/api/v1/';
|
||||
</script>
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<textarea class="copy-input"></textarea>
|
||||
<textarea input-auto type="text" class="post-reply-input" id="postInput" ng-model="formData.comment" /></textarea>
|
||||
</div>
|
||||
<button ng-click="addBlogReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr mt10">回复</button>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<textarea class="copy-input"></textarea>
|
||||
<textarea input-auto type="text" class="post-reply-input" id="postInput" ng-model="formData.comment" /></textarea>
|
||||
</div>
|
||||
<button ng-click="addDiscussionReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr mt10">回复</button>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
<textarea class="copy-input"></textarea>
|
||||
<textarea input-auto type="text" class="post-reply-input" id="postInput" ng-model="formData.comment" /></textarea>
|
||||
</div>
|
||||
<button ng-click="addNoticeReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr mt10">回复</button>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<textarea class="copy-input"></textarea>
|
||||
<textarea input-auto type="text" class="post-reply-input" id="postInput" ng-model="formData.comment"></textarea>
|
||||
</div>
|
||||
<button ng-click="addHomeworkReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr mt10">回复</button>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>react js</title>
|
||||
<meta charset='utf-8' />
|
||||
<meta name="keywords" content="" />
|
||||
<meta name="description" content="" />
|
||||
<meta name="apple-mobile-web-app-capable" content="no">
|
||||
<meta content='True' name='HandheldFriendly' />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
|
||||
|
||||
<link type="text/css" rel="stylesheet" href="/stylesheets/weui/weixin.css" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="container"></div>
|
||||
|
||||
<!-- 模板1开始,可以使用script(type设置为text/html)来存放模板片段,并且用id标示 -->
|
||||
<script id="t:result-list" type="text/html">
|
||||
|
||||
<! for(var i =0; i < issues.length; ++i){ !>
|
||||
<div class="post-container">
|
||||
<div class="post-wrapper">
|
||||
<div class="post-main">
|
||||
<div class="post-avatar fl"><img src="<!=issues[i].author.img_url!>" width="45" height="45" class="border-radius" /></div>
|
||||
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb"><!=issues[i].subject!></span></div>
|
||||
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10"><!=issues[i].author.nickname!></a>项目问题</div>
|
||||
<div class="cl"></div>
|
||||
<div class="post-content c-grey2 mt10">
|
||||
<div class="post-all-content"><!=issues[i].description!></div>
|
||||
</div>
|
||||
<a herf="javascript:void(0);" class="link-blue f13 fl mt5 post-more " style="text-decoration:underline">点击展开</a>
|
||||
<div class="cl"></div>
|
||||
<span class="c-grey f13 mt10 fl"><!=issues[i].created_on!></span>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<! } !>
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script src="/javascripts/jquery-1.3.2.js"></script>
|
||||
<script src="/javascripts/baiduTemplate.js"></script>
|
||||
<script src="/javascripts/wechat/auth.js"></script>
|
||||
<script src="/javascripts/wechat/wechat-dev.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -49,7 +49,7 @@
|
|||
<textarea class="copy-input"></textarea>
|
||||
<textarea input-auto type="text" class="post-reply-input" id="postInput" ng-model="formData.comment" /></textarea>
|
||||
</div>
|
||||
<button ng-click="addIssueReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr mt10">回复</button>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<textarea class="copy-input"></textarea>
|
||||
<textarea input-auto type="text" class="post-reply-input" id="postInput" ng-model="formData.comment" /></textarea>
|
||||
</div>
|
||||
<button ng-click="addJournalReply(formData)" ng-hide="formData.disabled" ng-disabled="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-click="addReply(formData)" ng-hide="formData.disabled" ng-disabled="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr mt10">回复</button>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -22,4 +22,4 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<my-alert message="alertService.message" title="alertService.title" visible="alertService.visible"></my-alert>
|
||||
<my-alert message="alertService.message" title="alertService.title" visible="alertService.visible" cb="alertService.cb"></my-alert>
|
|
@ -45,7 +45,7 @@
|
|||
<textarea class="copy-input"></textarea>
|
||||
<textarea input-auto type="text" class="post-reply-input" id="postInput" ng-model="formData.comment" /></textarea>
|
||||
</div>
|
||||
<button ng-click="addDiscussionReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-click="addReply(formData)" ng-disabled="formData.disabled" ng-hide="formData.disabled" class="post-reply-submit fr mt10">回复</button>
|
||||
<button ng-disabled="formData.disabled" ng-hide="!formData.disabled" class="post-reply-submit bg-grey fr mt10">回复</button>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -4,5 +4,24 @@ app.constant('config', {
|
|||
rootPath: '/assets/wechat/',
|
||||
rootUrl: '/',
|
||||
apiUrl: '/api/v1/'
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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")){
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
]);
|
|
@ -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"));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//跳到详情页
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}]);
|
|
@ -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);
|
||||
};
|
||||
}]);
|
|
@ -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);
|
||||
};
|
||||
});
|
||||
}]);
|
|
@ -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);
|
||||
};
|
||||
}]);
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
});
|
||||
}]);
|
|
@ -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);
|
||||
};
|
||||
});
|
||||
}]);
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
}]);
|
|
@ -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'
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue