Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

まとめ詳細: 一定数以上のクリップ閲覧にログイン制限を追加 #55

Merged
merged 7 commits into from
Dec 21, 2013
Merged
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//= require bootstrap-dropdown
//= require bootstrap-carousel
//= require bootstrap-transition
//= require bootstrap-modal
//= require masonry/jquery.masonry
//= require masonry/jquery.imagesloaded.min
//= require masonry/jquery.infinitescroll.min
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/application.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,8 @@ body {
/* width: 838px; */
width: 100%;
}

/* dialog */
.modal h3 {
font-size: x-large;
}
42 changes: 23 additions & 19 deletions app/assets/stylesheets/scaffolds.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
@import "bootstrap/variables";
@import "bootstrap/mixins";
@import "bootstrap/alerts";
@import "bootstrap/forms";

body {
background-color: #fff;
color: #333;
Expand Down Expand Up @@ -26,31 +31,30 @@ div {
}

.field_with_errors {
padding: 2px;
background-color: red;
display: table;
@extend .control-group;
@extend .error;
margin-bottom: 0;
display: inline-block;
}

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
@extend .alert;
@extend .alert-error;
@extend .alert-block;

h2 {
text-align: left;
font-size: large;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;

ul {
margin-top: 0.5em;
margin-left: 2em;
list-style-type: disc;
}

li {
line-height: 120%;
}
}

Expand Down
68 changes: 61 additions & 7 deletions app/assets/stylesheets/users.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

@import "carousel";

@import "common";

$screen_width: 900px;
$carousel_item_count_x: 4;
$carousel_item_count_y: 2;
Expand Down Expand Up @@ -150,22 +152,74 @@ $user_menu_height: 100px;
right: 0;
}

#user_header .profile {
#edit_button {
visibility: hidden;
}

&:hover #edit_button {
visibility: visible;
}
}

/* user */
#user {
form {
width: $screen_width;
h2 {
font-size: large;
margin-bottom: 0.5em;
}
}

/* forms */
#user form.edit_user {
width: $screen_width;

fieldset {
margin-bottom: 50px;
}
}

#user_header .profile {
#edit_button {
visibility: hidden;
#user form.new_user {
input[type="submit"] {
@extend .btn;
@extend .btn-large;
}

&:hover #edit_button {
visibility: visible;
.must {
&:after {
content: '*';
color: red;
font-weight: bold;
}
}
}

#user .shared_links {
margin-top: 15px;
margin-left: 5px;

li {
margin-bottom: 0.5em;
}

.facebook a {
padding: 10px 20px;
font-size: large;
font-family: $font_gothic;
@extend .btn;
}

.facebook a {
@extend .btn-primary;
@include icon(facebook);
&:before {
margin-right: 15px;
padding-right: 17px;
border-right: 1px solid #37d;
}
}
}

#dialog #user {
text-align: center;
}
4 changes: 2 additions & 2 deletions app/assets/stylesheets/wall.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ ul.comments li p {
@include border-radius(4px);
@include transition-property(opacity);
@include transition-duration(0.25s);
opacity: 0.5;
opacity: 1;

&:hover {
text-decoration: none;
opacity: 1;
opacity: 0.5;
}
}

Expand Down
7 changes: 0 additions & 7 deletions app/controllers/clips_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,6 @@ def destroy

private

def authenticate_user!
return super unless request.xhr?
return if user_signed_in?
flash[:alert] = 'この操作にはログインが必要です'
render js: %{window.location = "#{new_user_session_path}"}
end

def insert_div_tag_for_image_tag
-> image_tag { "<div class='box image_box'>#{image_tag}</div>" }
end
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/matomes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ def show
@matome.increment_view_count!(request)
@clips = @matome.clips.page(params[:page])
@cover_clip = @clips.try(:first)
render 'home/next_page', layout: false unless first_page?

return if first_page?

if user_signed_in?
render 'home/next_page', layout: false
else
render nothing: true
end
end

# GET /matomes/new
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/matomes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ def unlike_to_matome(matome, options={})
default_options = { method: :delete, remote: true }
link_to('イイネ!を取り消す', like_matome_path(matome), default_options.merge(options))
end

def left_clips_count
@clips.total_count - @clips.size
end
end
12 changes: 12 additions & 0 deletions app/views/base/_dialog.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- title ||= nil
- body ||= nil

.modal.fade.hide tabindex="-1" role="dialog" aria-hidden="true"
.modal-header
button type="button" class="close" data-dismiss="modal" aria-hidden="true"
| &times;
- if title
h3 = title
.modal-body
- if body
== body
18 changes: 0 additions & 18 deletions app/views/devise/registrations/new.html.erb

This file was deleted.

22 changes: 22 additions & 0 deletions app/views/devise/registrations/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#user
h2 新規登録

= form_for resource, as: resource_name, url: registration_path(resource_name) do |f|
= devise_error_messages!

.name
= f.text_field :name, placeholder: I18n.t(:name)

.email.must
= f.email_field :email, placeholder: I18n.t(:email)

.password.must
= f.password_field :password, placeholder: I18n.t(:password)

.password_confirmation.must
= f.password_field :password_confirmation, placeholder: I18n.t(:password_confirmation)

.submit
= f.submit I18n.t(:sign_up)

== render partial: 'devise/shared/links'
12 changes: 12 additions & 0 deletions app/views/devise/registrations/new.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$dialog = $('#dialog')
if $dialog.length == 0
$dialog = $('<div/>')
else
$dialog.remove()

$dialog.attr('id', 'dialog')
$dialog.html('<%= escape_javascript(render template: 'base/_dialog', formats: :html, locals: { title: 'ログインするとお得な機能がいっぱい!', show: true }) %>')
$dialog.find('.modal-body').html('<%= escape_javascript(render template: 'devise/registrations/new', formats: :html) %>')
$('#container').append($dialog)

$dialog.find('.modal').modal('show')
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
<div><%= f.submit "Sign in" %></div>
<% end %>

<%= render :partial => "devise/shared/links" %>
<%= render :partial => "devise/shared/links" %>
23 changes: 0 additions & 23 deletions app/views/devise/shared/_links.erb

This file was deleted.

17 changes: 17 additions & 0 deletions app/views/devise/shared/_links.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ul.shared_links
- if devise_mapping.omniauthable?
- resource.class.omniauth_providers.each do |provider|
li class="#{provider}"
= link_to "#{provider.to_s.titleize}でログイン", omniauth_authorize_path(resource_name, provider)

- if devise_mapping.registerable? && controller_name != 'registrations'
li = link_to "新規登録", new_registration_path(resource_name)

- if devise_mapping.recoverable? && controller_name != 'passwords'
li = link_to "パスワードを忘れた場合", new_password_path(resource_name)

- if devise_mapping.confirmable? && controller_name != 'confirmations'
li = link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name)

- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
li = link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name)
5 changes: 4 additions & 1 deletion app/views/matomes/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@
p クリップが存在しません

#done.hidden
= link_to "ほかのまとめを見る", matomes_path
- if user_signed_in? || left_clips_count.zero?
= link_to "ほかのまとめを見る", matomes_path
- else
= link_to "もっと見る (#{left_clips_count})", new_user_registration_path, remote: true
3 changes: 3 additions & 0 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,7 @@
# manager.intercept_401 = false
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
# end
config.warden do |manager|
manager.failure_app = CustomFailure
end
end
3 changes: 2 additions & 1 deletion config/locales/translation_ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ja:
name: &g_name ユーザー名
email: &g_email メールアドレス
password: &g_password パスワード
password_confirmation: &g_password_confirmation パスワード(確認)
created_at: &g_created_at 作成日時
updated_at: &g_updated_at 更新日時
refresh: 更新
Expand Down Expand Up @@ -39,7 +40,7 @@ ja:
reset_password_sent_at: reset_password_sent_at #g
reset_password_token: reset_password_token #g
password: *g_password
password_confirmation: パスワード(確認)
password_confirmation: *g_password_confirmation
remember_me: 次回から自動的にログイン
sign_up: 新規登録
sign_in: ログイン
Expand Down
27 changes: 27 additions & 0 deletions lib/custom_failure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class CustomFailure < Devise::FailureApp
def redirect_url
if warden_options[:scope] == :user
new_user_registration_path
else
super
end
end

def respond
if http_auth?
http_auth
else
redirect
end
end

def redirect_to(options={}, response_status={})
# If you are using XHR requests other than GET or POST and redirecting after the request
# then some browsers will follow the redirect using the original request method.
# This may lead to undesirable behavior such as a double DELETE.
# To work around this you can return a 303 See Other status code which will be followed using a GET request.
# -- from http://api.rubyonrails.org/classes/ActionController/Redirecting.html
default_response_status = { status: 303 }
super options, default_response_status.merge(response_status)
end
end
Loading