From 962a62577b550e47d6a29073a5c562a531fa0c0d Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 12:13:04 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 7a703bbc8..549fd493f 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -23,7 +23,21 @@ module Mobile refresh_token = session[:refresh_token] if access_token.present? && refresh_token.present? - refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) + begin + refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) + rescue + info = wechat.web_access_token(session[:wechat_code]) + openid =info["openid"] + access_token =info["access_token"] + if access_token + session[:access_token] = access_token + end + refresh_token = info["refresh_token"] + if refresh_token + session[:refresh_token] = refresh_token + end + refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) + end access_token = refreshinfo["access_token"] refresh_token = refreshinfo["refresh_token"] From 94777a42c4aa31cf93f9466e376077b533b02d6b Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 12:16:30 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=8E=B7=E5=8F=96refresh=5Ftoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 549fd493f..02411c080 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -26,7 +26,7 @@ module Mobile begin refreshinfo = Wechat.api.web_refresh_access_token(refresh_token) rescue - info = wechat.web_access_token(session[:wechat_code]) + info = Wechat.api.web_access_token(session[:wechat_code]) openid =info["openid"] access_token =info["access_token"] if access_token From 6eca6253dbaade78cb83d01a18857932286dae02 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 12:29:10 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 5 +++-- app/api/mobile/apis/users.rb | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 02411c080..872225e47 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -56,9 +56,10 @@ module Mobile user = us.register ({:login=>openid, :mail=>"#{openid}@163.com", :password=>"12345678", :password_confirmation=>"12345678", :should_confirmation_password => true}) - user.update_attributes(:lastname=>name) - raise user.errors.full_messages.first if user.new_record? + user.update_attributes(:lastname=>name) + #自动激活 + user = automatically_register(user) UserWechat.create!( openid: openid, user: user, diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 62376dc6e..08f037588 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -2,6 +2,7 @@ module Mobile module Apis class Users < Grape::API + include AccountHelper resource :users do desc "查询是否已绑定" @@ -68,6 +69,8 @@ module Mobile user = us.register params.merge(:password_confirmation => params[:password], :should_confirmation_password => true) raise user.errors.full_messages.first if user.new_record? + #自动激活 + user = automatically_register(user) if uw && !uw.real? user.update_attributes(:lastname=>uw.user[:lastname]) From 0fc6b845844e2f60b46109790b42a2ae5e80bd14 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 12:32:47 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 872225e47..ad02762d4 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -5,6 +5,7 @@ module Mobile class NewComment< Grape::API include ApplicationHelper include ApiHelper + include AccountHelper resources :new_comment do desc "add a new comment" From f50cfe159c7a8079239baed213f54c7a58386ef2 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 12:35:03 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user_wechat.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/user_wechat.rb b/app/models/user_wechat.rb index 8328a47df..c63411ab3 100644 --- a/app/models/user_wechat.rb +++ b/app/models/user_wechat.rb @@ -22,5 +22,6 @@ class UserWechat < ActiveRecord::Base Comment.where(author_id: old_user).update_all(author_id: u.id) Message.where(author_id: old_user).update_all(author_id: u.id) BlogComment.where(author_id: old_user).update_all(author_id: u.id) + UserActivity.where(user_id: old_user).update_all(user_id: u.id) end end From e17683d3d5a7f51fa2fcb5c253bd72846b8ad1ca Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 12:42:39 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B8=90=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index ad02762d4..d4a156271 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -60,7 +60,7 @@ module Mobile raise user.errors.full_messages.first if user.new_record? user.update_attributes(:lastname=>name) #自动激活 - user = automatically_register(user) + user = AccountHelper.automatically_register(user) UserWechat.create!( openid: openid, user: user, From 22e4e56029597c8e9ca7e391a5877dc3be89d1fc Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 13:24:07 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=BF=80=E6=B4=BB=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 10 ++++++++-- app/api/mobile/apis/users.rb | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index d4a156271..228fee157 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -5,7 +5,6 @@ module Mobile class NewComment< Grape::API include ApplicationHelper include ApiHelper - include AccountHelper resources :new_comment do desc "add a new comment" @@ -17,6 +16,7 @@ module Mobile unless current_user #如果当前用户不存在 则需要根据微信昵称注册一个帐号 openid = session[:wechat_openid] + openid = "asfsdf" raise "无法获取到openid,请在微信中打开本页面" unless openid us = UsersService.new @@ -60,7 +60,13 @@ module Mobile raise user.errors.full_messages.first if user.new_record? user.update_attributes(:lastname=>name) #自动激活 - user = AccountHelper.automatically_register(user) + if Setting.self_registration != '3' + user.activate + user.last_login_on = Time.now + if user.save + UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) + end + end UserWechat.create!( openid: openid, user: user, diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 08f037588..53884f779 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -2,7 +2,6 @@ module Mobile module Apis class Users < Grape::API - include AccountHelper resource :users do desc "查询是否已绑定" @@ -70,7 +69,14 @@ module Mobile :should_confirmation_password => true) raise user.errors.full_messages.first if user.new_record? #自动激活 - user = automatically_register(user) + if Setting.self_registration != '3' + # user = automatically_register(user) + user.activate + user.last_login_on = Time.now + if user.save + UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) + end + end if uw && !uw.real? user.update_attributes(:lastname=>uw.user[:lastname]) From 2f8b459a6f67efaa9fd2f25e6142674d2585e96d Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 13:35:00 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=BF=80=E6=B4=BB=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 228fee157..6d46b2f59 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -16,7 +16,6 @@ module Mobile unless current_user #如果当前用户不存在 则需要根据微信昵称注册一个帐号 openid = session[:wechat_openid] - openid = "asfsdf" raise "无法获取到openid,请在微信中打开本页面" unless openid us = UsersService.new From f9ee56111fc44d0742a75c12d306b0c775566ed8 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 14 Aug 2016 13:46:46 +0800 Subject: [PATCH 9/9] . --- Gemfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 39a181d05..80c0e1c2a 100644 --- a/Gemfile +++ b/Gemfile @@ -50,16 +50,16 @@ gem 'elasticsearch-model' gem 'elasticsearch-rails' #rails 3.2.22.2 bug - # gem "test-unit", "~>3.0" + gem "test-unit", "~>3.0" ### profile - # gem 'oneapm_rpm' + gem 'oneapm_rpm' group :development do gem 'grape-swagger' gem 'better_errors', '~> 1.1.0' # gem "query_reviewer" - # gem 'rack-mini-profiler', '~> 0.9.3' + gem 'rack-mini-profiler', '~> 0.9.3' if RUBY_PLATFORM =~ /w32/ gem 'win32console' end