Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
reyesyang committed Dec 19, 2012
2 parents 644e08c + 1aa690f commit c8f0c46
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 207 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -22,6 +22,7 @@ gem 'execjs'
gem 'therubyracer'
gem 'client_side_validations'
gem 'twitter-bootstrap-rails'
gem 'less-rails'
# gem "acts_as_ferret", :git => "https://github.com/jkraemer/acts_as_ferret.git"
# gem "jk-ferret"
# gem "rmmseg-cpp"
Expand Down Expand Up @@ -57,4 +58,5 @@ gem 'rvm-capistrano'

group :development, :test do
gem 'factory_girl_rails'
gem 'quiet_assets'
end
102 changes: 52 additions & 50 deletions Gemfile.lock
@@ -1,51 +1,51 @@
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.8)
actionpack (= 3.2.8)
actionmailer (3.2.9)
actionpack (= 3.2.9)
mail (~> 2.4.4)
actionpack (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
actionpack (3.2.9)
activemodel (= 3.2.9)
activesupport (= 3.2.9)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.3)
activemodel (3.2.8)
activesupport (= 3.2.8)
sprockets (~> 2.2.1)
activemodel (3.2.9)
activesupport (= 3.2.9)
builder (~> 3.0.0)
activerecord (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
activerecord (3.2.9)
activemodel (= 3.2.9)
activesupport (= 3.2.9)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
activesupport (3.2.8)
activeresource (3.2.9)
activemodel (= 3.2.9)
activesupport (= 3.2.9)
activesupport (3.2.9)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
bcrypt-ruby (3.0.1)
builder (3.0.3)
cancan (1.6.7)
capistrano (2.13.4)
builder (3.0.4)
cancan (1.6.8)
capistrano (2.13.5)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
client_side_validations (3.2.0)
client_side_validations (3.2.1)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.3.3)
coffee-script-source (1.4.0)
commonjs (0.2.6)
erubis (2.7.0)
execjs (1.4.0)
Expand All @@ -64,10 +64,9 @@ GEM
httpauth (0.2.0)
i18n (0.6.1)
journey (1.0.4)
jquery-rails (2.1.3)
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
jruby-pageant (1.1.1)
jquery-rails (2.1.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.7.5)
jwt (0.1.5)
multi_json (>= 1.0)
Expand All @@ -76,21 +75,19 @@ GEM
less-rails (2.2.3)
actionpack (>= 3.1)
less (~> 2.2.0)
libv8 (3.3.10.4)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.19)
multi_json (1.3.6)
multi_json (1.5.0)
multipart-post (1.1.5)
mysql2 (0.3.11)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.6.0)
jruby-pageant (>= 1.1.1)
net-ssh (2.6.2)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
oauth (0.4.7)
Expand Down Expand Up @@ -118,62 +115,65 @@ GEM
omniauth-oauth2 (1.1.1)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
omniauth-twitter (0.0.13)
omniauth-twitter (0.0.14)
multi_json (~> 1.3)
omniauth-oauth (~> 1.0)
omniauth-xiaonei (0.0.3)
omniauth-oauth2
polyglot (0.3.3)
quiet_assets (1.0.1)
railties (~> 3.1)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.8)
actionmailer (= 3.2.8)
actionpack (= 3.2.8)
activerecord (= 3.2.8)
activeresource (= 3.2.8)
activesupport (= 3.2.8)
rails (3.2.9)
actionmailer (= 3.2.9)
actionpack (= 3.2.9)
activerecord (= 3.2.9)
activeresource (= 3.2.9)
activesupport (= 3.2.9)
bundler (~> 1.0)
railties (= 3.2.8)
railties (3.2.8)
actionpack (= 3.2.8)
activesupport (= 3.2.8)
railties (= 3.2.9)
railties (3.2.9)
actionpack (= 3.2.9)
activesupport (= 3.2.9)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (0.9.2.2)
rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
redcarpet (2.1.1)
redcarpet (2.2.2)
ref (1.0.2)
rvm-capistrano (1.2.7)
capistrano (>= 2.0.0)
sass (3.2.1)
sass (3.2.3)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sprockets (2.1.3)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
therubyracer (0.10.2)
libv8 (~> 3.3.10)
therubyracer (0.11.0)
ref
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.11)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
twitter-bootstrap-rails (2.1.3)
twitter-bootstrap-rails (2.1.9)
actionpack (>= 3.1)
less-rails (~> 2.2.3)
execjs
railties (>= 3.1)
therubyracer (~> 0.10.2)
tzinfo (0.3.33)
tzinfo (0.3.35)
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
Expand All @@ -195,13 +195,15 @@ DEPENDENCIES
haml
jquery-rails
json
less-rails
mysql2
omniauth
omniauth-douban-oauth2
omniauth-github
omniauth-google-oauth2
omniauth-twitter
omniauth-xiaonei
quiet_assets
rails (~> 3.2.1)
redcarpet
rvm-capistrano
Expand Down
10 changes: 1 addition & 9 deletions app/controllers/application_controller.rb
@@ -1,8 +1,7 @@
# -*- encoding : utf-8 -*-
class ApplicationController < ActionController::Base
protect_from_forgery
authorize_resource
before_filter :get_tags
check_authorization

