From ec6b58680b282aa3b2d25e30505684d12bd7c9ca Mon Sep 17 00:00:00 2001 From: Ilya Konanykhin Date: Wed, 21 Dec 2016 17:17:54 +0600 Subject: [PATCH] BS3: devise & flash messaging. --- app/assets/stylesheets/frontend.scss | 5 ++ app/helpers/devise_helper.rb | 17 +++--- app/views/devise/_links.erb | 32 ---------- app/views/devise/_links.html.haml | 20 +++++++ app/views/devise/passwords/edit.html.erb | 16 ----- app/views/devise/passwords/edit.html.haml | 19 ++++++ app/views/devise/passwords/new.html.erb | 14 ----- app/views/devise/passwords/new.html.haml | 15 +++++ .../_user_profile_fields.html.haml | 31 +++++----- app/views/devise/registrations/new.html.haml | 58 ++++++++++++------- app/views/devise/sessions/new.html.erb | 46 --------------- app/views/devise/sessions/new.html.haml | 41 +++++++++++++ app/views/layouts/application.html.haml | 13 ++--- 13 files changed, 166 insertions(+), 161 deletions(-) delete mode 100644 app/views/devise/_links.erb create mode 100644 app/views/devise/_links.html.haml delete mode 100644 app/views/devise/passwords/edit.html.erb create mode 100644 app/views/devise/passwords/edit.html.haml delete mode 100644 app/views/devise/passwords/new.html.erb create mode 100644 app/views/devise/passwords/new.html.haml delete mode 100644 app/views/devise/sessions/new.html.erb create mode 100644 app/views/devise/sessions/new.html.haml diff --git a/app/assets/stylesheets/frontend.scss b/app/assets/stylesheets/frontend.scss index ff8c444..991a1ec 100644 --- a/app/assets/stylesheets/frontend.scss +++ b/app/assets/stylesheets/frontend.scss @@ -4,4 +4,9 @@ body { .x-boundlist-item { white-space: nowrap; +} + +fieldset { + margin-top: $line-height-computed; + margin-bottom: $line-height-computed; } \ No newline at end of file diff --git a/app/helpers/devise_helper.rb b/app/helpers/devise_helper.rb index e672d5b..588b429 100644 --- a/app/helpers/devise_helper.rb +++ b/app/helpers/devise_helper.rb @@ -1,21 +1,18 @@ module DeviseHelper - # A simple way to show error messages for the current devise resource. If you need - # to customize this method, you can either overwrite it in your application helpers or - # copy the views to your application. - # - # This method is intended to stay simple and it is unlikely that we are going to change - # it to add more behavior or options. def devise_error_messages! - return "" if resource.errors.empty? + return '' if resource.errors.empty? - messages = resource.errors.full_messages.map { |msg| content_tag(:p, msg, :class => "alert") }.join + messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) } sentence = I18n.t("errors.messages.not_saved", :count => resource.errors.count, :resource => resource.class.model_name.human.downcase) html = <<-HTML -

#{sentence}

- #{messages} +
#{sentence} + +
HTML html.html_safe diff --git a/app/views/devise/_links.erb b/app/views/devise/_links.erb deleted file mode 100644 index fc68770..0000000 --- a/app/views/devise/_links.erb +++ /dev/null @@ -1,32 +0,0 @@ -<%- if controller_name != 'sessions' %> -

- <%= link_to "Sign in", new_session_path(resource_name), class: "btn btn-block btn-default" %>
-

-<% end -%> - -<%- if devise_mapping.registerable? && controller_name != 'registrations' %> -

- <%= link_to "Sign up", new_registration_path(resource_name), class: "btn btn-block btn-default" %>
-

-<% end -%> - -<%- if devise_mapping.recoverable? && controller_name != 'passwords' %> -

- <%= link_to "Forgot your password?", new_password_path(resource_name), class: "btn btn-block btn-default" %>
-

-<% end -%> - -<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> -

- <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name), class: "btn btn-block btn-default" %>
-

-<% end -%> - -<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> -<% end -%> - -<%- if devise_mapping.omniauthable? %> - <%- resource_class.omniauth_providers.each do |provider| %> - <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
- <% end -%> -<% end -%> diff --git a/app/views/devise/_links.html.haml b/app/views/devise/_links.html.haml new file mode 100644 index 0000000..c75d77c --- /dev/null +++ b/app/views/devise/_links.html.haml @@ -0,0 +1,20 @@ +- links = [] + +- if controller_name != 'sessions' + - links << ['Sign in', new_session_path(resource_name)] + +- if devise_mapping.registerable? && controller_name != 'registrations' + - links << ['Sign up', new_registration_path(resource_name)] + +- if devise_mapping.recoverable? && controller_name != 'passwords' + - links << ['Forgot your password?', new_password_path(resource_name)] + +- if devise_mapping.confirmable? && controller_name != 'confirmations' + - links << ['Didn\'t receive confirmation instructions?', new_confirmation_path(resource_name)] + +- if devise_mapping.omniauthable? + - resource_class.omniauth_providers.each do |provider| + - links << ["Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider)] + +- if links.any? + %p= links.map { |title, url| link_to title, url }.join(' · ').html_safe diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb deleted file mode 100644 index 9272916..0000000 --- a/app/views/devise/passwords/edit.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -

Change your password

- -<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %> - <%= devise_error_messages! %> - <%= f.hidden_field :reset_password_token %> - -
<%= f.label :password, "New password" %>
- <%= f.password_field :password %>
- -
<%= f.label :password_confirmation, "Confirm new password" %>
- <%= f.password_field :password_confirmation %>
- -
<%= f.submit "Change my password" %>
-<% end %> - -<%= render "links" %> diff --git a/app/views/devise/passwords/edit.html.haml b/app/views/devise/passwords/edit.html.haml new file mode 100644 index 0000000..7b75a8b --- /dev/null +++ b/app/views/devise/passwords/edit.html.haml @@ -0,0 +1,19 @@ +%h1 Change your password + +.row + .col-xs-12.col-sm-6.col-lg-4 + = form_for resource, as: resource_name, url: password_path(resource_name), html: {method: :put} do |f| + = devise_error_messages! + = f.hidden_field :reset_password_token + + %fieldset + .form-group + = f.password_field :password, placeholder: 'New password', class: 'form-control' + + .form-group + = f.password_field :password_confirmation, placeholder: 'Confirm new password', class: 'form-control' + + .form-group + = f.submit 'Change my password', class: 'btn btn-primary' + + = render 'links' diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb deleted file mode 100644 index 17796e3..0000000 --- a/app/views/devise/passwords/new.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -

Forgot your password?

-
-
-<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %> - <%= devise_error_messages! %> - -
- <%= f.email_field :email, placeholder: "Email", class: "form-control input-lg" %> -
- -
<%= f.submit "Reset Password", class:"btn btn-lg btn-primary"%>
-<% end %> - -<%= render "links" %> diff --git a/app/views/devise/passwords/new.html.haml b/app/views/devise/passwords/new.html.haml new file mode 100644 index 0000000..155e406 --- /dev/null +++ b/app/views/devise/passwords/new.html.haml @@ -0,0 +1,15 @@ +%h1 Forgot your password? + +.row + .col-xs-12.col-sm-6.col-lg-4 + = form_for resource, as: resource_name, url: password_path(resource_name), html: {method: :post } do |f| + = devise_error_messages! + + %fieldset + .form-group + = f.email_field :email, placeholder: 'Email', class: 'form-control' + + .form-group + = f.submit 'Reset Password', class: 'btn btn-primary' + + = render 'links' diff --git a/app/views/devise/registrations/_user_profile_fields.html.haml b/app/views/devise/registrations/_user_profile_fields.html.haml index 471e288..9a7323f 100644 --- a/app/views/devise/registrations/_user_profile_fields.html.haml +++ b/app/views/devise/registrations/_user_profile_fields.html.haml @@ -1,14 +1,17 @@ -%p - %fieldset - .form-group - = f.text_field :addrStreet1, placeholder: "Street Address Line 1", :class => "form-control input-lg" - .form-group - = f.text_field :addrStreet2, placeholder: "Street Address Line 2",:class => "form-control input-lg" - .form-group - = f.text_field :addrCity, placeholder: "City", :class => "form-control input-lg" - .form-group - = f.text_field :addrState, placeholder: "State Abbreviation", :class => "form-control input-lg" - .form-group - = f.text_field :addrZip, placeholder: "Zip Code", :class => "form-control input-lg" - .form-group - = f.text_field :phone, placeholder: "Phone", :class => "form-control input-lg" +.form-group + = f.text_field :addrStreet1, placeholder: 'Street Address Line 1', class: 'form-control' + +.form-group + = f.text_field :addrStreet2, placeholder: 'Street Address Line 2',class: 'form-control' + +.form-group + = f.text_field :addrCity, placeholder: 'City', class: 'form-control' + +.form-group + = f.text_field :addrState, placeholder: 'State Abbreviation', class: 'form-control' + +.form-group + = f.text_field :addrZip, placeholder: 'Zip Code', class: 'form-control' + +.form-group + = f.text_field :phone, placeholder: 'Phone', class: 'form-control' diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index 7ef96cf..823795a 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -1,22 +1,36 @@ -= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| - = devise_error_messages! - .controls - %h2 Sign up - .form-group - = f.text_field :username, placeholder: "Username", :class => "form-control input-lg" - .form-group - = f.text_field :first_name, placeholder: "First Name", :class => "form-control input-lg" - .form-group - = f.text_field :last_name, placeholder: "Last Name", :class => "form-control input-lg" - .form-group - = f.email_field :email, placeholder: "E-mail", :class => "form-control input-lg" - - profile_builder = resource.user_profiles.empty? ? resource.user_profiles.build : resource.user_profiles - = f.fields_for :user_profiles, profile_builder do |builder| - = render 'user_profile_fields', f: builder - .form-group - = f.password_field :password, placeholder: "Password", :class => "form-control input-lg" - .form-group - = f.password_field :password_confirmation, placeholder: "Password Confirmation", :class => "form-control input-lg" - .form-group - = f.submit "Sign up", class:"btn btn-lg btn-primary" -= render "links" +%h1 Sign up + +.row + .col-xs-12.col-sm-6.col-lg-4 + = form_for resource, as: resource_name, url: registration_path(resource_name) do |f| + = devise_error_messages! + + %fieldset + .form-group + = f.text_field :username, placeholder: 'Username', class: 'form-control' + + .form-group + = f.text_field :first_name, placeholder: 'First Name', class: 'form-control' + + .form-group + = f.text_field :last_name, placeholder: 'Last Name', class: 'form-control' + + .form-group + = f.email_field :email, placeholder: 'E-mail', class: 'form-control' + + %fieldset + - profile_builder = resource.user_profiles.empty? ? resource.user_profiles.build : resource.user_profiles + = f.fields_for :user_profiles, profile_builder do |builder| + = render 'user_profile_fields', f: builder + + %fieldset + .form-group + = f.password_field :password, placeholder: 'Password', class: 'form-control' + + .form-group + = f.password_field :password_confirmation, placeholder: 'Password Confirmation', class: 'form-control' + + .form-group + = f.submit 'Sign up', class: 'btn btn-primary' + + = render 'links' diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb deleted file mode 100644 index cdf7a6e..0000000 --- a/app/views/devise/sessions/new.html.erb +++ /dev/null @@ -1,46 +0,0 @@ -

Velocipede

-Made with ♥ in Baltimore -
-
-<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> -
- <%= f.text_field :username, placeholder: "Username", class: "form-control input-lg"%> -
- -
- <%= f.password_field :password, placeholder: "Password", class: "form-control input-lg" %> -
- -
- <% if devise_mapping.rememberable? -%> - - <% end -%> -
- -
-

- <%= f.submit "Sign in", class:"btn btn-lg btn-primary" %> -

-

Or quickly...

-
- - -
-
-<% end %> - -<%= render "links" %> - -<% if Rails.env.development? %> -

- <% User.all.each do |user| %> - <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> - <%= f.hidden_field :username, :value => user.username%> - <%= f.hidden_field :password, :value => 'password' %> - <%= f.submit "Sign in as #{user.username}", class:"btn btn-info" %> - <% end %> - <% end %> -

-<% end %> diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml new file mode 100644 index 0000000..048fa83 --- /dev/null +++ b/app/views/devise/sessions/new.html.haml @@ -0,0 +1,41 @@ +%h1 Velocipede +%p= link_to 'Made with ♥ in Baltimore'.html_safe, 'http://madewithloveinbaltimore.org' + +.row + .col-xs-12.col-sm-6.col-lg-4 + = form_for resource, as: resource_name, url: session_path(resource_name) do |f| + + %fieldset + .form-group + = f.text_field :username, placeholder: 'Username', class: 'form-control' + + .form-group + = f.password_field :password, placeholder: 'Password', class: 'form-control' + + - if devise_mapping.rememberable? + .form-group + .checkbox + = f.label :remember_me do + = f.check_box :remember_me + Remember Me + + .form-group + .pull-left + = f.submit 'Sign in', class: 'btn btn-primary' + + .pull-right + %span.btn-group + = f.button 'CHECK IN', id: 'checkin', name: 'checkin', type: 'button', value: 'CHECK IN', class: 'btn btn-xsя btn-success' + = f.button 'CHECK OUT', id: 'checkout', name: 'checkout', type: 'button', value: 'CHECK OUT', class: 'btn btn-xsя btn-danger' + + .clearfix + + = render 'links' + + - if false && Rails.env.development? + %hr + - User.all.each do |user| + = form_for resource, as: resource_name, url: session_path(resource_name) do |f| + = f.hidden_field :username, value: user.username + = f.hidden_field :password, value: 'password' + %p= f.submit "Sign in as #{user.username}", class: 'btn btn-sm btn-info' \ No newline at end of file diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index ddb6171..fad9fb6 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -11,18 +11,17 @@ %body .container - .content - if flash[:notice] - %p{class: 'notice'}= flash[:notice] + %div.alert.alert-info= flash[:notice] - if flash[:alert] - %p{class: 'alert'}= flash[:alert] - .row - .span12 - = yield + %div.alert.alert-danger= flash[:alert] + + = yield %footer - %p © BikeShed #{Time.now.year} + %hr + %p.text-muted © BikeShed #{Time.now.year} = javascript_include_tag 'application' = javascript_include_tag params[:controller]