解决没绑定用户不跳转到绑定页问题

This commit is contained in:
guange 2016-07-25 16:59:52 +08:00
parent 5bd3e98f56
commit 9d2900d58f
8 changed files with 48 additions and 17 deletions

View File

@ -51,7 +51,7 @@ gem 'elasticsearch-rails'
### profile ### profile
gem 'oneapm_rpm' # gem 'oneapm_rpm'
group :development do group :development do
gem 'grape-swagger' gem 'grape-swagger'

View File

@ -43,9 +43,9 @@ module Mobile
end end
def current_user def current_user
openid = params[:openid] openid = session[:wechat_openid]
if openid if openid
uw = UserWechat.find_by_openid(params[:openid]) uw = UserWechat.find_by_openid(openid)
return uw.user if uw return uw.user if uw
end end

View File

@ -0,0 +1,13 @@
#coding=utf-8
#
module Mobile
module Exceptions
class AuthException < StandardError
attr_reader :err_code, :msg
def initialize(code, msg)
@err_code = code
@msg = msg
end
end
end
end

View File

@ -1,3 +1,6 @@
#coding=utf-8
module Mobile module Mobile
module Middleware module Middleware
class ErrorHandler < Grape::Middleware::Base class ErrorHandler < Grape::Middleware::Base
@ -6,7 +9,10 @@ module Mobile
begin begin
@app.call(@env) @app.call(@env)
rescue =>e rescue =>e
message = {status: 1, message: e.message }.to_json code = 1
message = {status: code, message: e.message }.to_json
Rails.logger.error e.inspect Rails.logger.error e.inspect
Rails.logger.error e.backtrace.join("\n") Rails.logger.error e.backtrace.join("\n")
status = 200 status = 200

View File

@ -288,8 +288,7 @@ class WechatsController < ActionController::Base
session[:wechat_code] = params[:code] if params[:code] session[:wechat_code] = params[:code] if params[:code]
openid = get_openid_from_code(params[:code]) openid = get_openid_from_code(params[:code])
@wechat_user = user_binded?(openid) @wechat_user = user_binded?(openid)
render 'wechats/user_activities', layout: nil
render 'wechats/login', layout: 'base_wechat'
end end
def user_activities def user_activities
@ -299,13 +298,18 @@ class WechatsController < ActionController::Base
unless open_id unless open_id
render 'wechats/open_wechat', layout: nil and return render 'wechats/open_wechat', layout: nil and return
end end
if params[:state] == 'myclass'
@course_id = params[:id]; unless user_binded?(open_id)
end @path = '/login'
else
if params[:state] == 'myclass'
@course_id = params[:id];
end
session[:wechat_openid] = open_id session[:wechat_openid] = open_id
if params[:code] if params[:code]
redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return
end
end end
render 'wechats/user_activities', layout: nil render 'wechats/user_activities', layout: nil
end end

View File

@ -10,7 +10,7 @@ module Redmine
def acts_as_watchable(options = {}) def acts_as_watchable(options = {})
return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods) return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods)
class_eval do class_eval do
has_many :watchers, :as => :watchable, :dependent => :delete_all has_many :watchers, :dependent => :delete_all
has_many :watcher_users, :through => :watchers, :source => :user, :validate => false has_many :watcher_users, :through => :watchers, :source => :user, :validate => false
scope :watched_by, lambda { |user_id| scope :watched_by, lambda { |user_id|

View File

@ -60,7 +60,7 @@ app.factory('auth', ['$http','$routeParams', '$q', 'session', 'config',function(
} }
var getToken = function(){ var getToken = function(){
return session.get("token"); return 'token';//session.get("token");
} }
return {get_bind: isBind, token: getToken}; return {get_bind: isBind, token: getToken};
}]); }]);
@ -300,4 +300,4 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config', function(
} }
return {init: init, addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise}; return {init: init, addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise};
}]); }]);

View File

@ -8,8 +8,8 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func
var makeRoute = function(path, ctrl){ var makeRoute = function(path, ctrl){
return { return {
templateUrl: rootPath + path, templateUrl: rootPath + path,
controller: ctrl, controller: ctrl
resolve: resolve //resolve: resolve
} }
} }
//$locationProvider.html5Mode(true); //$locationProvider.html5Mode(true);
@ -59,6 +59,14 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func
return rejection; return rejection;
}, },
response: function (response) { response: function (response) {
// var data = response.data;
// if(data && data.status==405){
// var rootScope = $injector.get('$rootScope');
// var state = $injector.get('$rootScope').$state.current.name;
// rootScope.stateBeforLogin = state;
// rootScope.$state.go("login");
// return $q.reject(response);
// }
$rootScope.activeCalls -= 1; $rootScope.activeCalls -= 1;
return response; return response;
}, },