Merge branch 'develop' into cs_optimize_txz

Conflicts:
	app/views/layouts/new_base.html.erb
	app/views/layouts/new_base_user.html.erb
	app/views/users/_user_resource_info.html.erb
cs_optimize_txz
Tim 9 years ago
commit 1658f78a7b

@ -0,0 +1 @@
{"access_token":"oEEf8ZKAB8Y2G0o_xnTPkPJHKKk8iHkLC-f5ptvQ2nCMj9IpC86ivLD2-p38GfOkuG-HuQp3pWZqhs3NJXUMdPLWsr5k67hPZYuqg4ozLccx0xdLswapj0mn8ovZhK1tKIKiAFAOMO","expires_in":7200,"got_token_at":1467012449}

4
.gitignore vendored

@ -6,6 +6,8 @@
/config/database.yml
/config/configuration.yml
/config/additional_environment.rb
/config/menu.yml
/config/wechat.yml
/files/*
/log/*
@ -31,3 +33,5 @@ vendor/cache
/tags
/config/initializers/gitlab_config.rb
1234567
public/javascripts/wechat/node_modules/
.ruby-version

@ -1,25 +0,0 @@
<html>
<head>
<title>
Client
</title>
</head>
<body>
<hr />
<h2>这是一张图片</h2>
<p>photo<a href="http://10.0.47.15:3000/shares/new?access_token='2d3dda45dsd'&comment='verygood'&title=davide&share_type=1&url=http://www.baidu.com"> Share A </a></p>
<hr />
<h2>这是一段视频</h2>
<p>Text<a href="http://10.0.47.15:3000/shares/new?access_token=2d3dda45dsd&comment=verygood&title=kaka&share_type=2&url=http://www.sina.com"> Share B </a></p>
<hr />
<h2>这是一篇文章</h2>
<p>Text<a href="http://10.0.47.15:3000/shares/new?access_token=2d3dda45dsd&comment=verygood&title=pepe&share_type=3&url=http://www.sina.com"> Share C </a></p>
<hr />
</body>
</html>

@ -1,13 +1,19 @@
source 'https://rubygems.org/'
### 这里执行bundle config mirror.https://rubygems.org https://gems.ruby-china.org 切换到ruby-china源
source 'https://ruby.taobao.org/'
unless RUBY_PLATFORM =~ /w32/
# unix-like only
gem 'iconv'
if RUBY_PLATFORM =~ /darwin/
gem "rmagick", "= 2.15.4" ## osx must be this version
else
gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel
end
gem 'certified'
gem 'net-ssh', '2.9.1'
gem 'jenkins_api_client'
gem 'nokogiri'
end
gem 'certified'
gem 'wechat',path: 'lib/wechat'
gem 'grack', path:'lib/grack'
gem 'gitlab', path: 'lib/gitlab-cli'
@ -31,7 +37,6 @@ gem 'acts-as-taggable-on', '2.4.1'
gem 'spreadsheet'
gem 'ruby-ole'
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
#gem "rmagick", ">= 2.0.0"
gem 'binding_of_caller'
gem 'chinese_pinyin'
# gem 'sunspot_rails', '~> 1.3.3'
@ -81,7 +86,7 @@ group :assets do
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end

@ -1,3 +1,5 @@
#coding=utf-8
module Mobile
require_relative 'middleware/error_handler'
require_relative 'apis/auth'
@ -16,11 +18,13 @@ module Mobile
require_relative 'apis/blog_comments'
require_relative 'apis/new_comment'
require_relative 'apis/praise'
require_relative 'apis/resources'
class API < Grape::API
version 'v1', using: :path
format :json
content_type :json, "application/json;charset=UTF-8"
use ActionDispatch::Session::CookieStore
use Mobile::Middleware::ErrorHandler
helpers do
@ -29,16 +33,26 @@ module Mobile
end
def authenticate!
raise('Unauthorized. Invalid or expired token.') unless current_user
raise('Unauthorized. 用户认证失败.') unless current_user
end
def session
env['rack.session']
end
def current_user
openid = params[:openid]
if openid
uw = UserWechat.find_by_openid(params[:openid])
return uw.user if uw
end
token = ApiKey.where(access_token: params[:token]).first
if token && !token.expired?
@current_user = User.find(token.user_id)
else
nil
return User.find(token.user_id)
end
nil
end
end
@ -58,9 +72,9 @@ module Mobile
mount Apis::BlogComments
mount Apis::NewComment
mount Apis::Praise
mount Apis::Resources
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
end
end

@ -9,38 +9,24 @@ module Mobile
params do
requires :page, type: Integer
requires :openid, type: String
requires :token, type: String
end
post do
user = UserWechat.find_by_openid(params[:openid]).user
=begin
shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
page = params[:page] ? params[:page] : 0
user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
principal_types = "JournalsForMessage"
authenticate!
blog_ids = "("+user.blog.id.to_s+","+((User.watched_by(user.id).count == 0 )? '0' :User.watched_by(user.id).map{|u| u.blog.id}.join(','))+")"
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " +
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc')
=end
user = current_user
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
page = params[:page] ? params[:page] : 0
user_project_ids = (user.projects.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.map{|course| course.id}-shield_course_ids).join(",") + ")"
user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
project_types = "('Message','Issue','Project')"
principal_types = "JournalsForMessage"
watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(','))
user_ids = "(" + user.id.to_s + watched_user_ids + ")"
watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",")
watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").count == 0 ? " " :Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",")
blog_ids = "(" + watched_user_blog_ids + ")"
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +

@ -14,8 +14,9 @@ module Mobile
optional :token, type: String
end
get do
authenticate!
cs = CoursesService.new
courses = cs.course_list(params,current_user.nil? ? User.find(2):current_user)
courses = cs.user_courses_list(current_user)
present :data, courses, with: Mobile::Entities::Course
present :status, 0
end
@ -98,25 +99,19 @@ module Mobile
desc "加入课程"
params do
requires :token, type: String
requires :course_password, type: String
requires :invite_code, type: String, desc: '邀请码'
end
post ":id" do
post "join" do
authenticate!
cs = CoursesService.new
status = cs.join_course({:object_id => params[:id],:course_password => params[:course_password]},current_user)
out = {status: status[:state]}
message = case status[:state]
when 0; "加入成功"
when 1; "密码错误"
when 2; "课程已过期 请联系课程管理员重启课程。(在配置课程处)"
when 3; "您已经加入了课程"
when 4; "您加入的课程不存在"
when 5; "您还未登录"
else; "未知错误,请稍后再试"
end
out.merge(message: message)
status = cs.join_course({role: "10", openid: params[:openid], invite_code: params[:invite_code]}, current_user)
{
status: status[:state],
messsge:CoursesService::JoinCourseError.message(status[:state])
}
end
desc "退出课程"
params do
requires :token, type: String
@ -202,6 +197,7 @@ module Mobile
end
route_param :id do
get do
authenticate!
cs = CoursesService.new
course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user))
#course = Course.find(params[:id])
@ -389,7 +385,16 @@ module Mobile
end
desc '获取测验列表'
params do
requires :token, type:String
end
get ':course_id/exercises' do
authenticate!
exercises = Course.find(params[:course_id]).exercises
present :data,exercises,with:Mobile::Entities::Exercise
present :status,0
end
end
end

@ -8,7 +8,8 @@ module Mobile
desc "get special issuse"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
issue = Issue.find params[:id]
present :data, issue, with: Mobile::Entities::Issue,user: user
present :status, 0

@ -7,7 +7,8 @@ module Mobile
desc "get special journal"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
jour = JournalsForMessage.find params[:id]
present :data, jour, with: Mobile::Entities::Jours,user: user
present :status, 0

@ -7,7 +7,8 @@ module Mobile
desc "get special topic"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
message = Message.find params[:id]
present :data, message, with: Mobile::Entities::Message,user: user
present :status, 0

@ -11,12 +11,12 @@ module Mobile
params do
requires :type, type: String
requires :content, type: String
requires :openid, type: String
requires :token, type: String
end
post ':id' do
authenticate!
type = params[:type]
result = 1
current_user = UserWechat.find_by_openid(params[:openid]).user
if params[:content]!="" && current_user
case type
when "HomeworkCommon"

@ -7,7 +7,8 @@ module Mobile
desc "get special news"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
news = News.find params[:id]
present :data, news, with: Mobile::Entities::News,user: user
present :status, 0

@ -9,12 +9,13 @@ module Mobile
params do
requires :type, type: String
requires :openid, type: String
requires :token, type: String
end
post ':id' do
authenticate!
obj_id = params[:id]
obj_type = params[:type]
user = UserWechat.find_by_openid(params[:openid]).user
user = current_user
pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id).first
if pts.blank?
praise_or_cancel(obj_type,obj_id,user,1)

@ -0,0 +1,55 @@
#coding=utf-8
module Mobile
module Apis
class Resources < Grape::API
resource :resources do
desc '获取所有课件'
params do
requires :token, type: String
end
get do
authenticate!
data = current_user.course_attachments
present :data, data, with: Mobile::Entities::Attachment
present :status, 0
end
desc '获取所有作业'
params do
requires :token, type: String
end
get 'homeworks' do
authenticate!
homeworks = current_user.homework_commons
present :data, homeworks, with: Mobile::Entities::Homework
present :status, 0
end
desc '获取所有测验'
params do
requires :token, type: String
end
get 'exercies' do
authenticate!
exercises = current_user.exercises
present :data, exercises, with: Mobile::Entities::Exercise
present :status, 0
end
end
end
end
end

@ -4,6 +4,48 @@ module Mobile
class Users < Grape::API
resource :users do
desc "查询是否已绑定"
params do
requires :openid, type: String, desc: 'wechat openid'
end
post 'isbind' do
openid = params[:openid]
uw = UserWechat.where(openid: openid).first
raise "还未绑定trustie帐户" unless uw
user = uw.user
::ApiKey.delete_all(user_id: user.id)
key = ::ApiKey.create!(user_id: user.id)
present status: 0, token: key.access_token
end
desc "绑定微信用户"
params do
requires :login, type: String, desc: 'username'
requires :password, type: String, desc: 'password'
end
post 'wxbind' do
openid = session[:wechat_openid]
logger.debug "openid ============== #{openid}"
raise "无法获取到openid,请在微信中打开本页面" unless openid
uw = UserWechat.where(openid: openid).first
raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw
user, last_login_on = User.try_to_login(params[:login], params[:password])
raise "用户名或密码错误,请重新输入" unless user
#补全用户信息
raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat
UserWechat.create!(
openid: openid,
user: user
)
# ws = WechatService.new
# ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now))
present status: 0, message: '您已成功绑定Trustie平台'
end
desc "注册用户"
params do
requires :login, type: String, desc: 'username'

@ -7,7 +7,8 @@ module Mobile
desc "get one homework"
get ':id' do
user = UserWechat.find_by_openid(params[:openid]).user
authenticate!
user = current_user
homework = HomeworkCommon.find params[:id]
present :data, homework, with: Mobile::Entities::Whomework,user: user
present :status, 0

@ -14,7 +14,7 @@ module Mobile
else
case f
when :user_act
if ac.act_type == "ProjectCreateInfo"
if ac.act_type == "Project"
ac unless ac.nil?
else
ac.act unless ac.nil? || ac.act.nil?
@ -41,11 +41,11 @@ module Mobile
end
when :description
if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News"
ac.act.description unless ac.nil? || ac.act.nil?
strip_html(ac.act.description) unless ac.nil? || ac.act.nil?
elsif ac.act_type == "Message" || ac.act_type == "BlogComment"
ac.act.content unless ac.nil? || ac.act.nil?
strip_html(ac.act.content) unless ac.nil? || ac.act.nil?
elsif ac.act_type == "JournalsForMessage"
ac.act.notes unless ac.nil? || ac.act.nil?
strip_html(ac.act.notes) unless ac.nil? || ac.act.nil?
end
when :latest_update
time_from_now ac.updated_at unless ac.nil?
@ -84,10 +84,10 @@ module Mobile
elsif ac.container_type == "Project"
case ac.act_type
when "Issue"
"项目缺陷"
"项目问题"
when "Message"
"项目讨论区"
when "ProjectCreateInfo"
when "Project"
"项目"
end
end
@ -98,10 +98,11 @@ module Mobile
end
expose :act_type #缺陷/作业/讨论区/留言等类型
expose :act_id
expose :id
expose :container_type #课程/项目/博客/个人
expose :author, using: Mobile::Entities::User do |a, opt| #用户信息
if a.is_a? ::UserActivity
if a.act_type == "ProjectCreateInfo"
if a.act_type == "Project"
get_user(get_project(a.act_id).user_id)
elsif !a.act.nil?
if a.act_type == 'Issue' || a.act_type == 'News' || a.act_type == 'Message' || a.act_type == 'BlogComment'

@ -45,6 +45,8 @@ module Mobile
course_expose :tea_id
course_expose :term
course_expose :time
course_expose :invite_code
course_expose :qrcode
course_expose :updated_at
course_expose :course_student_num
expose :teacher, using: Mobile::Entities::User do |c, opt|

@ -0,0 +1,8 @@
module Mobile
module Entities
class Exercise < Grape::Entity
expose :exercise_name
expose :exercise_description
end
end
end

@ -26,6 +26,8 @@ module Mobile
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id
when :realname
u.nil? ? "" : get_user_realname(u)
when :name
u.nil? ? "" : u.show_name
end
end
end
@ -57,6 +59,11 @@ module Mobile
user_expose :student_num
# 活跃值
user_expose :active_count
user_expose :role_name
user_expose :name
end
end

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

@ -0,0 +1,3 @@
// Place all the styles related to the QualityAnalyses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

@ -0,0 +1,3 @@
// Place all the styles related to the syllabuses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

@ -239,14 +239,23 @@ class AccountController < ApplicationController
end
def resendmail
result = {:status=>1, :email=>""}
user = User.find(params[:user]) if params[:user]
result[:email] = user.mail
token = Token.new(:user => user, :action => "register")
if token.save
Mailer.run.register(token)
# Mailer.run.register(token)
Mailer.register(token).deliver
else
yield if block_given?
result[:status] = 0
end
render :json => result
end
def email_activation
end
private
@ -264,6 +273,7 @@ class AccountController < ApplicationController
if user.nil?
invalid_credentials
elsif user.status == 2
@user = user
invalid_credentials_new
elsif user.new_record?
onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id })
@ -375,8 +385,9 @@ class AccountController < ApplicationController
def invalid_credentials_new
logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
flash[:error] = l(:notice_account_invalid_creditentials_new)
render signin_path(:login=>true)
# flash[:error] = l(:notice_account_invalid_creditentials_new)
# render signin_path(:login=>true)
render :action => 'email_activation'
end
# Register a user for email activation.

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save