This commit is contained in:
parent
61c117b8cb
commit
3f98562c0f
|
@ -207,14 +207,14 @@ class WechatsController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_activities
|
def user_activities
|
||||||
session[:wechat_code] = params[:code] if params[:code]
|
# session[:wechat_code] = params[:code] if params[:code]
|
||||||
code = params[:code] || session[:wechat_code]
|
# code = params[:code] || session[:wechat_code]
|
||||||
openid = get_openid_from_code(code)
|
# openid = get_openid_from_code(code)
|
||||||
@wechat_user = user_binded?(openid)
|
# @wechat_user = user_binded?(openid)
|
||||||
unless @wechat_user
|
# unless @wechat_user
|
||||||
redirect_to login_wechat_path
|
# redirect_to login_wechat_path
|
||||||
return
|
# return
|
||||||
end
|
# end
|
||||||
|
|
||||||
render 'wechats/user_activities', layout: nil
|
render 'wechats/user_activities', layout: nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<link type="text/css" rel="stylesheet" href="/stylesheets/weui/weixin.css" />
|
<link type="text/css" rel="stylesheet" href="/stylesheets/weui/weixin.css" />
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.g_openid = '<%= @wechat_user.openid %>';
|
// window.g_openid = '<%= @wechat_user.openid %>';
|
||||||
window.g_debug = false; //调试标志,如果在本地请置为true
|
window.g_debug = false; //调试标志,如果在本地请置为true
|
||||||
window.apiUrl = '/api/v1/';
|
window.apiUrl = '/api/v1/';
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
var app=angular.module("wechat",["ngRoute"]);
|
var app=angular.module("wechat",["ngRoute"]);app.constant("config",{rootPath:"/assets/wechat/",rootUrl:"/",apiUrl:"/api/v1/"}),app.run(["$rootScope","auth","$location",function(t,e,a){t.$on("$routeChangeError",function(t,e,l){e&&e.templateUrl&&(e.templateUrl.endsWith("login.html")||e.templateUrl.endsWith("reg.html")||a.path("/login"))}),t.$on("$routeChangeStart",function(t,e,a){e&&e.templateUrl&&!e.templateUrl.endsWith("login.html")&&!e.templateUrl.endsWith("reg.html")})}]);
|
||||||
app.factory("auth",["$http","$routeParams","$q",function(e,n,t){var o="";"undefined"!=typeof g_openid&&(o=g_openid);var a=function(){var a=t.defer();if("undefined"!=typeof o&&o.length>0)a.resolve(o);else{var i=n.code;e({url:"/wechat/get_open_id",data:{code:i},method:"POST"}).then(function(e){o=e.data.openid,a.resolve(o)},function(e){a.reject(e)})}return a.promise},i=function(){return o};return{getOpenId:a,openid:i}}]),app.factory("rms",function(){var e={},n=function(n,t){e[n]=t},t=function(n){return e[n]};return{save:n,get:t}}),app.factory("common",["$http","auth","$routeParams",function(e,n,t){var o=function(t,o,a,i){if(a.comment&&!(a.comment.length<=0)){var r=a.comment.replace(/\n/g,"<br/>"),d={type:o,content:r,openid:n.openid()};a.disabled=!0,e({method:"POST",url:apiUrl+"new_comment/"+t,data:d}).then(function(e){a.disabled=!1,"function"==typeof i&&i()},function(e){})}},a=function(t,o){return e({method:"GET",url:apiUrl+o+"/"+t+"?openid="+n.openid()})},i=function(t){t.praise_count+=1,t.has_praise=!0,e({method:"POST",url:apiUrl+"praise/"+t.act_id,data:{openid:n.openid(),type:t.act_type}}).then(function(e){console.log(e.data)},function(e){})},r=function(t){t.praise_count-=1,t.has_praise=!1,e({method:"POST",url:apiUrl+"praise/"+t.act_id,data:{openid:n.openid(),type:t.act_type}}).then(function(e){console.log(e.data)},function(e){})};return{addCommonReply:o,loadCommonData:a,addCommonPraise:i,decreaseCommonPraise:r}}]);
|
app.factory("alertService",function(){function t(){this.title=null,this.message=null,this.visible=null,this.cb=null}return t.prototype.showMessage=function(t,e,n){this.message=e,this.title=t,this.visible=!0,this.cb=n},t.prototype.dismiss=function(){this.message=null,this.title=null,this.visible=!1,this.cb&&this.cb()},{create:function(){return new t}}}),app.factory("auth",["$http","$routeParams","$q","session","config",function(t,e,n,o,a){var i="";"undefined"!=typeof g_openid&&(i=g_openid),i||(i=o.get("openid"));var r=function(){var e=n.defer(),i=c();return i&&i.length>10?e.resolve(i):s().then(function(e){return t.post(a.apiUrl+"users/isbind",{openid:e})}).then(function(t){0!=t.data.status?e.reject(t.data.message):(o.save("token",t.data.token),e.resolve(t.data.token))})["catch"](function(t){e.reject(t)}),e.promise},s=function(){var a=n.defer();if(console.log(i),"undefined"!=typeof i&&i&&i.length>0)a.resolve(i);else{var r=e.code||o.get("code");t({url:"/wechat/get_open_id",data:{code:r},method:"POST"}).then(function(t){0!=t.data.status?a.reject(t.data.message):(i=t.data.openid,a.resolve(i))},function(t){a.reject(t)})}return a.promise},c=function(){return o.get("token")};return{isBind:r,token:c,openid:s}}]),app.factory("session",function(){return{save:function(t,e){sessionStorage.setItem(t,e)},get:function(t){return sessionStorage.getItem(t)}}}),app.factory("rms",function(){var t={},e=function(e,n){t[e]=n},n=function(e){return t[e]};return{save:e,get:n}}),app.factory("common",["$http","auth","$routeParams",function(t,e,n){var o=function(n,o,a,i){if(a.comment&&!(a.comment.length<=0)){var r=a.comment.replace(/\n/g,"<br/>"),s={type:o,content:r,token:e.token()};a.disabled=!0,t({method:"POST",url:apiUrl+"new_comment/"+n,data:s}).then(function(t){a.disabled=!1,"function"==typeof i&&i()},function(t){})}},a=function(n,o){return t({method:"GET",url:apiUrl+o+"/"+n+"?token="+e.token()})},i=function(n){n.praise_count+=1,n.has_praise=!0,t({method:"POST",url:apiUrl+"praise/"+n.act_id,data:{token:e.token(),type:n.act_type}}).then(function(t){console.log(t.data)},function(t){})},r=function(n){n.praise_count-=1,n.has_praise=!1,t({method:"POST",url:apiUrl+"praise/"+n.act_id,data:{token:e.token(),type:n.act_type}}).then(function(t){console.log(t.data)},function(t){})},s=function(t){t.scope.formData={comment:""};var e=function(e){a(e,t.type).then(function(e){t.loadCallback(e.data)},function(t){})};e(t.id),t.scope.addReply=function(n){console.log(n.comment),o(t.id,t.replyType,n,function(){t.scope.formData={comment:""},e(t.id),"function"==typeof t.replyCallback&&t.replyCallback()})},t.scope.addPraise=i,t.scope.decreasePraise=r};return{init:s,addCommonReply:o,loadCommonData:a,addCommonPraise:i,decreaseCommonPraise:r}}]);
|
||||||
app.filter("safeHtml",["$sce",function(t){return function(n){return t.trustAsHtml(n)}}]);
|
app.filter("safeHtml",["$sce",function(t){return function(n){return t.trustAsHtml(n)}}]);
|
||||||
app.controller("ActivityController",["$anchorScroll","$location","$scope","$http","$timeout","auth","rms","common",function(t,a,e,o,i,n,c,s){e.replaceUrl=function(t){return t},console.log("ActivityController load"),e.page=c.get("page")||0,e.activities=c.get("activities")||[],e.has_more=c.get("has_more"),e.loadActData=function(t){e.page=t,o({method:"POST",url:apiUrl+"activities",data:{openid:n.openid(),page:t}}).then(function(t){t.data.page>0?e.activities=e.activities.concat(t.data.data):e.activities=t.data.data,c.save("activities",e.activities),e.has_more=t.data.count+10*t.data.page<t.data.all_count,c.save("has_more",e.has_more),c.save("page",t.data.page),console.log(t.data)},function(t){})},e.activities.length<=0?n.getOpenId().then(function(t){e.loadActData(0)},function(t){alert("获取openid出错:"+t)}):i(function(){window.scrollTo(0,c.get("yoffset"))}),e.goDetail=function(t,e,o){c.save("yoffset",window.document.body.scrollTop),a.path("/"+t+"/"+e)},e.addPraise=function(t){s.addCommonPraise(t)},e.decreasePraise=function(t){s.decreaseCommonPraise(t)}}]);
|
app.controller("ActivityController",["$anchorScroll","$location","$scope","$http","$timeout","auth","rms","common","alertService",function(t,a,e,o,i,c,n,s,r){e.replaceUrl=function(t){return t},e.alertService=r.create(),console.log("ActivityController load"),e.page=n.get("page")||0,e.activities=n.get("activities")||[],e.has_more=n.get("has_more"),e.loadActData=function(t){e.page=t,o({method:"POST",url:apiUrl+"activities",data:{token:c.token(),page:t}}).then(function(t){t.data.page>0?e.activities=e.activities.concat(t.data.data):e.activities=t.data.data,n.save("activities",e.activities),e.has_more=t.data.count+10*t.data.page<t.data.all_count,n.save("has_more",e.has_more),n.save("page",t.data.page),console.log(t.data)},function(t){})},e.activities.length<=0?c.isBind().then(function(){e.loadActData(0)},function(t){e.alertService.showMessage("获取token出错",t)}):i(function(){window.scrollTo(0,n.get("yoffset"))}),e.goDetail=function(t,e,o){n.save("yoffset",window.document.body.scrollTop),a.path("/"+t+"/"+e)},e.addPraise=function(t){s.addCommonPraise(t)},e.decreasePraise=function(t){s.decreaseCommonPraise(t)}}]);
|
||||||
app.controller("AddClassController",["$scope",function(o){}]);
|
app.controller("AddClassController",["$scope",function(o){}]);
|
||||||
app.controller("BlogController",["$scope","$http","$routeParams","auth","common",function(o,n,e,t,a){o.formData={comment:""};var c=function(n){a.loadCommonData(n,"blog_comments").then(function(n){console.log(n.data),o.blog=n.data.data},function(o){})};t.getOpenId().then(function(o){c(e.id)},function(o){alert("获取openid出错:"+o)}),o.addBlogReply=function(n){console.log(n.comment),a.addCommonReply(e.id,"BlogComment",n,function(){o.formData={comment:""},c(e.id)})},o.addPraise=function(o){console.log(o),a.addCommonPraise(o)},o.decreasePraise=function(o){console.log(o),a.decreaseCommonPraise(o)}}]);
|
app.controller("BlogController",["$scope","$http","$routeParams","auth","common",function(o,l,t,n,a){a.init({id:t.id,scope:o,type:"blog_comments",replyType:"BlogComment",loadCallback:function(l){o.blog=l.data},replyCallback:function(){}})}]);
|
||||||
app.controller("CourseNoticeController",["$scope","$http","$routeParams","auth","common",function(o,n,e,t,a){o.formData={comment:""};var c=function(n){a.loadCommonData(n,"newss").then(function(n){console.log(n.data),o.news=n.data.data},function(o){})};t.getOpenId().then(function(o){c(e.id)},function(o){alert("获取openid出错:"+o)}),o.addNoticeReply=function(n){console.log(n.comment),a.addCommonReply(e.id,"News",n,function(){o.formData={comment:""},c(e.id)})},o.addPraise=function(o){a.addCommonPraise(o)},o.decreasePraise=function(o){a.decreaseCommonPraise(o)}}]);
|
app.controller("CourseNoticeController",["$scope","$http","$routeParams","auth","common",function(o,e,t,n,a){a.init({id:t.id,scope:o,type:"newss",replyType:"News",loadCallback:function(e){o.news=e.data},replyCallback:function(){}})}]);
|
||||||
app.controller("DiscussionController",["$scope","$http","$routeParams","auth","common",function(o,n,a,e,t){o.formData={comment:""};var i=function(n){t.loadCommonData(n,"messages").then(function(n){console.log(n.data),o.discussion=n.data.data},function(o){})};e.getOpenId().then(function(o){i(a.id)},function(o){alert("获取openid出错:"+o)}),o.addDiscussionReply=function(n){console.log(n.comment),t.addCommonReply(a.id,"Message",n,function(){o.formData={comment:""},i(a.id)})},o.addPraise=function(o){t.addCommonPraise(o)},o.decreasePraise=function(o){t.decreaseCommonPraise(o)}}]);
|
app.controller("DiscussionController",["$scope","$http","$routeParams","auth","common",function(o,s,a,e,n){n.init({id:a.id,scope:o,type:"messages",replyType:"Message",loadCallback:function(s){o.discussion=s.data},replyCallback:function(){}})}]);
|
||||||
app.controller("HomeworkController",["$scope","$http","$routeParams","auth","common",function(o,n,e,a,t){o.formData={comment:""};var m=function(n){t.loadCommonData(n,"whomeworks").then(function(n){console.log(n.data),o.homework=n.data.data},function(o){})};a.getOpenId().then(function(o){m(e.id)},function(o){alert("获取openid出错:"+o)}),o.addHomeworkReply=function(n){console.log(n.comment),t.addCommonReply(e.id,"HomeworkCommon",n,function(){o.formData={comment:""},m(e.id)})},o.addPraise=function(o){t.addCommonPraise(o)},o.decreasePraise=function(o){t.decreaseCommonPraise(o)}}]);
|
app.controller("HomeworkController",["$scope","$http","$routeParams","auth","common",function(o,e,l,n,r){r.init({id:l.id,scope:o,type:"whomeworks",replyType:"HomeworkCommon",loadCallback:function(e){console.log(e),o.homework=e.data},replyCallback:function(){}})}]);
|
||||||
app.controller("IssueController",["$scope","$http","$routeParams","auth","common",function(o,n,e,a,t){o.formData={comment:""};var s=function(n){t.loadCommonData(n,"issues").then(function(n){console.log(n.data),o.issue=n.data.data},function(o){})};a.getOpenId().then(function(o){s(e.id)},function(o){alert("获取openid出错:"+o)}),o.addIssueReply=function(n){console.log(n.comment),t.addCommonReply(e.id,"Issue",n,function(){o.formData={comment:""},s(e.id)})},o.addPraise=function(o){t.addCommonPraise(o)},o.decreasePraise=function(o){t.decreaseCommonPraise(o)}}]);
|
app.controller("IssueController",["$scope","$http","$routeParams","auth","common",function(o,e,l,s,t){t.init({id:l.id,scope:o,type:"issues",replyType:"Issue",loadCallback:function(e){console.log(e),o.issue=e.data},replyCallback:function(){}})}]);
|
||||||
app.controller("JournalsController",["$scope","$http","$routeParams","auth","common",function(o,n,a,e,t){o.formData={comment:""};var c=function(n){t.loadCommonData(n,"journal_for_messages").then(function(n){console.log(n.data),o.message=n.data.data},function(o){})};e.getOpenId().then(function(o){c(a.id)},function(o){alert("获取openid出错:"+o)}),o.addJournalReply=function(n){console.log(n.comment),t.addCommonReply(a.id,"JournalsForMessage",n,function(){o.formData={comment:""},c(a.id)})},o.addPraise=function(o){console.log(o),t.addCommonPraise(o)},o.decreasePraise=function(o){console.log(o),t.decreaseCommonPraise(o)}}]);
|
app.controller("JournalsController",["$scope","$http","$routeParams","auth","common",function(o,a,e,l,n){n.init({id:e.id,scope:o,type:"journal_for_messages",replyType:"JournalsForMessage",loadCallback:function(a){o.message=a.data},replyCallback:function(){}})}]);
|
||||||
|
app.controller("LoginController",["$scope","$http","$location","$routeParams","alertService","config","auth","session",function(e,o,t,i,a,n,s,r){s.isBind().then(function(){t.path("/activities")}),i.code&&r.save("code",i.code);var l=e;l.loginFailed=!1,l.alertService=a.create(),l.findPwdDialog=a.create(),l.login=function(i,a){return i.$setSubmitted(),console.log(a),i.$valid?(console.log(apiUrl+"auth"),void s.openid().then(function(e){return o.post(n.apiUrl+"users/wxbind",{login:a.login,password:a.password,openid:e})}).then(function(o){console.log(o.data),l.loginFailed=0!=o.data.status,e.loginFailed?l.alertService.showMessage("出错了",o.data.message):l.alertService.showMessage("提示",o.data.message,function(){t.path("/activities")})})["catch"](function(e){l.alertService.showMessage("出错了",e)})):void console.log(i.$error)},l.showBox=function(){l.findPwdDialog.showMessage("提示","请访问www.trustie.net获取密码,谢谢!")},l.goReg=function(){t.path("/reg")}}]);
|
||||||
|
app.controller("RegController",["$scope","$http","$location","alertService",function(e,o,a,r){var s=e;s.errDialog=r.create(),s.goLogin=function(){a.path("/login")},s.isagreed=!0,s.agreed=function(e){s.isagreed=!e},s.reg=function(e,a){return e.$setSubmitted(),console.log(e),e.$valid?(console.log(a),void o.post(apiUrl+"users",{login:a.username,password:a.password,mail:a.email}).then(function(e){0!=e.data.status?s.errDialog.showMessage("出错了",e.data.message):s.errDialog.showMessage("提示","注册且绑定微信成功")},function(e){s.errDialo.showMessage("出错了",e.data)})):void console.log(e.$error)}}]);
|
||||||
|
app.directive("myAlert",["config",function(t){return{templateUrl:t.rootPath+"templates/alert.html",scope:{title:"=",message:"=",visible:"=",cb:"="},link:function(t){t.dismiss=function(){"function"==typeof t.cb&&t.cb()}}}}]);
|
||||||
|
app.directive("pwdconfirm",function(){return{require:"ngModel",link:function(r,n,i,e){e.$validators.pwdconfirm=function(n,i){return r.user&&r.user.password==i}}}});
|
||||||
app.directive("inputAuto",function(){return{restrict:"A",scope:{},link:function(n,t){var e=t.parent().children().eq(0),i=t.parent().next();t.on("input",function(){console.log(i),e.html(t[0].value);var n=e[0].scrollHeight;t.css("height",n+"px")}),i.on("click",function(){t.css("height","28px")})}}});
|
app.directive("inputAuto",function(){return{restrict:"A",scope:{},link:function(n,t){var e=t.parent().children().eq(0),i=t.parent().next();t.on("input",function(){console.log(i),e.html(t[0].value);var n=e[0].scrollHeight;t.css("height",n+"px")}),i.on("click",function(){t.css("height","28px")})}}});
|
||||||
app.directive("loadingSpinner",["$http",function(i){return{restrict:"A",replace:!0,template:'<div ng-show="activeCalls>0" class="loading-bg"><div class="loading-box"><img src="/images/loading.gif" alt=""/><span>加载中...</span></div></div>'}}]);
|
app.directive("loadingSpinner",["$http",function(i){return{restrict:"A",replace:!0,template:'<div ng-show="activeCalls>0" class="loading-bg"><div class="loading-box"><img src="/images/loading.gif" alt=""/><span>加载中...</span></div></div>'}}]);
|
||||||
app.config(["$routeProvider","$httpProvider","$locationProvider",function(e,r,t){var o="/assets/wechat/";e.when("/activites",{templateUrl:o+"activities.html",controller:"ActivityController"}).when("/issues/:id",{templateUrl:o+"issue_detail.html",controller:"IssueController"}).when("/project_discussion/:id",{templateUrl:o+"project_discussion.html",controller:"DiscussionController"}).when("/homework/:id",{templateUrl:o+"homework_detail.html",controller:"HomeworkController"}).when("/course_notice/:id",{templateUrl:o+"course_notice.html",controller:"CourseNoticeController"}).when("/course_discussion/:id",{templateUrl:o+"course_discussion.html",controller:"DiscussionController"}).when("/journal_for_message/:id",{templateUrl:o+"jour_message_detail.html",controller:"JournalsController"}).when("/blog_comment/:id",{templateUrl:o+"blog_detail.html",controller:"BlogController"}).when("/add_class",{templateUrl:o+"add_class.html",controller:"AddClassController"}).otherwise({redirectTo:"/activites"}),r.interceptors.push(["$q","$rootScope",function(e,r){return void 0==r.activeCalls&&(r.activeCalls=0),{request:function(e){return r.activeCalls+=1,e},requestError:function(e){return r.activeCalls-=1,e},response:function(e){return r.activeCalls-=1,e},responseError:function(e){return r.activeCalls-=1,e}}}])}]);
|
app.config(["$routeProvider","$httpProvider","$locationProvider","config",function(e,o,r,t){var l=t.rootPath,n={delay:["auth",function(e){return e.isBind()}]},i=function(e,o){return{templateUrl:l+e,controller:o,resolve:n}};e.when("/login",{templateUrl:l+"login.html",controller:"LoginController"}).when("/reg",{templateUrl:l+"reg.html",controller:"RegController"}).when("/activites",i("activities.html","ActivityController")).when("/issues/:id",i("issue_detail.html","IssueController")).when("/project_discussion/:id",i("project_discussion.html","DiscussionController")).when("/homework/:id",i("homework_detail.html","HomeworkController")).when("/course_notice/:id",i("course_notice.html","CourseNoticeController")).when("/course_discussion/:id",i("course_discussion.html","DiscussionController")).when("/journal_for_message/:id",i("jour_message_detail.html","JournalsController")).when("/blog_comment/:id",i("blog_detail.html","BlogController")).when("/add_class",i("add_class.html","AddClassController")).otherwise({redirectTo:"/activites"}),o.interceptors.push(["$q","$rootScope",function(e,o){return void 0==o.activeCalls&&(o.activeCalls=0),{request:function(e){return o.activeCalls+=1,e},requestError:function(e){return o.activeCalls-=1,e},response:function(e){return o.activeCalls-=1,e},responseError:function(e){return o.activeCalls-=1,e}}}])}]);
|
Loading…
Reference in New Issue