Created
March 30, 2014 16:31
-
-
Save halsk/9875417 to your computer and use it in GitHub Desktop.
LocomotiveCMS のページにユーザー認証機能を組み込む(Engineの拡張) ref: http://qiita.com/hal_sk/items/c6d4f5582d23bc4dd415
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= f.input :published, as: :'Locomotive::Toggle', input_html: { class: 'simple-toggle' } | |
= f.input :require_login, as: :'Locomotive::Toggle', input_html: { class: 'simple-toggle' } #この行を追加 | |
= f.input :listed, as: :'Locomotive::Toggle', input_html: { class: 'simple-toggle' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Auth | |
module AuthField | |
extend ActiveSupport::Concern | |
included do | |
field :require_login, type: Boolean, localize: true | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Auth | |
module AuthPage | |
extend ActiveSupport::Concern | |
included do | |
before_filter :authcheck | |
end | |
def authcheck | |
@page ||= self.locomotive_page | |
authenticate_user! if @page && @page.require_login | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd {RAILS_ROOT} | |
mkdir -p app/controllers/locomotive/public/ | |
vi app/controllers/locomotive/public/pages_controller.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started GET "/entry" for 127.0.0.1 at 2014-03-30 22:07:38 +0900 | |
Processing by Locomotive::Public::PagesController#show as HTML | |
Parameters: {"path"=>"entry"} | |
[LocomotiveCMS] [fetch site] host = localhost / localhost:8080 | |
MOPED: 127.0.0.1:27017 QUERY database=mysite_dev collection=locomotive_sites selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.5510ms) | |
Auth Check ←これ | |
MOPED: 127.0.0.1:27017 QUERY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= semantic_form_for @page, url: page_path(@page), html: { multipart: true } do |form| | |
= render 'form', f: form ←これ | |
= render 'locomotive/shared/form_actions', back_url: pages_path, button_label: :update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bundle exec rails g devise User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% mongo localhost:27017 | |
MongoDB shell version: 2.4.9 | |
connecting to: localhost:27017/test | |
Server has startup warnings: | |
Thu Mar 27 17:45:06.188 [initandlisten] | |
Thu Mar 27 17:45:06.188 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 | |
> use mysite_dev | |
switched to db mysite_dev | |
> db.users.find() | |
{ "_id" : ObjectId("533675464857099c8d000001"), "current_sign_in_at" : ISODate("2014-03-29T07:24:54.852Z"), "current_sign_in_ip" : "127.0.0.1", "email" : "hal@georepublic.co.jp", "encrypted_password" : "$2a$1*******", "last_sign_in_at" : ISODate("2014-03-29T07:24:54.852Z"), "last_sign_in_ip" : "127.0.0.1", "sign_in_count" : 1 } | |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cp {オリジナルのEngineをcloneしておいた場所}/app/views/locomotive/pages/_form.html.haml {RAILS_ROOT}/app/views/locomotive/pages/_form.html.haml | |
vi {RAILS_ROOT}/app/views/locomotive/pages/_form.html.haml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% bundle exec rails console | |
Loading development environment (Rails 3.2.16) | |
[1] pry(main)> | |
[2] pry(main)> Locomotive::Page.first() | |
=> #<Locomotive::Page _id: 53303a0c485709d69800000e, created_at: 2014-03-24 13:58:36 UTC, updated_at: 2014-03-27 03:27:16 UTC, parent_id: "5330384f485709d698000004", parent_ids: ["5330384f485709d698000004"], position: 0, depth: 1, serialized_template: {"ja"=>#<Moped::BSON::Binary type=:generic length=7286>}, template_dependencies: {"ja"=>["5330384f485709d698000004"]}, snippet_dependencies: {"ja"=>["footer"]}, templatized: false, templatized_from_parent: false, target_klass_name: nil, redirect: false, redirect_url: nil, redirect_type: 301, listed: true, seo_title: {"ja"=>"お知らせ"}, meta_keywords: {"ja"=>"html5, "}, meta_description: {"ja"=>"html5, "}, title: {"ja"=>"お知らせ"}, slug: {"ja"=>"news"}, fullpath: {"ja"=>"news"}, handle: "news", raw_template: {"ja"=>"{% extends 'parent' %}\n{% block main %}\n<div class='row'>\n <div class='large-8 columns'>\n <p>News</p>\n {% editable_text \"news_body\", rows: 20 %}\n hoge\n {% endeditable_text %}\n </div>\n</div>\n{% endblock %}\n", "en"=>"{% extends 'parent' %}"}, locales: [:ja], published: true, cache_strategy: "simple", response_type: "text/html", site_id: "5330384f485709d698000002", require_login: nil, cache_strategy_text: "Simple", lang: "ja"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Locomotive | |
class Page | |
include Auth::AuthField | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Locomotive | |
module Public | |
class PagesController < ApplicationController | |
include Auth::AuthPage #AuthPageというプラグインを読み込む | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment