动态点提交如果没绑定则自动创建一个帐号绑定,然后注册的时候将已绑定的用户信息修改为注册的信息

weixin_guange
yuanke 9 years ago
parent 03551dfba9
commit 4e6c58ae37

@ -15,6 +15,24 @@ module Mobile
end end
post ':id' do post ':id' do
# authenticate! # authenticate!
unless current_user
#如果当前用户不存在
openid = session[:wechat_openid]
raise "请在微信中关注Trustie创新实践平台后再打开本页面" unless openid
us = UsersService.new
#login mail password
user = us.register ({:login=>openid, :mail=>openid+"@163.com",
:password=>"12345678", :password_confirmation=>"12345678", :should_confirmation_password => true})
raise user.errors.full_messages.first if user.new_record?
UserWechat.create!(
openid: openid,
user: user,
bindtype: 1
)
end
status = 0 status = 0
tip = 0 #0班级1项目 tip = 0 #0班级1项目
type = params[:type] type = params[:type]
@ -25,32 +43,37 @@ module Mobile
homework_common = HomeworkCommon.find(params[:id]) homework_common = HomeworkCommon.find(params[:id])
#如果是私有的 并且不是成员则不能回复 #如果是私有的 并且不是成员则不能回复
is_public = homework_common.course.is_public # is_public = homework_common.course.is_public
if is_public == 0 && !current_user.member_of_course?(homework_common.course) # if is_public == 0 && !current_user.member_of_course?(homework_common.course)
status = -1 # status = -1
tip = 0 # tip = 0
else # else
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id]) # feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
if (feedback.errors.empty?) # if (feedback.errors.empty?)
homework_common.update_column(:updated_at, Time.now) # homework_common.update_column(:updated_at, Time.now)
result = 2 # result = 2
end # end
# end
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
if (feedback.errors.empty?)
homework_common.update_column(:updated_at, Time.now)
result = 2
end end
when "News" when "News"
news = News.find(params[:id]) news = News.find(params[:id])
if news.project # if news.project
if news.project.is_public == false && !current_user.member_of?(news.project) # if news.project.is_public == false && !current_user.member_of?(news.project)
status = -1 # status = -1
tip = 1 # tip = 1
end # end
elsif news.course # elsif news.course
if news.course.is_public == 0 && !current_user.member_of_course?(news.course) # if news.course.is_public == 0 && !current_user.member_of_course?(news.course)
status = -1 # status = -1
tip = 0 # tip = 0
end # end
end # end
if status == 0 if status == 0
comment = Comment.new comment = Comment.new
@ -64,17 +87,17 @@ module Mobile
message = Message.find(params[:id]) message = Message.find(params[:id])
board = Board.find(message.board_id) board = Board.find(message.board_id)
if message.project # if message.project
if message.project.is_public == false && !current_user.member_of?(message.project) # if message.project.is_public == false && !current_user.member_of?(message.project)
status = -1 # status = -1
tip = 1 # tip = 1
end # end
elsif message.course # elsif message.course
if message.course.is_public == 0 && !current_user.member_of_course?(message.course) # if message.course.is_public == 0 && !current_user.member_of_course?(message.course)
status = -1 # status = -1
tip = 0 # tip = 0
end # end
end # end
if status == 0 if status == 0
topic = message.root topic = message.root
@ -91,17 +114,17 @@ module Mobile
when "JournalsForMessage" when "JournalsForMessage"
jour = JournalsForMessage.find params[:id] jour = JournalsForMessage.find params[:id]
if jour.jour_type == "Project" # if jour.jour_type == "Project"
if jour.project.is_public == false && !current_user.member_of?(jour.project) # if jour.project.is_public == false && !current_user.member_of?(jour.project)
status = -1 # status = -1
tip = 1 # tip = 1
end # end
elsif jour.jour_type == "Course" # elsif jour.jour_type == "Course"
if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course) # if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course)
status = -1 # status = -1
tip = 0 # tip = 0
end # end
end # end
if status == 0 if status == 0
parent_id = params[:id] parent_id = params[:id]
@ -125,10 +148,10 @@ module Mobile
when 'Issue' when 'Issue'
issue = Issue.find params[:id] issue = Issue.find params[:id]
if issue.project.is_public == false && !current_user.member_of?(issue.project) # if issue.project.is_public == false && !current_user.member_of?(issue.project)
status = -1 # status = -1
tip = 1 # tip = 1
end # end
if status == 0 if status == 0
is_jour = Journal.new is_jour = Journal.new

@ -54,21 +54,34 @@ module Mobile
requires :password, type: String, desc: 'password' requires :password, type: String, desc: 'password'
end end
post do post do
openid = session[:wechat_openid] openid = session[:wechat_openid]
logger.debug "openid ============== #{openid}" logger.debug "openid ============== #{openid}"
# raise "无法获取到openid,请在微信中打开本页面" unless openid # raise "无法获取到openid,请在微信中打开本页面" unless openid
raise "请在微信中关注Trustie创新实践平台后再打开本页面" unless openid raise "请在微信中关注Trustie创新实践平台后再打开本页面" unless openid
uw = UserWechat.where(openid: openid).first
if uw
uw.bindtype = 0
uw.save
user = uw.user
user[:login] = params[:login]
user[:mail] = params[:mail]
user[:password] = params[:password]
user[:password_confirmation] = params[:password]
user[:should_confirmation_password] = true
user.save!
else
us = UsersService.new
user = us.register params.merge(:password_confirmation => params[:password],
:should_confirmation_password => true)
raise user.errors.full_messages.first if user.new_record?
UserWechat.create!(
openid: openid,
user: user
)
end
us = UsersService.new
user = us.register params.merge(:password_confirmation => params[:password],
:should_confirmation_password => true)
raise user.errors.full_messages.first if user.new_record?
UserWechat.create!(
openid: openid,
user: user
)
ws = WechatService.new ws = WechatService.new
ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.login, Time.now.strftime("%Y-%m-%d")) ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.login, Time.now.strftime("%Y-%m-%d"))
present :data, user, with: Mobile::Entities::User present :data, user, with: Mobile::Entities::User

@ -424,7 +424,7 @@ class WechatsController < ActionController::Base
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]}&userid=#{params[:userid]}" and return
end end
# end # end
render 'wechats/user_activities', layout: nil render 'wechats/user_activities', layout: nil
@ -451,6 +451,7 @@ class WechatsController < ActionController::Base
def user_binded?(openid) def user_binded?(openid)
uw = UserWechat.where(openid: openid).first uw = UserWechat.where(openid: openid).first
uw && uw.bindtype == 0
end end
def current_url def current_url

@ -1,6 +1,6 @@
class UserWechat < ActiveRecord::Base class UserWechat < ActiveRecord::Base
attr_accessible :subscribe, :openid, :nickname, :sex, :language, :city, :province, :country, attr_accessible :subscribe, :openid, :nickname, :sex, :language, :city, :province, :country,
:headimgurl, :subscribe_time, :unionid, :remark, :groupid, :user, :user_id :headimgurl, :subscribe_time, :unionid, :remark, :groupid, :user, :user_id, :bindtype
belongs_to :user belongs_to :user
end end

@ -112,9 +112,11 @@ class WechatService
end end
def two_keys_template(openid, template_id, type, id, first, key1, key2, remark="",uid) def two_keys_template(openid, template_id, type, id, first, key1, key2, remark="",uid)
tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"
tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3
if uid && uid != 0 if uid && uid != 0
tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s
tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3
end end
data = { data = {
touser:openid, touser:openid,
@ -144,9 +146,11 @@ class WechatService
end end
def three_keys_template(openid, template_id, type, id, first, key1, key2, key3, remark="",uid) def three_keys_template(openid, template_id, type, id, first, key1, key2, key3, remark="",uid)
tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"
tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3
if uid && uid != 0 if uid && uid != 0
tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s
tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3
end end
data = { data = {
@ -181,9 +185,11 @@ class WechatService
end end
def four_keys_template(openid, template_id, type, id, first, key1, key2, key3, key4, remark="",uid) def four_keys_template(openid, template_id, type, id, first, key1, key2, key3, key4, remark="",uid)
tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}" # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"
tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3
if uid && uid != 0 if uid && uid != 0
tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s # tmpurl = "#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/#{type}?id=#{id}"+ "&user_id="+uid.to_s
tmpurl = Wechat.config.auto_openid_url_1+"?id="+id.to_s+ "&user_id="+uid.to_s+Wechat.config.auto_openid_url_2+type+Wechat.config.auto_openid_url_3
end end
data = { data = {
@ -227,7 +233,7 @@ class WechatService
data = { data = {
touser:uw.openid, touser:uw.openid,
template_id:Wechat.config.binding_succ_notice, template_id:Wechat.config.binding_succ_notice,
url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities", url:Wechat.config.auto_openid_url_1+Wechat.config.auto_openid_url_2+"activites"+Wechat.config.auto_openid_url_3,
topcolor:"#FF0000", topcolor:"#FF0000",
data:{ data:{
first: { first: {
@ -315,7 +321,7 @@ class WechatService
data = { data = {
touser:uw.openid, touser:uw.openid,
template_id:Wechat.config.create_class_notice, template_id:Wechat.config.create_class_notice,
url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/class?id="+id.to_s, url:Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+"class"+Wechat.config.auto_openid_url_3,
topcolor:"#FF0000", topcolor:"#FF0000",
data:{ data:{
first: { first: {
@ -356,7 +362,7 @@ class WechatService
data = { data = {
touser:uw.openid, touser:uw.openid,
template_id:Wechat.config.create_project_notice, template_id:Wechat.config.create_project_notice,
url:"#{Setting.protocol}://#{Setting.host_name}/wechat/user_activities#/project?id="+id.to_s, url:Wechat.config.auto_openid_url_1+"?id="+id.to_s+Wechat.config.auto_openid_url_2+"project"+Wechat.config.auto_openid_url_3,
topcolor:"#FF0000", topcolor:"#FF0000",
data:{ data:{
first: { first: {

@ -18,6 +18,7 @@
window.apiUrl = '/api/v1/'; window.apiUrl = '/api/v1/';
window.g_redirect_path = '<%= @path %>'; window.g_redirect_path = '<%= @path %>';
window.g_localhost = "<%= Setting.protocol%>://"+"<%= Setting.host_name%>"; window.g_localhost = "<%= Setting.protocol%>://"+"<%= Setting.host_name%>";
window.g_appid = <%= @appid %>
<% if @course_id %> <% if @course_id %>
window.g_courseid = <%= @course_id %>; window.g_courseid = <%= @course_id %>;
<% elsif @project_id %> <% elsif @project_id %>

@ -24,6 +24,10 @@ default: &default
create_project_notice: "jYu0iimbDpgWYZaTLXioZe2lvqoWTdKnUPyphTJ1mxs" create_project_notice: "jYu0iimbDpgWYZaTLXioZe2lvqoWTdKnUPyphTJ1mxs"
project_review_notice: "kdb-8UlMjTc3z51Qcf8g2vY4i_nE4OGKZAucdQma_2E" project_review_notice: "kdb-8UlMjTc3z51Qcf8g2vY4i_nE4OGKZAucdQma_2E"
join_project_notice: "TtXvy0XMIQyCgpnXHhoB8t-x0QIfy-78gAJXsGf9afg" join_project_notice: "TtXvy0XMIQyCgpnXHhoB8t-x0QIfy-78gAJXsGf9afg"
auto_openid_url_1: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=https://www.trustie.net/wechat/user_activities"
auto_openid_url_2: "&response_type=code&scope=snsapi_base&state="
auto_openid_url_3: "&connect_redirect=1#wechat_redirect"
production: production:
<<: *default <<: *default

@ -25,6 +25,10 @@ default: &default
project_review_notice: "ip192wVXTav3qchgUn9_7B6lFfTlCZjwL7A1tncTOuc" project_review_notice: "ip192wVXTav3qchgUn9_7B6lFfTlCZjwL7A1tncTOuc"
join_project_notice: "3KnMQEMUCmQWkB5JvzrpmguEwnN8bvUHUdpOTudxv_M" join_project_notice: "3KnMQEMUCmQWkB5JvzrpmguEwnN8bvUHUdpOTudxv_M"
auto_openid_url_1: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities"
auto_openid_url_2: "&response_type=code&scope=snsapi_base&state="
auto_openid_url_3: "&connect_redirect=1#wechat_redirect"
production: production:
<<: *default <<: *default

@ -0,0 +1,5 @@
class AddBindtypeToUserWechats < ActiveRecord::Migration
def change
add_column :user_wechats, :bindtype, :integer, :default => 0
end
end

@ -14,8 +14,8 @@ app.controller('InviteCodeController', ['$scope','$http', '$routeParams','config
vm.course = response.data.data; vm.course = response.data.data;
var desc = "您的好友邀请您加入班级:\n"+vm.course.name+"\n和小伙伴一起踏上便捷的学习之旅吧"; var desc = "您的好友邀请您加入班级:\n"+vm.course.name+"\n和小伙伴一起踏上便捷的学习之旅吧";
var link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d" + var link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid+
"&redirect_uri=https://test.forge.trustie.net/wechat/user_activities?id="+vm.course.id+ "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+vm.course.id+
"&response_type=code&scope=snsapi_base&state=invite_code&connect_redirect=1#wechat_redirect"; "&response_type=code&scope=snsapi_base&state=invite_code&connect_redirect=1#wechat_redirect";
common.wxConfig("",desc,"",link); common.wxConfig("",desc,"",link);

@ -14,9 +14,8 @@ app.controller('ProjectInviteCodeController', ['$scope','$http', '$routeParams',
vm.project = response.data.data; vm.project = response.data.data;
var desc = "您的好友邀请您加入项目:\n"+vm.project.name+"\n和小伙伴一起踏上便捷的研发之旅吧"; var desc = "您的好友邀请您加入项目:\n"+vm.project.name+"\n和小伙伴一起踏上便捷的研发之旅吧";
var link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid+
var link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d" + "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+vm.project.id+
"&redirect_uri=https://test.forge.trustie.net/wechat/user_activities?id="+vm.project.id+
"&response_type=code&scope=snsapi_base&state=project_invite_code&connect_redirect=1#wechat_redirect"; "&response_type=code&scope=snsapi_base&state=project_invite_code&connect_redirect=1#wechat_redirect";
common.wxConfig("",desc,"",link); common.wxConfig("",desc,"",link);

@ -96,15 +96,15 @@ app.factory('rms', function(){
app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$location', function($http, auth, $routeParams,rms,config,wx,$location){ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$location', function($http, auth, $routeParams,rms,config,wx,$location){
var addCommonReply = function(id, type, data,args, cb){ var addCommonReply = function(id, type, data,args, cb){
//先判断有没有绑定 //先判断有没有绑定
$http.post( // $http.post(
'/wechat/is_bind', // '/wechat/is_bind',
{} ///不用传code了,都由服务器来处理 // {} ///不用传code了,都由服务器来处理
).then(function(response){ // ).then(function(response){
console.log(response.data); // console.log(response.data);
if(response.data.status != 0){ // if(response.data.status != 0){
$location.path("/login_tip"); // $location.path("/login_tip");
} // }
}); // });
if(!data.comment || data.comment.length<=0){ if(!data.comment || data.comment.length<=0){
return; return;
@ -266,13 +266,13 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc
if(args.urlName == "discussion"){ if(args.urlName == "discussion"){
var urlName = response.data.type_name + "_discussion"; var urlName = response.data.type_name + "_discussion";
link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d" + link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid +
"&redirect_uri=https://test.forge.trustie.net/wechat/user_activities?id="+response.data.data.act_id+ "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+response.data.data.act_id+
"&response_type=code&scope=snsapi_base&state="+urlName+"&connect_redirect=1#wechat_redirect"; "&response_type=code&scope=snsapi_base&state="+urlName+"&connect_redirect=1#wechat_redirect";
} }
else{ else{
link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d" + link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid +
"&redirect_uri=https://test.forge.trustie.net/wechat/user_activities?id="+response.data.data.act_id+ "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+response.data.data.act_id+
"&response_type=code&scope=snsapi_base&state="+args.urlName+"&connect_redirect=1#wechat_redirect"; "&response_type=code&scope=snsapi_base&state="+args.urlName+"&connect_redirect=1#wechat_redirect";
} }

Loading…
Cancel
Save