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

This commit is contained in:
yuanke 2016-08-11 17:22:48 +08:00
parent 03551dfba9
commit 4e6c58ae37
12 changed files with 141 additions and 85 deletions

View File

@ -15,6 +15,24 @@ module Mobile
end
post ':id' do
# 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
tip = 0 #0班级1项目
type = params[:type]
@ -25,32 +43,37 @@ module Mobile
homework_common = HomeworkCommon.find(params[:id])
#如果是私有的 并且不是成员则不能回复
is_public = homework_common.course.is_public
if is_public == 0 && !current_user.member_of_course?(homework_common.course)
status = -1
tip = 0
else
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
# is_public = homework_common.course.is_public
# if is_public == 0 && !current_user.member_of_course?(homework_common.course)
# status = -1
# tip = 0
# else
# 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
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
when "News"
news = News.find(params[:id])
if news.project
if news.project.is_public == false && !current_user.member_of?(news.project)
status = -1
tip = 1
end
elsif news.course
if news.course.is_public == 0 && !current_user.member_of_course?(news.course)
status = -1
tip = 0
end
end
# if news.project
# if news.project.is_public == false && !current_user.member_of?(news.project)
# status = -1
# tip = 1
# end
# elsif news.course
# if news.course.is_public == 0 && !current_user.member_of_course?(news.course)
# status = -1
# tip = 0
# end
# end
if status == 0
comment = Comment.new
@ -64,17 +87,17 @@ module Mobile
message = Message.find(params[:id])
board = Board.find(message.board_id)
if message.project
if message.project.is_public == false && !current_user.member_of?(message.project)
status = -1
tip = 1
end
elsif message.course
if message.course.is_public == 0 && !current_user.member_of_course?(message.course)
status = -1
tip = 0
end
end
# if message.project
# if message.project.is_public == false && !current_user.member_of?(message.project)
# status = -1
# tip = 1
# end
# elsif message.course
# if message.course.is_public == 0 && !current_user.member_of_course?(message.course)
# status = -1
# tip = 0
# end
# end
if status == 0
topic = message.root
@ -91,17 +114,17 @@ module Mobile
when "JournalsForMessage"
jour = JournalsForMessage.find params[:id]
if jour.jour_type == "Project"
if jour.project.is_public == false && !current_user.member_of?(jour.project)
status = -1
tip = 1
end
elsif jour.jour_type == "Course"
if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course)
status = -1
tip = 0
end
end
# if jour.jour_type == "Project"
# if jour.project.is_public == false && !current_user.member_of?(jour.project)
# status = -1
# tip = 1
# end
# elsif jour.jour_type == "Course"
# if jour.course.is_public == 0 && !current_user.member_of_course?(jour.course)
# status = -1
# tip = 0
# end
# end
if status == 0
parent_id = params[:id]
@ -125,10 +148,10 @@ module Mobile
when 'Issue'
issue = Issue.find params[:id]
if issue.project.is_public == false && !current_user.member_of?(issue.project)
status = -1
tip = 1
end
# if issue.project.is_public == false && !current_user.member_of?(issue.project)
# status = -1
# tip = 1
# end
if status == 0
is_jour = Journal.new

View File

@ -54,21 +54,34 @@ module Mobile
requires :password, type: String, desc: 'password'
end
post do
openid = session[:wechat_openid]
logger.debug "openid ============== #{openid}"
# raise "无法获取到openid,请在微信中打开本页面" 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.binding_succ_notice(user.id, "您已成功绑定Trustie平台。", user.login, Time.now.strftime("%Y-%m-%d"))
present :data, user, with: Mobile::Entities::User

View File

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

View File

@ -1,6 +1,6 @@
class UserWechat < ActiveRecord::Base
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
end

View File

@ -112,9 +112,11 @@ class WechatService
end
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
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
data = {
touser:openid,
@ -144,9 +146,11 @@ class WechatService
end
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
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
data = {
@ -181,9 +185,11 @@ class WechatService
end
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
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
data = {
@ -227,7 +233,7 @@ class WechatService
data = {
touser:uw.openid,
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",
data:{
first: {
@ -315,7 +321,7 @@ class WechatService
data = {
touser:uw.openid,
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",
data:{
first: {
@ -356,7 +362,7 @@ class WechatService
data = {
touser:uw.openid,
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",
data:{
first: {

View File

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

View File

@ -24,6 +24,10 @@ default: &default
create_project_notice: "jYu0iimbDpgWYZaTLXioZe2lvqoWTdKnUPyphTJ1mxs"
project_review_notice: "kdb-8UlMjTc3z51Qcf8g2vY4i_nE4OGKZAucdQma_2E"
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:
<<: *default

View File

@ -25,6 +25,10 @@ default: &default
project_review_notice: "ip192wVXTav3qchgUn9_7B6lFfTlCZjwL7A1tncTOuc"
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:
<<: *default

View File

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

View File

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

View File

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

View File

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