Merge branch 'weixin_guange' of https://git.trustie.net/jacknudt/trustieforge into weixin_guange

weixin_guange
yuanke 9 years ago
commit 3a83b40a64

@ -11,50 +11,18 @@ module Mobile
params do params do
requires :type, type: String requires :type, type: String
requires :content, type: String requires :content, type: String
requires :token, type: String
end end
post ':id' do post ':id' do
# authenticate!
unless current_user unless current_user
#如果当前用户不存在 则需要根据微信昵称注册一个帐号 #如果当前用户不存在 则需要根据微信昵称注册一个帐号
openid = session[:wechat_openid] openid = session[:wechat_openid]
raise "无法获取到openid,请在微信中打开本页面" unless openid raise "无法获取到openid,请在微信中打开本页面" unless openid
us = UsersService.new us = UsersService.new
#login mail password
#根据openid生成一个用户名
openid_length = openid.length
login = openid[0..10]+openid[openid_length-3..openid_length-1]+Time.now.to_i.to_s
access_token = session[:access_token]
refresh_token = session[:refresh_token]
Rails.logger.info "session!!!!!!!!!"
Rails.logger.info session
if access_token && refresh_token
#先刷新下access_token 已防止过期
refreshinfo = Wechat.api.web_refresh_access_token(refresh_token)
access_token = refreshinfo["access_token"]
refresh_token = refreshinfo["refresh_token"]
session[:access_token] = access_token
session[:refresh_token] = refresh_token
#获取用户信息
userinfo = Wechat.api.web_userinfo(access_token,openid)
Rails.logger.info "userinfo!!!!!!!!!"
Rails.logger.info userinfo
name = userinfo["nickname"]
else
name = openid[0..3]+"***"+openid.last
end
user = us.register ({:login=>login, :mail=>login+"@163.com", user = us.register ({:login=>openid, :mail=>"#{openid}@163.com",
:password=>"12345678", :password_confirmation=>"12345678", :password=>"12345678", :password_confirmation=>"12345678",
:should_confirmation_password => true}) :should_confirmation_password => true})
user.update_attributes(:lastname=>name)
raise user.errors.full_messages.first if user.new_record? raise user.errors.full_messages.first if user.new_record?
UserWechat.create!( UserWechat.create!(
openid: openid, openid: openid,
@ -63,6 +31,8 @@ module Mobile
) )
end end
authenticate!
status = 0 status = 0
tip = 0 #0班级1项目 tip = 0 #0班级1项目
type = params[:type] type = params[:type]

@ -228,7 +228,7 @@ class User < Principal
# Prevents unauthorized assignments # Prevents unauthorized assignments
attr_protected :login, :admin, :password, :password_confirmation, :hashed_password attr_protected :login, :admin, :password, :password_confirmation, :hashed_password
LOGIN_LENGTH_LIMIT = 25 LOGIN_LENGTH_LIMIT = 30
MAIL_LENGTH_LIMIT = 60 MAIL_LENGTH_LIMIT = 60
validates_presence_of :login, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } validates_presence_of :login, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }

@ -17,7 +17,7 @@
window.g_debug = false; //调试标志,如果在本地请置为true window.g_debug = false; //调试标志,如果在本地请置为true
window.apiUrl = '/api/v1/'; window.apiUrl = '/api/v1/';
window.g_redirect_path = '<%= @path %>'; window.g_redirect_path = '<%= @path %>';
window.g_localhost = "https://"+"<%= Setting.host_name%>"; window.g_localhost = "<%= Setting.protocol %>"+ "://"+"<%= Setting.host_name%>";
window.g_appid = "<%= @appid %>"; window.g_appid = "<%= @appid %>";
<% if @course_id %> <% if @course_id %>
window.g_courseid = <%= @course_id %>; window.g_courseid = <%= @course_id %>;

File diff suppressed because it is too large Load Diff

@ -268,12 +268,12 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc
var urlName = response.data.type_name + "_discussion"; var urlName = response.data.type_name + "_discussion";
link = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+window.g_appid + 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+ "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+response.data.data.act_id+
"&response_type=code&scope=snsapi_userinfo&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="+window.g_appid + 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+ "&redirect_uri="+window.g_localhost+"/wechat/user_activities?id="+response.data.data.act_id+
"&response_type=code&scope=snsapi_userinfo&state="+args.urlName+"&connect_redirect=1#wechat_redirect"; "&response_type=code&scope=snsapi_base&state="+args.urlName+"&connect_redirect=1#wechat_redirect";
} }
// if(args.urlName == "discussion"){ // if(args.urlName == "discussion"){

Loading…
Cancel
Save