From 6045b6cb1880b27e8b21799b9501a794a5f5b88b Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 5 Mar 2016 22:43:05 +0100 Subject: Customizing devise views and controllers --- app/views/auth/mailer/password_change.html.erb | 3 +++ .../mailer/reset_password_instructions.html.erb | 8 +++++++ app/views/auth/passwords/edit.html.erb | 25 ++++++++++++++++++++++ app/views/auth/passwords/new.html.haml | 9 ++++++++ app/views/auth/registrations/edit.html.haml | 11 ++++++++++ app/views/auth/registrations/new.html.haml | 17 +++++++++++++++ app/views/auth/sessions/new.html.haml | 9 ++++++++ app/views/auth/shared/_links.html.haml | 19 ++++++++++++++++ app/views/home/index.html.haml | 2 ++ app/views/layouts/application.html.haml | 5 +---- app/views/layouts/auth.html.haml | 10 +++++++++ 11 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 app/views/auth/mailer/password_change.html.erb create mode 100644 app/views/auth/mailer/reset_password_instructions.html.erb create mode 100644 app/views/auth/passwords/edit.html.erb create mode 100644 app/views/auth/passwords/new.html.haml create mode 100644 app/views/auth/registrations/edit.html.haml create mode 100644 app/views/auth/registrations/new.html.haml create mode 100644 app/views/auth/sessions/new.html.haml create mode 100644 app/views/auth/shared/_links.html.haml create mode 100644 app/views/layouts/auth.html.haml (limited to 'app/views') diff --git a/app/views/auth/mailer/password_change.html.erb b/app/views/auth/mailer/password_change.html.erb new file mode 100644 index 000000000..b41daf476 --- /dev/null +++ b/app/views/auth/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/auth/mailer/reset_password_instructions.html.erb b/app/views/auth/mailer/reset_password_instructions.html.erb new file mode 100644 index 000000000..f667dc12f --- /dev/null +++ b/app/views/auth/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/auth/passwords/edit.html.erb b/app/views/auth/passwords/edit.html.erb new file mode 100644 index 000000000..6a796b050 --- /dev/null +++ b/app/views/auth/passwords/edit.html.erb @@ -0,0 +1,25 @@ +

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" %>
+ <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum)
+ <% end %> + <%= f.password_field :password, autofocus: true, autocomplete: "off" %> +
+ +
+ <%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %> +
+ +
+ <%= f.submit "Change my password" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/auth/passwords/new.html.haml b/app/views/auth/passwords/new.html.haml new file mode 100644 index 000000000..2677feea0 --- /dev/null +++ b/app/views/auth/passwords/new.html.haml @@ -0,0 +1,9 @@ += form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| + = devise_error_messages! + + .field + = f.email_field :email, autofocus: true, required: true, placeholder: 'E-mail address' + .actions + = f.button "Reset password", type: 'submit' + +.form-footer= render "auth/shared/links" diff --git a/app/views/auth/registrations/edit.html.haml b/app/views/auth/registrations/edit.html.haml new file mode 100644 index 000000000..943230b34 --- /dev/null +++ b/app/views/auth/registrations/edit.html.haml @@ -0,0 +1,11 @@ += form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| + = devise_error_messages! + + .field + = f.password_field :password, autocomplete: "off", placeholder: 'New password' + .field + = f.password_field :password_confirmation, autocomplete: "off", placeholder: 'Confirm new password' + .field + = f.password_field :current_password, autocomplete: "off", placeholder: 'Current password' + .actions + = f.button "Save changes", type: 'submit' diff --git a/app/views/auth/registrations/new.html.haml b/app/views/auth/registrations/new.html.haml new file mode 100644 index 000000000..c8532ec38 --- /dev/null +++ b/app/views/auth/registrations/new.html.haml @@ -0,0 +1,17 @@ += form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| + = devise_error_messages! + + = f.fields_for :account do |ff| + .field + = ff.text_field :username, autofocus: true, placeholder: 'Username', required: true + + .field + = f.email_field :email, placeholder: 'E-mail address', required: true + .field + = f.password_field :password, autocomplete: "off", placeholder: 'Password', required: true + .field + = f.password_field :password_confirmation, autocomplete: "off", placeholder: 'Confirm password', required: true + .actions + = f.button "Sign up", type: 'submit' + +.form-footer= render "auth/shared/links" diff --git a/app/views/auth/sessions/new.html.haml b/app/views/auth/sessions/new.html.haml new file mode 100644 index 000000000..220d0ec79 --- /dev/null +++ b/app/views/auth/sessions/new.html.haml @@ -0,0 +1,9 @@ += form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| + .field + = f.email_field :email, autofocus: true, placeholder: 'E-mail address', required: true + .field + = f.password_field :password, autocomplete: "off", placeholder: 'Password', required: true + .actions + = f.button "Log in", type: 'submit' + +.form-footer= render "auth/shared/links" diff --git a/app/views/auth/shared/_links.html.haml b/app/views/auth/shared/_links.html.haml new file mode 100644 index 000000000..6f89eed75 --- /dev/null +++ b/app/views/auth/shared/_links.html.haml @@ -0,0 +1,19 @@ +%ul.no-list + - if controller_name != 'sessions' + %li= link_to "Log in", new_session_path(resource_name) + + - if devise_mapping.registerable? && controller_name != 'registrations' + %li= link_to "Sign up", new_registration_path(resource_name) + + - if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' + %li= link_to "Forgot your password?", 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) + + - if devise_mapping.omniauthable? + - resource_class.omniauth_providers.each do |provider| + %li= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 862374a98..11894d72c 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1 +1,3 @@ Mastodon + += link_to 'Logout', destroy_user_session_path, method: :delete diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index f15217203..25b3b5b49 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -9,7 +9,4 @@ = yield :header_tags %body .container - = yield - .footer - Powered by - = link_to 'Mastodon', 'https://github.com/Gargron/mastodon', class: 'mastodon-link' + = content_for?(:content) ? yield(:content) : yield diff --git a/app/views/layouts/auth.html.haml b/app/views/layouts/auth.html.haml new file mode 100644 index 000000000..dd0e7f166 --- /dev/null +++ b/app/views/layouts/auth.html.haml @@ -0,0 +1,10 @@ +- content_for :content do + .logo-container + %h1 + Mastodon + %small= Rails.configuration.x.local_domain + + .form-container + = yield + += render template: "layouts/application" -- cgit