helper_method :current_user, :logined?

Expand All @@ -17,11 +16,4 @@ def logined?
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, flash: { error: exception.message }
end

protected
def get_tags
@tags = current_user && current_user.admin? ?
Tag.all :
Tag.where("name != 'draft'")
end
end
56 changes: 11 additions & 45 deletions app/controllers/articles_controller.rb
@@ -1,91 +1,66 @@
# -*- encoding : utf-8 -*-
class ArticlesController < ApplicationController
skip_before_filter :authorize, :only => [:index, :show, :tagged]
# GET /articles
# GET /articles.xml
before_filter :load_article_with_tags, only: [:show, :edit]
load_and_authorize_resource

def index
@articles = current_user && current_user.admin? ?
Article.includes(:tags).order('articles.id DESC').paginate(:page => params[:page]) :
Article.includes(:tags).where("tags.name != 'draft'").order('articles.id DESC').paginate(:page => params[:page])
@articles.includes(:tags).paginate(:page => params[:page]) :
@articles.includes(:tags).where("tags.name != 'draft'").paginate(:page => params[:page])

@page_title = '首页'

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @articles }
format.html
end
end

# GET /articles/1
# GET /articles/1.xml
def show
@article = Article.includes(:tags).find(params[:id])
@page_title = '文章 - ' + @article.title
@page_description = @article.title

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @article }
format.html
end
end

# GET /articles/new
# GET /articles/new.xml
def new
@article = Article.new
@page_title = '发布文章'

respond_to do |format|
#format.html
format.html { render layout: 'wide' }
format.xml { render :xml => @article }
end
end

# GET /articles/1/edit
def edit
@article = Article.includes(:tags).find(params[:id])
@page_title = '编辑文章 - ' + @article.title
render layout: 'wide'
end

# POST /articles
# POST /articles.xml
def create
@article = Article.new(params[:article])

respond_to do |format|
if @article.save
format.html { redirect_to(@article, :notice => 'Article was successfully created.') }
format.xml { render :xml => @article, :status => :created, :location => @article }
else
format.html { render :action => "new" }
format.xml { render :xml => @article.errors, :status => :unprocessable_entity }
end
end
end

# PUT /articles/1
# PUT /articles/1.xml
def update
@article = Article.find(params[:id])

respond_to do |format|
if @article.update_attributes(params[:article])
#if @article.save
format.html { redirect_to(@article, :notice => 'Article was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @article.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /articles/1
# DELETE /articles/1.xml
def destroy
@article = Article.find(params[:id])
@article.destroy

respond_to do |format|
Expand All @@ -94,17 +69,8 @@ def destroy
end
end

# GET /articles/tag/1
def tagged
#tag = Tag.find params[:tag_id]
tag = Tag.find_by_name params[:tag]
@articles = tag.articles.includes(:tags).paginate(:page => params[:page],
:order => 'created_at DESC')
@page_title = @page_description = '标签为' + tag.name + '的文章'

respond_to do |format|
format.html { render 'index' }
format.xml { render :xml => @articles }
end
end
private
def load_article_with_tags
@article = Article.includes(:tags).find(params[:id])
end
end
18 changes: 17 additions & 1 deletion app/controllers/sessions_controller.rb
@@ -1,5 +1,6 @@
class SessionsController < ApplicationController
skip_authorize_resource
authorize_resource :class => false

def create
omniauth = request.env['omniauth.auth']
auth = Authorization.where(provider: omniauth['provider'], uid: omniauth['uid']).first_or_create do |auth|
Expand All @@ -10,4 +11,19 @@ def create
session[:user_id] = auth.user.id
redirect_to root_path
end

def login
user = User.find_by_name params[:name]
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to articles_url
else
redirect_to root_url
end
end

def logout
reset_session
redirect_to :root
end
end

0 comments on commit c8f0c46

Please sign in to comment.