Created
April 8, 2014 09:04
-
-
Save halsk/10103204 to your computer and use it in GitHub Desktop.
LocomotiveCMS + Devise を使って作ったログインページのデザインをCMS側でできるようにする(2) ref: http://qiita.com/hal_sk/items/c0f56736398f1154ddca
This file contains hidden or 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
class Users::ConfirmationsController < Devise::ConfirmationsController | |
protected | |
# The path used after confirmation. | |
def after_confirmation_path_for(resource_name, resource) | |
if signed_in? | |
'/registrationfinished' | |
else | |
new_session_path(resource_name) | |
end | |
end | |
end |
This file contains hidden or 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
def create | |
build_resource(params.fetch(resource_name, {})) #パラメータから resource クラスを作成(Userクラスが入っている) | |
resource_saved = resource.save #保存 | |
yield resource if block_given? | |
if resource_saved #ユーザ登録成功 | |
if resource.active_for_authentication? | |
# メールによる確認なし | |
sign_up(resource_name, resource) | |
respond_with resource, location: after_sign_up_path_for(resource) | |
else | |
# メールによる確認あり | |
@page = self.locomotive_page('/registrationconfirm') | |
expire_data_after_sign_in! | |
respond_to do |format| | |
format.html { | |
render :inline => @page.render(self.locomotive_context({})) | |
} | |
end | |
end | |
else | |
# バリデーションエラー(再度入力フォームを呼び出す) | |
@page ||= self.locomotive_page('/userregistration') | |
clean_up_passwords resource | |
respond_to do |format| | |
format.html { | |
render :inline => @page.render(self.locomotive_context({ 'user' => resource, 'error' => devise_error_messages! })) | |
} | |
end | |
end | |
end | |
# エラーメッセージを作って返す | |
def devise_error_messages! | |
return "" if resource.errors.empty? | |
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join | |
html = <<-HTML | |
<div id="error_explanation"> | |
<h2>エラーが発生しました</h2> | |
<ul>#{messages}</ul> | |
</div> | |
HTML | |
html.html_safe | |
end | |
# セッションキーの削除 | |
def expire_data_after_sign_in! | |
# session.keys will return an empty array if the session is not yet loaded. | |
# This is a bug in both Rack and Rails. | |
# A call to #empty? forces the session to be loaded. | |
session.empty? | |
session.keys.grep(/^devise\./).each { |k| session.delete(k) } | |
end | |
# サインアップ後のリダイレクト先 | |
def after_sign_up_path_for(resource) | |
'/registrationfinished' | |
end |
This file contains hidden or 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
--- | |
title: ユーザー登録メール送信済 | |
slug: registrationconfirm | |
listed: false | |
published: true | |
cache_strategy: none | |
response_type: text/html | |
--- | |
{% extends 'parent' %} | |
{% block main %} | |
.row | |
.large-8.columns | |
%h1 仮登録完了 | |
入力されたメールアドレスに確認のメールをお送りしました。メール本文に書かれているURLをクリックして登録を完了させてください。 | |
{% endblock %} |
This file contains hidden or 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
--- | |
title: ユーザー登録完了 | |
slug: registrationfinished | |
listed: false | |
published: true | |
cache_strategy: none | |
response_type: text/html | |
--- | |
{% extends 'parent' %} | |
{% block main %} | |
.row | |
.large-8.columns | |
%h1 登録完了 | |
ユーザー登録が完了し、ログイン済です。 | |
{% endblock %} |
This file contains hidden or 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
devise_for :users, :controllers => { | |
:registrations => 'users/registrations', | |
:confirmations => 'users/confirmations' | |
} |
This file contains hidden or 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
class User < Liquid::Drop | |
include Mongoid::Document | |
… | |
end |
This file contains hidden or 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
--- | |
title: ユーザー登録 | |
slug: userregistration | |
listed: false | |
published: true | |
cache_strategy: none | |
response_type: text/html | |
position: 4 | |
--- | |
{% extends 'parent' %} | |
{% block main %} | |
.row | |
.large-8.columns | |
%h1 ユーザー登録ページ | |
.error {{error}} | |
%form#new_user.new_user{"accept-charset" => "UTF-8", :action => "/users", :method => "post"} | |
.hidden | |
{% csrf_param %} | |
%input{:name => "utf8", :type => "hidden", :value => "✓"}/ | |
%div | |
%label{:for => "user_email"} Email | |
%br/ | |
%input#user_email{:autofocus => "autofocus", :keyev => "true", :mouseev => "true", :name => "user[email]", :size => "30", :type => "email", :value => "{{user.email}}"}/ | |
%div | |
%label{:for => "user_password"} Password | |
%br/ | |
%input#user_password{:keyev => "true", :mouseev => "true", :name => "user[password]", :size => "30", :type => "password"}/ | |
%div | |
%label{:for => "user_password_confirmation"} Password confirmation | |
%br/ | |
%input#user_password_confirmation{:keyev => "true", :mouseev => "true", :name => "user[password_confirmation]", :size => "30", :type => "password"}/ | |
%div | |
%input{:name => "commit", :type => "submit", :value => "Sign up"}/ | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment