├── README.rdoc ├── log └── .keep ├── app ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── concerns │ │ └── .keep │ ├── .DS_Store │ ├── mongoid │ │ ├── .DS_Store │ │ ├── soft_delete.rb │ │ └── base_model.rb │ ├── mimi_contact.rb │ ├── mimi_topic.rb │ ├── mimi_topic_reply.rb │ └── mimi_user.rb ├── assets │ ├── images │ │ └── .keep │ ├── stylesheets │ │ ├── index.css.scss │ │ ├── mimis.css.scss │ │ ├── videos.css.scss │ │ ├── courses.css.scss │ │ └── application.css │ └── javascripts │ │ ├── courses.js.coffee │ │ ├── index.js.coffee │ │ ├── mimis.js.coffee │ │ ├── videos.js.coffee │ │ └── application.js ├── controllers │ ├── concerns │ │ └── .keep │ ├── .DS_Store │ ├── application_controller.rb │ └── mimis_controller.rb ├── helpers │ ├── mimis_helper.rb │ ├── application_helper.rb │ └── .DS_Store ├── api │ ├── utils.rb │ ├── api.rb │ ├── entities.rb │ ├── helpers.rb │ └── api_v1.rb └── views │ ├── .DS_Store │ ├── layouts │ └── application.html.erb │ └── mimis │ └── index.html.erb ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── public ├── favicon.ico ├── robots.txt ├── 500.html ├── 422.html └── 404.html ├── test ├── helpers │ ├── .keep │ ├── index_helper_test.rb │ ├── mimis_helper_test.rb │ ├── videos_helper_test.rb │ └── courses_helper_test.rb ├── mailers │ └── .keep ├── models │ └── .keep ├── controllers │ ├── .keep │ ├── mimis_controller_test.rb │ ├── courses_controller_test.rb │ ├── index_controller_test.rb │ └── videos_controller_test.rb ├── fixtures │ └── .keep ├── integration │ └── .keep └── test_helper.rb ├── vendor └── assets │ ├── javascripts │ └── .keep │ └── stylesheets │ └── .keep ├── db ├── .DS_Store └── seeds.rb ├── config ├── .DS_Store ├── environment.rb ├── initializers │ ├── session_store.rb │ ├── filter_parameter_logging.rb │ ├── mime_types.rb │ ├── wrap_parameters.rb │ ├── backtrace_silencers.rb │ ├── inflections.rb │ └── secret_token.rb ├── boot.rb ├── locales │ └── en.yml ├── environments │ ├── development.rb │ ├── test.rb │ └── production.rb ├── application.rb ├── routes.rb └── mongoid.yml ├── bin ├── rake ├── bundle └── rails ├── config.ru ├── Rakefile ├── .gitignore ├── Gemfile ├── README.md └── Gemfile.lock /README.rdoc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/helpers/mimis_helper.rb: -------------------------------------------------------------------------------- 1 | module MimisHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/api/utils.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | module APIUtils 3 | 4 | 5 | end 6 | -------------------------------------------------------------------------------- /db/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/db/.DS_Store -------------------------------------------------------------------------------- /config/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/config/.DS_Store -------------------------------------------------------------------------------- /app/helpers/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/helpers/.DS_Store -------------------------------------------------------------------------------- /app/models/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/models/.DS_Store -------------------------------------------------------------------------------- /app/views/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/views/.DS_Store -------------------------------------------------------------------------------- /app/controllers/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/controllers/.DS_Store -------------------------------------------------------------------------------- /app/models/mongoid/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jikexueyuan/mimi_api/HEAD/app/models/mongoid/.DS_Store -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /test/helpers/index_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class IndexHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/helpers/mimis_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class MimisHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/helpers/videos_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class VideosHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /test/helpers/courses_helper_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class CoursesHelperTest < ActionView::TestCase 4 | end 5 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | JikeXueyuan::Application.initialize! 6 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | JikeXueyuan::Application.config.session_store :cookie_store, key: '_JikeXueyuan_session' 4 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 5 | -------------------------------------------------------------------------------- /test/controllers/mimis_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class MimisControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/courses_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class CoursesControllerTest < ActionController::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /app/api/api.rb: -------------------------------------------------------------------------------- 1 | require "entities" 2 | require "helpers" 3 | require "utils" 4 | class Api < Grape::API 5 | prefix "api" 6 | format :json 7 | default_error_formatter :json 8 | 9 | mount Api_v1 10 | 11 | end -------------------------------------------------------------------------------- /app/assets/stylesheets/index.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the index controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/mimis.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the mimis controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/videos.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the videos controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/courses.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the courses controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /app/models/mimi_contact.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | class MimiContact 3 | include Mongoid::Document 4 | include Mongoid::Timestamps 5 | 6 | field :phone_md5 7 | field :u_phone_md5 8 | belongs_to :mimi_user 9 | 10 | 11 | end -------------------------------------------------------------------------------- /test/controllers/index_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class IndexControllerTest < ActionController::TestCase 4 | test "should get index" do 5 | get :index 6 | assert_response :success 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /app/assets/javascripts/courses.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/index.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/mimis.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/videos.js.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] ||= "test" 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Add more helper methods to be used by all tests here... 7 | end 8 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | JikeXueyuan::Application.load_tasks 7 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :exception 5 | 6 | 7 | 8 | end 9 | -------------------------------------------------------------------------------- /app/api/entities.rb: -------------------------------------------------------------------------------- 1 | require "digest/md5" 2 | 3 | module APIEntities 4 | 5 | 6 | class MimiTopic < Grape::Entity 7 | expose :msg,:msgId,:phone_md5,:created_at 8 | end 9 | 10 | class MimiTopicReply < Grape::Entity 11 | expose :rid,:content,:phone_md5,:created_at 12 | end 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | end 21 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /app/models/mimi_topic.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | class MimiTopic 3 | include Mongoid::Document 4 | include Mongoid::Timestamps 5 | include Mongoid::BaseModel 6 | 7 | field :msg 8 | field :phone_md5 9 | field :state, :type => Integer, :default => 1 10 | 11 | 12 | belongs_to :mimi_user 13 | 14 | scope :normal, -> { where(:state.gt => 0) } 15 | 16 | def msgId 17 | self.id.to_s 18 | end 19 | end -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | -------------------------------------------------------------------------------- /test/controllers/videos_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class VideosControllerTest < ActionController::TestCase 4 | test "should get index" do 5 | get :index 6 | assert_response :success 7 | end 8 | 9 | test "should get upload" do 10 | get :upload 11 | assert_response :success 12 | end 13 | 14 | test "should get edit" do 15 | get :edit 16 | assert_response :success 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /app/models/mimi_topic_reply.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | class MimiTopicReply 3 | include Mongoid::Document 4 | include Mongoid::Timestamps 5 | 6 | field :content 7 | field :phone_md5 8 | belongs_to :mimi_topic 9 | belongs_to :mimi_user 10 | 11 | 12 | scope :by_msg_id, Proc.new { |t| where(:mimi_topic_id => t) } 13 | scope :normal, -> { where(:state.gt => 0) } 14 | 15 | 16 | def rid 17 | self.id.to_s 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /app/controllers/mimis_controller.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | class MimisController < ApplicationController 3 | 4 | def index 5 | @users = MimiUser.paginate(:page => params[:page], :per_page => 1000) 6 | @topics = MimiTopic.paginate(:page => params[:page], :per_page => 1000) 7 | @replies = MimiTopicReply.paginate(:page => params[:page], :per_page => 1000) 8 | @contacts = MimiContact.paginate(:page => params[:page], :per_page => 1000) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /app/models/mongoid/soft_delete.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # 软删除 3 | module Mongoid 4 | module SoftDelete 5 | extend ActiveSupport::Concern 6 | 7 | included do 8 | field :deleted_at, :type => DateTime 9 | 10 | default_scope where(:deleted_at => nil) 11 | alias_method :destroy!, :destroy 12 | end 13 | 14 | def destroy 15 | if persisted? 16 | self.update_attribute(:deleted_at,Time.now.utc) 17 | end 18 | 19 | @destroyed = true 20 | freeze 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/*.log 16 | /tmp 17 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JikeXueyuan 5 | 6 | <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> 7 | <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 8 | 9 | <%= csrf_meta_tags %> 10 | 11 | 12 |
13 | <%= yield %> 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /app/api/helpers.rb: -------------------------------------------------------------------------------- 1 | module APIHelpers 2 | def warden 3 | env['warden'] 4 | end 5 | 6 | # items helpers 7 | def max_page_size 8 | 100 9 | end 10 | 11 | def default_page_size 12 | 15 13 | end 14 | 15 | def page_size 16 | size = params[:size].to_i 17 | [size.zero? ? default_page_size : size, max_page_size].min 18 | end 19 | 20 | # user helpers 21 | def current_user 22 | token = params[:token] || oauth_token 23 | @current_user ||= MimiUser.try_login(token) if token 24 | end 25 | 26 | 27 | 28 | def authenticate! 29 | error!({:status => "0", "msg" => "Unauthorized" }, 401) unless current_user 30 | end 31 | 32 | 33 | 34 | 35 | 36 | 37 | end -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure your secret_key_base is kept private 11 | # if you're sharing your code publicly. 12 | JikeXueyuan::Application.config.secret_key_base = '7759da739522b12c2107f93e2f380f29adfc474ca7dcb87a3b88143c0089bdfd7d39fe9d6dfac5730a445b04597ae6b6d58627e7cbd81facccedf724af84e8e4' 13 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require turbolinks 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /app/views/mimis/index.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Mimi

4 | 5 | 6 |

users

7 | 12 | 13 |

Topic

14 | 19 | 20 | 21 |

Reply

22 | 27 | 28 |

Contacts

29 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | JikeXueyuan::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | 23 | # Debug mode disables concatenation and preprocessing of assets. 24 | # This option may cause significant delays in view rendering with a large 25 | # number of complex assets. 26 | config.assets.debug = true 27 | end 28 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | # Pick the frameworks you want: 4 | # require "active_record/railtie" 5 | require "action_controller/railtie" 6 | require "action_mailer/railtie" 7 | require "sprockets/railtie" 8 | require "rails/test_unit/railtie" 9 | 10 | # Require the gems listed in Gemfile, including any gems 11 | # you've limited to :test, :development, or :production. 12 | Bundler.require(:default, Rails.env) 13 | 14 | module JikeXueyuan 15 | class Application < Rails::Application 16 | # Settings in config/environments/* take precedence over those specified here. 17 | # Application configuration should go into files in config/initializers 18 | # -- all .rb files in that directory are automatically loaded. 19 | config.paths.add "app/grape", glob: "**/*.rb" 20 | config.autoload_paths += %W(#{config.root}/app/grape) 21 | 22 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 23 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 24 | # config.time_zone = 'Central Time (US & Canada)' 25 | 26 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 27 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 28 | # config.i18n.default_locale = :de 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

We're sorry, but something went wrong.

54 |
55 |

If you are the application owner check the logs for more information.

56 | 57 | 58 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

The change you wanted was rejected.

54 |

Maybe you tried to change something you didn't have access to.

55 |
56 |

If you are the application owner check the logs for more information.

57 | 58 | 59 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

The page you were looking for doesn't exist.

54 |

You may have mistyped the address or the page may have moved.

55 |
56 |

If you are the application owner check the logs for more information.

57 | 58 | 59 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | JikeXueyuan::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static asset server for tests with Cache-Control for performance. 16 | config.serve_static_assets = true 17 | config.static_cache_control = "public, max-age=3600" 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | config.action_mailer.delivery_method = :test 33 | 34 | # Print deprecation notices to the stderr. 35 | config.active_support.deprecation = :stderr 36 | end 37 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | source 'http://ruby.taobao.org' 3 | #source 'https://rubygems.org' 4 | 5 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 6 | gem 'rails', '4.0.1' 7 | 8 | #new qiniu gems 9 | gem 'qiniu-policy' 10 | gem 'unicorn' 11 | # Mongoid 辅助插件 12 | gem 'mongoid', '~> 4.0.0.beta1', :github => 'mongoid/mongoid' 13 | gem 'will_paginate_mongoid' 14 | gem 'will_paginate' #, '3.0.4' 15 | gem 'will_paginate-bootstrap' 16 | 17 | gem 'execjs' 18 | gem 'therubyracer' 19 | 20 | #ui 21 | gem 'flatui-rails-less' 22 | 23 | #for api 24 | gem 'grape' 25 | gem 'grape-entity' 26 | 27 | gem 'ruby-hmac' 28 | gem 'rest_client' 29 | gem 'json' 30 | 31 | # Use SCSS for stylesheets 32 | gem 'sass-rails', '~> 4.0.0' 33 | 34 | # Use Uglifier as compressor for JavaScript assets 35 | gem 'uglifier', '>= 1.3.0' 36 | 37 | # Use CoffeeScript for .js.coffee assets and views 38 | gem 'coffee-rails', '~> 4.0.0' 39 | 40 | # See https://github.com/sstephenson/execjs#readme for more supported runtimes 41 | # gem 'therubyracer', platforms: :ruby 42 | 43 | # Use jquery as the JavaScript library 44 | gem 'jquery-rails' 45 | 46 | # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 47 | gem 'turbolinks' 48 | 49 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 50 | gem 'jbuilder', '~> 1.2' 51 | 52 | group :doc do 53 | # bundle exec rake doc:rails generates the API under doc/api. 54 | gem 'sdoc', require: false 55 | end 56 | 57 | # Use ActiveModel has_secure_password 58 | # gem 'bcrypt-ruby', '~> 3.1.2' 59 | 60 | # Use unicorn as the app server 61 | # gem 'unicorn' 62 | 63 | # Use Capistrano for deployment 64 | # gem 'capistrano', group: :development 65 | 66 | # Use debugger 67 | # gem 'debugger', group: [:development, :test] 68 | -------------------------------------------------------------------------------- /app/models/mongoid/base_model.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | # 基本 Model,加入一些通用功能 3 | module Mongoid 4 | module BaseModel 5 | extend ActiveSupport::Concern 6 | 7 | included do 8 | # scope :recent, desc(:_id) 9 | # scope :exclude_ids, Proc.new { |ids| where(:_id.nin => ids.map(&:to_i)) } 10 | 11 | delegate :url_helpers, to: 'Rails.application.routes' 12 | end 13 | 14 | def update_last_reply(reply) 15 | # replied_at 用于最新回复的排序,如果贴着创建时间在一个月以前,就不再往前面顶了 16 | self.last_active_mark = Time.now.to_i if self.created_at > 1.month.ago 17 | self.replied_at = Time.now 18 | self.last_reply_id = reply.id 19 | self.last_reply_account_id = reply.account_id 20 | self.last_reply_account_login = reply.account.try(:login) || nil 21 | self.save 22 | end 23 | 24 | module ClassMethods 25 | # like ActiveRecord find_by_id 26 | def find_by_id(id) 27 | if id.is_a?(Integer) or id.is_a?(String) 28 | where(:_id => id.to_i).first 29 | else 30 | nil 31 | end 32 | end 33 | 34 | def find_in_batches(opts = {}) 35 | batch_size = opts[:batch_size] || 1000 36 | start = opts.delete(:start).to_i || 0 37 | objects = self.limit(batch_size).skip(start) 38 | t = Time.new 39 | while objects.any? 40 | yield objects 41 | start += batch_size 42 | # Rails.logger.debug("processed #{start} records in #{Time.new - t} seconds") if Rails.logger.debug? 43 | break if objects.size < batch_size 44 | objects = self.limit(batch_size).skip(start) 45 | end 46 | end 47 | 48 | def delay 49 | Sidekiq::Extensions::Proxy.new(DelayedDocument, self) 50 | end 51 | 52 | end 53 | 54 | def delay 55 | Sidekiq::Extensions::Proxy.new(DelayedDocument, self) 56 | end 57 | 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | JikeXueyuan::Application.routes.draw do 2 | require 'api' 3 | mount Api => "/" 4 | 5 | # The priority is based upon order of creation: first created -> highest priority. 6 | # See how all your routes lay out with "rake routes". 7 | 8 | # You can have the root of your site routed with "root" 9 | # root 'welcome#index' 10 | root 'index#index' 11 | 12 | # Example of regular route: 13 | # get 'products/:id' => 'catalog#view' 14 | 15 | # Example of named route that can be invoked with purchase_url(id: product.id) 16 | # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 17 | 18 | # Example resource route (maps HTTP verbs to controller actions automatically): 19 | # resources :products 20 | 21 | # Example resource route with options: 22 | # resources :products do 23 | # member do 24 | # get 'short' 25 | # post 'toggle' 26 | # end 27 | # 28 | # collection do 29 | # get 'sold' 30 | # end 31 | # end 32 | 33 | # Example resource route with sub-resources: 34 | # resources :products do 35 | # resources :comments, :sales 36 | # resource :seller 37 | # end 38 | 39 | resources :mimis do 40 | end 41 | 42 | 43 | 44 | 45 | # Example resource route with more complex sub-resources: 46 | # resources :products do 47 | # resources :comments 48 | # resources :sales do 49 | # get 'recent', on: :collection 50 | # end 51 | # end 52 | 53 | # Example resource route with concerns: 54 | # concern :toggleable do 55 | # post 'toggle' 56 | # end 57 | # resources :posts, concerns: :toggleable 58 | # resources :photos, concerns: :toggleable 59 | 60 | # Example resource route within a namespace: 61 | # namespace :admin do 62 | # # Directs /admin/products/* to Admin::ProductsController 63 | # # (app/controllers/admin/products_controller.rb) 64 | # resources :products 65 | # end 66 | end 67 | -------------------------------------------------------------------------------- /app/api/api_v1.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | #Api 3 | #Get(先用get测,测试完成后再换成post) 4 | #入口: http://demo.eoeschool.com/nimings/io?action=xxx 5 | #返回: status-状态;msg-提示信息 6 | #Todo:连发送短信的接口发短信; 7 | class Api_v1 < Grape::API 8 | version 'v1', :using => :path, :format => :json #,:vendor => 'acme' 9 | helpers APIHelpers 10 | 11 | 12 | resource :nimings do 13 | get '/hey' do 14 | "say hey from NiMing " 15 | end 16 | 17 | post '/io' do 18 | act = params[:action] 19 | if act == "send_pass" 20 | MimiUser.send_code(params[:phone]) 21 | elsif act == "login" 22 | code = params[:code] 23 | phone_md5 = params[:phone_md5] 24 | MimiUser.try_login_by_code(phone_md5,code) 25 | else 26 | authenticate! 27 | case act 28 | #上传联系人 29 | when "upload_contacts" 30 | contacts = params[:contacts] 31 | if(current_user.upload_contacts(contacts)) 32 | {:status =>"1", "msg" => "成了~" } 33 | else 34 | {:status =>"0", "msg" => "失败鸟~" } 35 | end 36 | #消息列表 37 | when "timeline" 38 | page = params[:page] || 1 39 | prepage = params[:prepage] || 10 40 | @items = current_user.get_timeline(page,prepage) 41 | present @items, :with => APIEntities::MimiTopic 42 | body( { status: "1", items: body() }) 43 | #获取评论 44 | when "get_comment" 45 | msg_id = params[:msgId] 46 | page = params[:page] || 1 47 | prepage = params[:prepage] || 10 48 | @comments = current_user.get_comment(msg_id,page,prepage) 49 | present @comments, :with => APIEntities::MimiTopicReply 50 | body( { status: "1", items: body() }) 51 | #发布消息 52 | when "publish" 53 | msg = params[:msg] 54 | current_user.publish(msg) 55 | #发布评论 56 | when "pub_comment" 57 | content = params[:content] 58 | msg_id = params[:msgId] 59 | current_user.pub_comment(msg_id,content) 60 | else 61 | end 62 | end 63 | 64 | end 65 | 66 | end 67 | 68 | 69 | 70 | 71 | end #end class -------------------------------------------------------------------------------- /config/mongoid.yml: -------------------------------------------------------------------------------- 1 | development: 2 | # Configure available database sessions. (required) 3 | sessions: 4 | # Defines the default session. (required) 5 | default: 6 | # Defines the name of the default database that Mongoid can connect to. 7 | # (required). 8 | database: mimi 9 | # Provides the hosts the default session can connect to. Must be an array 10 | # of host:port pairs. (required) 11 | hosts: 12 | - localhost:27017 13 | options: 14 | # Change whether the session persists in safe mode by default. 15 | # (default: false) 16 | # safe: false 17 | 18 | # Change the default consistency model to :eventual or :strong. 19 | # :eventual will send reads to secondaries, :strong sends everything 20 | # to master. (default: :eventual) 21 | # consistency: :strong 22 | pool_size: 35 23 | # Configure Mongoid specific options. (optional) 24 | options: 25 | # Configuration for whether or not to allow access to fields that do 26 | # not have a field definition on the model. (default: true) 27 | # allow_dynamic_fields: true 28 | 29 | # Enable the identity map, needed for eager loading. (default: false) 30 | # identity_map_enabled: false 31 | 32 | # Includes the root model name in json serialization. (default: false) 33 | # include_root_in_json: false 34 | 35 | # Include the _type field in serializaion. (default: false) 36 | # include_type_for_serialization: false 37 | 38 | # Preload all models in development, needed when models use 39 | # inheritance. (default: false) 40 | # preload_models: false 41 | 42 | # Protect id and type from mass assignment. (default: true) 43 | # protect_sensitive_fields: true 44 | 45 | # Raise an error when performing a #find and the document is not found. 46 | # (default: true) 47 | # raise_not_found_error: true 48 | 49 | # Raise an error when defining a scope with the same name as an 50 | # existing method. (default: false) 51 | # scope_overwrite_exception: false 52 | 53 | # Skip the database version check, used when connecting to a db without 54 | # admin access. (default: false) 55 | # skip_version_check: false 56 | 57 | # User Active Support's time zone in conversions. (default: true) 58 | # use_activesupport_time_zone: true 59 | 60 | # Ensure all times are UTC in the app side. (default: false) 61 | # use_utc: false 62 | test: 63 | sessions: 64 | default: 65 | database: mimi 66 | hosts: 67 | - localhost:27017 68 | options: 69 | consistency: :strong 70 | #production 71 | production: 72 | sessions: 73 | default: 74 | database: mimi 75 | hosts: 76 | - localhost:27017 77 | options: 78 | # consistency: :strong 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 秘密服务器端代码 2 | ================ 3 | 4 | Ruby写的秘密服务器端代码 5 | 6 | 环境: 7 | Ruby + MongoDB + Grape 8 | 9 | 10 | # MiMi_Api的配置部署 11 | 12 | 13 | ## 首先安装Ruby环境 14 | 15 | 首先更新你的服务器,我一般用的是Debian,国际惯例 16 | 17 | `sudo apt-get update && sudo apt-get upgrade` 18 | 19 | 然后用普通用户安装RVM,RVM是一个管理Ruby版本的软件,当然你也可以选择Rbenv,紧紧是个人喜好以及熟悉问题: 20 | 21 | `\curl -sSL https://get.rvm.io | bash -s stable` 22 | 23 | 执行过后,需要再执行这个确保本机配置正确: 24 | 25 | `source ~/.rvm/scripts/rvm` 26 | 27 | 此刻,如果你打出`rvm -v`,终端出现如下字样,那么恭喜你,rvm安装成功 28 | 29 | `rvm 1.25.29 (stable) by Wayne E. Seguin , Michal Papis [https://rvm.io/]` 30 | 31 | 然后再用RVM安装Ruby,可以用`rvm list known`来列出RVM支持的Ruby版本,这里我们选择2.1.2版本,执行`rvm install 2.1.2`就可以安装Ruby了,在这当中你可能需要输入密码来安装依赖。 32 | 33 | 安装好之后,还需要用`rvm use 2.1.2`来确保系统使用的Ruby版本。 34 | 35 | ## 安装 36 | 37 | 把仓库clone到本地 38 | 39 | git clone https://github.com/jikexueyuan/mimi_api.git 40 | 41 | 然后执行 `bundle` 42 | 43 | cd mimi_api && bundle 44 | 45 | ## MongoDB 配置 46 | 47 | 48 | 先略过 (。-_-。) 49 | 50 | 51 | ## unicorn 配置 52 | 53 | 在上面的bundle中已经安装了unicorn,这里我们选择nginx来配合。 54 | 55 | sudo apt-get install nginx 56 | 57 | 然后需要在`mimi_api/config`下建立`unicorn.rb` 文件,并写入如下内容 58 | 59 | # Set the working application directory 60 | # working_directory "/path/to/your/app" 61 | working_directory "/www/mimi" 62 | 63 | # Unicorn PID file location 64 | # pid "/path/to/pids/unicorn.pid" 65 | pid "/www/mimi/unicorn.pid" 66 | 67 | # Path to logs 68 | # stderr_path "/path/to/log/unicorn.log" 69 | # stdout_path "/path/to/log/unicorn.log" 70 | stderr_path "/www/mimi/log/unicorn.log" 71 | stdout_path "/www/mimi/log/unicorn.log" 72 | 73 | # Unicorn socket 74 | # listen "/tmp/unicorn.[app name].sock" 75 | listen "/tmp/unicorn.mimi.sock" 76 | 77 | # Number of processes 78 | # worker_processes 4 79 | worker_processes 2 80 | 81 | # Time-out 82 | timeout 30 83 | 84 | 注意的是,`/www/mimi`是我的本地目录,需要你改成你clone到服务器上的目录。 85 | 86 | 然后配置nginx,新建或者修改如下文件`/etc/nginx/conf.d/default.conf`,写入如下内容 87 | 88 | upstream app { 89 | # Path to Unicorn SOCK file, as defined previously 90 | server unix:/tmp/unicorn.mimi.sock fail_timeout=0; 91 | } 92 | 93 | server { 94 | 95 | 96 | listen 80; 97 | server_name localhost; 98 | 99 | # Application root, as defined previously 100 | root /home/ishell/www/mimi/public; 101 | 102 | try_files $uri/index.html $uri @app; 103 | 104 | location @app { 105 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 106 | proxy_set_header Host $http_host; 107 | proxy_redirect off; 108 | proxy_pass http://app; 109 | } 110 | 111 | error_page 500 502 503 504 /500.html; 112 | client_max_body_size 4G; 113 | keepalive_timeout 10; 114 | } 115 | 116 | 117 | 然后在`mimi_api`目录执行 118 | 119 | unicorn_rails -c config/unicorn.rb -D 120 | 121 | 接着执行 122 | 123 | sudo service nginx restart 124 | 125 | 这时打开`http://你的ip/api/v1/nimings/hey` 就可以看到 `"say hey from NiMing "` -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | JikeXueyuan::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both thread web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. 20 | # config.action_dispatch.rack_cache = true 21 | 22 | # Disable Rails's static asset server (Apache or nginx will already do this). 23 | config.serve_static_assets = false 24 | 25 | # Compress JavaScripts and CSS. 26 | config.assets.js_compressor = :uglifier 27 | # config.assets.css_compressor = :sass 28 | 29 | # Do not fallback to assets pipeline if a precompiled asset is missed. 30 | config.assets.compile = false 31 | 32 | # Generate digests for assets URLs. 33 | config.assets.digest = true 34 | 35 | # Version of your assets, change this if you want to expire all your assets. 36 | config.assets.version = '1.0' 37 | 38 | # Specifies the header that your server uses for sending files. 39 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 40 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 41 | 42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 43 | # config.force_ssl = true 44 | 45 | # Set to :debug to see everything in the log. 46 | config.log_level = :info 47 | 48 | # Prepend all log lines with the following tags. 49 | # config.log_tags = [ :subdomain, :uuid ] 50 | 51 | # Use a different logger for distributed setups. 52 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 53 | 54 | # Use a different cache store in production. 55 | # config.cache_store = :mem_cache_store 56 | 57 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 58 | # config.action_controller.asset_host = "http://assets.example.com" 59 | 60 | # Precompile additional assets. 61 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 62 | # config.assets.precompile += %w( search.js ) 63 | 64 | # Ignore bad email addresses and do not raise email delivery errors. 65 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 66 | # config.action_mailer.raise_delivery_errors = false 67 | 68 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 69 | # the I18n.default_locale when a translation can not be found). 70 | config.i18n.fallbacks = true 71 | 72 | # Send deprecation notices to registered listeners. 73 | config.active_support.deprecation = :notify 74 | 75 | # Disable automatic flushing of the log to improve performance. 76 | # config.autoflush_log = false 77 | 78 | # Use default logging formatter so that PID and timestamp are not suppressed. 79 | config.log_formatter = ::Logger::Formatter.new 80 | end 81 | -------------------------------------------------------------------------------- /app/models/mimi_user.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | require "digest/md5" 3 | require "open-uri" 4 | require 'cgi' 5 | require 'json' 6 | class MimiUser 7 | include Mongoid::Document 8 | include Mongoid::Timestamps 9 | 10 | field :phone 11 | field :phone_md5 12 | field :code 13 | field :token 14 | 15 | #publish 16 | def publish(msg) 17 | mt = MimiTopic.new(:msg => msg) 18 | mt.mimi_user_id = self.id 19 | mt.phone_md5 = self.phone_md5 20 | if mt.save 21 | {:status =>"1", "msg" => "发布成功~" } 22 | else 23 | {:status =>"0", "msg" => "发失败鸟~" } 24 | end 25 | end 26 | 27 | #发表评论 28 | def pub_comment(msg_id,content) 29 | mt = MimiTopic.find msg_id 30 | if mt 31 | mtr = MimiTopicReply.new(:content => content) 32 | mtr.mimi_topic_id = mt.id 33 | mtr.mimi_user_id = self.id 34 | mt.phone_md5 = self.phone_md5 35 | if mtr.save 36 | {:status =>"1", "msg" => "评论成功~" } 37 | else 38 | {:status =>"0", "msg" => "评论失败鸟~" } 39 | end 40 | else 41 | {:status =>"0", "msg" => "消息不存在~" } 42 | end 43 | end 44 | 45 | def get_timeline(page,per_page) 46 | scoped_items = MimiTopic.all 47 | @items = scoped_items.paginate :per_page => per_page, :page => page 48 | end 49 | 50 | def get_comment(msg_id,page,per_page) 51 | scoped_items = MimiTopicReply.normal 52 | @items = scoped_items.by_msg_id(msg_id).paginate :per_page => per_page, :page => page 53 | end 54 | 55 | def self.try_login(token) 56 | a = MimiUser.where(:token => token).first if token 57 | a ? a : nil 58 | end 59 | 60 | def self.try_login_by_code(phone_md5,code) 61 | a = MimiUser.where(:phone_md5 => phone_md5).first if phone_md5 62 | if (a && a.code == code) 63 | {:status =>"1", "token" => "#{a.token}" } 64 | else 65 | {:status =>"0", "msg" => "登录失败,请检查你的短信验证码~" } 66 | end 67 | end 68 | 69 | #upload 70 | def upload_contacts(contacts) 71 | jcontacts = JSON.parse(contacts) 72 | logger.info "contacts:#{jcontacts}" 73 | jcontacts.each do |c| 74 | phone_md5 = c['phone_md5'] 75 | mc = MimiContact.where(:phone_md5 => phone_md5,:mini_user_id => self.id).first 76 | unless mc 77 | mc = MimiContact.new(:phone_md5 => phone_md5) 78 | mc.u_phone_md5 = self.phone_md5 79 | mc.mimi_user_id = self.id 80 | mc.save 81 | end 82 | end 83 | end 84 | 85 | def self.get_user(phone) 86 | u = MimiUser.where(:phone => phone).first 87 | unless u 88 | u = MimiUser.e(:phone => phone) 89 | u.save 90 | u 91 | else 92 | u 93 | end 94 | end 95 | 96 | #send sms code 97 | def self.send_code(phone) 98 | unless phone.blank? 99 | @u = MimiUser.get_user(phone) 100 | logger.info "phone:#{phone},u:#{@u.phone}" 101 | message = "验证码:#{@u.code}(半小时内有效)-极客学院" 102 | uri = "http://www.xxx.com/sendsms?id=xx&phone=#{@u.phone}&message=#{CGI::escape(message)}" 103 | logger.info("uri:#{uri}") 104 | html_response = nil 105 | open(uri) do |http| 106 | html_response = http.read 107 | end 108 | logger.info "html_response:#{html_response}" 109 | if html_response 110 | {:status =>"1", "msg" => "请查看收到的短信验证码(#{@u.try(:code)})~" } 111 | else 112 | {:status =>"0", "msg" => "短信发送失败,请稍后再试~" } 113 | end 114 | else 115 | {:status =>"0", "msg" => "手机号码为空~" } 116 | end 117 | end 118 | 119 | #after_save 120 | after_create :gen_token_and_phone_md5 121 | 122 | def gen_token_and_phone_md5 123 | token = "#{SecureRandom.hex(6)}" 124 | self.update_attribute(:token, token) 125 | 126 | code = MimiUser.rand_code(4) 127 | self.update_attribute(:code, code) 128 | 129 | phone_md5 = Digest::MD5.hexdigest(phone || "") 130 | self.update_attribute(:phone_md5, phone_md5) 131 | end 132 | 133 | 134 | def self.rand_code(len=4) 135 | #("a".."z").to_a + ("A".."Z").to_a + 136 | chars = ("0".."9").to_a 137 | newpass = "" 138 | 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] } 139 | return newpass 140 | end 141 | 142 | 143 | 144 | end -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | 15 | body { 16 | padding-top: 50px; 17 | padding-bottom: 30px; 18 | min-width: 970px; 19 | background: #e3e3e3; 20 | } 21 | 22 | 23 | 24 | 25 | .topbar{ 26 | padding: 10px; 27 | background: #000; 28 | color:#fff; 29 | } 30 | .topbar a{ 31 | color:#fff; 32 | } 33 | 34 | .innav{ 35 | background: #ccc; 36 | padding: 4px 0px; 37 | 38 | } 39 | .v_items{ 40 | display: table; 41 | margin:0px; 42 | width:100%; 43 | } 44 | 45 | .v_item{ 46 | background: #fff; 47 | width: 227px; 48 | margin:4px; 49 | padding: 10px; 50 | height: 400px; 51 | overflow: hidden; 52 | float: left; 53 | border: 1px solid #DDD; 54 | } 55 | 56 | .v_item img{ 57 | border: 1px solid #DDD; 58 | } 59 | 60 | .c_items{ 61 | clear:both; 62 | margin-bottom:20px; 63 | } 64 | 65 | .c_item{ 66 | border: 1px solid #DDD; 67 | background: #fff; 68 | /*width: 229px;*/ 69 | margin:4px; 70 | padding: 10px; 71 | height: 240px; 72 | overflow: hidden; 73 | float: left; 74 | } 75 | 76 | .c_item img{ 77 | border: 1px solid #DDD; 78 | } 79 | 80 | .large{ 81 | width: 400px; 82 | padding: 6px; 83 | 84 | } 85 | 86 | .xlarge{ 87 | width: 700px; 88 | padding: 6px; 89 | } 90 | 91 | h1{ 92 | margin: 10px 0px 0px; 93 | } 94 | 95 | h2{ 96 | margin: 4px 0px 4px; 97 | } 98 | 99 | h4{ 100 | border-bottom: 1px solid #DDD; 101 | width: 600px; 102 | margin: 20px 0px 10px; 103 | } 104 | 105 | .help-block{ 106 | font-size:12px; 107 | margin-top:0px; 108 | margin-bottom:2px; 109 | color:#666; 110 | } 111 | 112 | .clearfix{ 113 | margin-bottom:10px; 114 | } 115 | 116 | fieldset{ 117 | margin-bottom:20px; 118 | } 119 | 120 | 121 | /* Account for fixed navbar */ 122 | body { 123 | padding-top: 70px; 124 | padding-bottom: 30px; 125 | min-width: 970px; 126 | } 127 | 128 | /* Finesse the page header spacing */ 129 | .page-header { 130 | margin-top: 15px; 131 | margin-bottom: 10px; 132 | padding-bottom:2px; 133 | } 134 | .page-header .lead { 135 | margin-bottom: 15px; 136 | font-size:16px; 137 | color:#999; 138 | } 139 | 140 | h1{ 141 | font-size:20px; 142 | } 143 | 144 | h3{ 145 | font-size:16px; 146 | } 147 | 148 | /* Non-responsive overrides 149 | * 150 | * Utilitze the following CSS to disable the responsive-ness of the container, 151 | * grid system, and navbar. 152 | */ 153 | 154 | /* Reset the container */ 155 | .container { 156 | max-width: none !important; 157 | width: 970px; 158 | background: #fff; 159 | } 160 | 161 | .content{ 162 | padding-bottom: 25px; 163 | } 164 | 165 | /* Demonstrate the grids */ 166 | .col-xs-4 { 167 | padding-top: 15px; 168 | padding-bottom: 15px; 169 | background-color: #eee; 170 | border: 1px solid #ddd; 171 | background-color: rgba(86,61,124,.15); 172 | border: 1px solid rgba(86,61,124,.2); 173 | } 174 | 175 | .container .navbar-header, 176 | .container .navbar-collapse { 177 | margin-right: 0; 178 | margin-left: 0; 179 | } 180 | 181 | /* Always float the navbar header */ 182 | .navbar-header { 183 | float: left; 184 | } 185 | 186 | /* Undo the collapsing navbar */ 187 | .navbar-collapse { 188 | display: block !important; 189 | height: auto !important; 190 | padding-bottom: 0; 191 | overflow: visible !important; 192 | } 193 | 194 | .navbar-toggle { 195 | display: none; 196 | } 197 | .navbar-collapse { 198 | border-top: 0; 199 | } 200 | 201 | .navbar-brand { 202 | margin-left: -15px; 203 | } 204 | 205 | /* Always apply the floated nav */ 206 | .navbar-nav { 207 | float: left; 208 | margin: 0; 209 | } 210 | .navbar-nav > li { 211 | float: left; 212 | } 213 | .navbar-nav > li > a { 214 | padding: 15px; 215 | } 216 | 217 | /* Redeclare since we override the float above */ 218 | .navbar-nav.navbar-right { 219 | float: right; 220 | } 221 | 222 | /* Undo custom dropdowns */ 223 | .navbar .navbar-nav .open .dropdown-menu { 224 | position: absolute; 225 | float: left; 226 | background-color: #fff; 227 | border: 1px solid #cccccc; 228 | border: 1px solid rgba(0, 0, 0, 0.15); 229 | border-width: 0 1px 1px; 230 | border-radius: 0 0 4px 4px; 231 | -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); 232 | box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); 233 | } 234 | .navbar-default .navbar-nav .open .dropdown-menu > li > a { 235 | color: #333; 236 | } 237 | .navbar .navbar-nav .open .dropdown-menu > li > a:hover, 238 | .navbar .navbar-nav .open .dropdown-menu > li > a:focus, 239 | .navbar .navbar-nav .open .dropdown-menu > .active > a, 240 | .navbar .navbar-nav .open .dropdown-menu > .active > a:hover, 241 | .navbar .navbar-nav .open .dropdown-menu > .active > a:focus { 242 | color: #fff !important; 243 | background-color: #428bca !important; 244 | } 245 | .navbar .navbar-nav .open .dropdown-menu > .disabled > a, 246 | .navbar .navbar-nav .open .dropdown-menu > .disabled > a:hover, 247 | .navbar .navbar-nav .open .dropdown-menu > .disabled > a:focus { 248 | color: #999 !important; 249 | background-color: transparent !important; 250 | } 251 | 252 | img{ max-width:100%;} -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GIT 2 | remote: git://github.com/mongoid/mongoid.git 3 | revision: c8af8d0836b086cebc4a609037a97747e9f3359b 4 | specs: 5 | mongoid (4.0.0.beta1) 6 | activemodel (>= 4.0.0) 7 | moped (~> 2.0.beta6) 8 | origin (~> 2.1) 9 | tzinfo (>= 0.3.37) 10 | 11 | GEM 12 | remote: http://ruby.taobao.org/ 13 | specs: 14 | actionmailer (4.0.1) 15 | actionpack (= 4.0.1) 16 | mail (~> 2.5.4) 17 | actionpack (4.0.1) 18 | activesupport (= 4.0.1) 19 | builder (~> 3.1.0) 20 | erubis (~> 2.7.0) 21 | rack (~> 1.5.2) 22 | rack-test (~> 0.6.2) 23 | activemodel (4.0.1) 24 | activesupport (= 4.0.1) 25 | builder (~> 3.1.0) 26 | activerecord (4.0.1) 27 | activemodel (= 4.0.1) 28 | activerecord-deprecated_finders (~> 1.0.2) 29 | activesupport (= 4.0.1) 30 | arel (~> 4.0.0) 31 | activerecord-deprecated_finders (1.0.3) 32 | activesupport (4.0.1) 33 | i18n (~> 0.6, >= 0.6.4) 34 | minitest (~> 4.2) 35 | multi_json (~> 1.3) 36 | thread_safe (~> 0.1) 37 | tzinfo (~> 0.3.37) 38 | arel (4.0.2) 39 | atomic (1.1.14) 40 | axiom-types (0.0.5) 41 | descendants_tracker (~> 0.0.1) 42 | ice_nine (~> 0.9) 43 | backports (3.3.5) 44 | bson (2.2.1) 45 | builder (3.1.4) 46 | coercible (0.2.0) 47 | backports (~> 3.0, >= 3.1.0) 48 | descendants_tracker (~> 0.0.1) 49 | coffee-rails (4.0.1) 50 | coffee-script (>= 2.2.0) 51 | railties (>= 4.0.0, < 5.0) 52 | coffee-script (2.2.0) 53 | coffee-script-source 54 | execjs 55 | coffee-script-source (1.7.0) 56 | commonjs (0.2.7) 57 | connection_pool (1.2.0) 58 | descendants_tracker (0.0.3) 59 | equalizer (0.0.7) 60 | erubis (2.7.0) 61 | execjs (2.0.2) 62 | flatui-rails-less (1.3) 63 | less-rails 64 | less-rails-bootstrap 65 | grape (0.6.0) 66 | activesupport 67 | builder 68 | hashie (>= 1.2.0) 69 | multi_json (>= 1.3.2) 70 | multi_xml (>= 0.5.2) 71 | rack (>= 1.3.0) 72 | rack-accept 73 | rack-mount 74 | virtus 75 | grape-entity (0.3.0) 76 | activesupport 77 | multi_json (>= 1.3.2) 78 | hashie (2.0.5) 79 | hike (1.2.3) 80 | i18n (0.6.9) 81 | ice_nine (0.10.0) 82 | jbuilder (1.5.3) 83 | activesupport (>= 3.0.0) 84 | multi_json (>= 1.2.0) 85 | jquery-rails (3.1.0) 86 | railties (>= 3.0, < 5.0) 87 | thor (>= 0.14, < 2.0) 88 | json (1.8.1) 89 | kgio (2.9.2) 90 | less (2.5.0) 91 | commonjs (~> 0.2.7) 92 | less-rails (2.5.0) 93 | actionpack (>= 3.1) 94 | less (~> 2.5.0) 95 | less-rails-bootstrap (3.1.1.1) 96 | less-rails (~> 2.5.0) 97 | libv8 (3.16.14.3) 98 | mail (2.5.4) 99 | mime-types (~> 1.16) 100 | treetop (~> 1.4.8) 101 | mime-types (1.25.1) 102 | minitest (4.7.5) 103 | moped (2.0.0.beta6) 104 | bson (~> 2.2) 105 | connection_pool (~> 1.2) 106 | optionable (~> 0.2.0) 107 | multi_json (1.8.4) 108 | multi_xml (0.5.5) 109 | netrc (0.7.7) 110 | optionable (0.2.0) 111 | origin (2.1.0) 112 | polyglot (0.3.4) 113 | qiniu-kit (0.1.3) 114 | json (~> 1.8) 115 | qiniu-policy (0.1.1) 116 | qiniu-kit (~> 0.1) 117 | rack (1.5.2) 118 | rack-accept (0.4.5) 119 | rack (>= 0.4) 120 | rack-mount (0.8.3) 121 | rack (>= 1.0.0) 122 | rack-test (0.6.2) 123 | rack (>= 1.0) 124 | rails (4.0.1) 125 | actionmailer (= 4.0.1) 126 | actionpack (= 4.0.1) 127 | activerecord (= 4.0.1) 128 | activesupport (= 4.0.1) 129 | bundler (>= 1.3.0, < 2.0) 130 | railties (= 4.0.1) 131 | sprockets-rails (~> 2.0.0) 132 | railties (4.0.1) 133 | actionpack (= 4.0.1) 134 | activesupport (= 4.0.1) 135 | rake (>= 0.8.7) 136 | thor (>= 0.18.1, < 2.0) 137 | raindrops (0.13.0) 138 | rake (10.1.1) 139 | rdoc (4.1.1) 140 | json (~> 1.4) 141 | ref (1.0.5) 142 | rest_client (1.7.3) 143 | netrc (~> 0.7.7) 144 | ruby-hmac (0.4.0) 145 | sass (3.2.14) 146 | sass-rails (4.0.1) 147 | railties (>= 4.0.0, < 5.0) 148 | sass (>= 3.1.10) 149 | sprockets-rails (~> 2.0.0) 150 | sdoc (0.4.0) 151 | json (~> 1.8) 152 | rdoc (~> 4.0, < 5.0) 153 | sprockets (2.11.0) 154 | hike (~> 1.2) 155 | multi_json (~> 1.0) 156 | rack (~> 1.0) 157 | tilt (~> 1.1, != 1.3.0) 158 | sprockets-rails (2.0.1) 159 | actionpack (>= 3.0) 160 | activesupport (>= 3.0) 161 | sprockets (~> 2.8) 162 | therubyracer (0.12.1) 163 | libv8 (~> 3.16.14.0) 164 | ref 165 | thor (0.18.1) 166 | thread_safe (0.1.3) 167 | atomic 168 | tilt (1.4.1) 169 | treetop (1.4.15) 170 | polyglot 171 | polyglot (>= 0.3.1) 172 | turbolinks (2.2.1) 173 | coffee-rails 174 | tzinfo (0.3.38) 175 | uglifier (2.4.0) 176 | execjs (>= 0.3.0) 177 | json (>= 1.8.0) 178 | unicorn (4.8.2) 179 | kgio (~> 2.6) 180 | rack 181 | raindrops (~> 0.7) 182 | virtus (1.0.0) 183 | axiom-types (~> 0.0.5) 184 | coercible (~> 0.2) 185 | descendants_tracker (~> 0.0.1) 186 | equalizer (~> 0.0.7) 187 | will_paginate (3.0.5) 188 | will_paginate-bootstrap (1.0.0) 189 | will_paginate (>= 3.0.3) 190 | will_paginate_mongoid (2.0.1) 191 | mongoid 192 | will_paginate (~> 3.0) 193 | 194 | PLATFORMS 195 | ruby 196 | 197 | DEPENDENCIES 198 | coffee-rails (~> 4.0.0) 199 | execjs 200 | flatui-rails-less 201 | grape 202 | grape-entity 203 | jbuilder (~> 1.2) 204 | jquery-rails 205 | json 206 | mongoid (~> 4.0.0.beta1)! 207 | qiniu-policy 208 | rails (= 4.0.1) 209 | rest_client 210 | ruby-hmac 211 | sass-rails (~> 4.0.0) 212 | sdoc 213 | therubyracer 214 | turbolinks 215 | uglifier (>= 1.3.0) 216 | unicorn 217 | will_paginate 218 | will_paginate-bootstrap 219 | will_paginate_mongoid 220 | --------------------------------------------------------------------------------