-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for user account management. Needs to be enabled via # config/initializers/alchemy.rb Alchemy::Devise.enable_user_accounts = true
- Loading branch information
Showing
28 changed files
with
808 additions
and
61 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Alchemy | ||
class AccountsController < ::Devise::RegistrationsController | ||
helper 'Alchemy::Pages' | ||
|
||
def show | ||
authorize! :show, current_alchemy_user | ||
@user = current_alchemy_user | ||
end | ||
|
||
private | ||
|
||
def permission_denied(*) | ||
store_location_for(:user, account_path) | ||
flash[:warning] = t(:unauthenticated, scope: 'devise.failure') | ||
redirect_to alchemy.login_path | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Alchemy | ||
class ConfirmationsController < ::Devise::ConfirmationsController | ||
helper 'Alchemy::Pages' | ||
|
||
private | ||
|
||
def new_session_path(*) | ||
alchemy.login_path | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Alchemy | ||
class PasswordsController < ::Devise::PasswordsController | ||
helper 'Alchemy::Pages' | ||
|
||
private | ||
|
||
def new_session_path(*) | ||
alchemy.login_path | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Alchemy | ||
class SessionsController < ::Devise::SessionsController | ||
helper 'Alchemy::Pages' | ||
|
||
private | ||
|
||
def after_sign_in_path_for(user) | ||
stored_location_for(user) || alchemy.account_path | ||
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h2>Hallo <%= @user.fullname %></h2> | ||
|
||
<%= link_to 'Edit account', alchemy.edit_account_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<%- if controller_name != 'sessions' %> | ||
<%= link_to t('.login', default: 'Log in'), alchemy.login_path %><br /> | ||
<% end %> | ||
<%- if devise_mapping.registerable? && controller_name != 'registrations' %> | ||
<%= link_to t('.sign_up', default: 'Sign up'), alchemy.new_account_path %><br /> | ||
<% end %> | ||
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> | ||
<%= link_to t('.forgot_password', default: 'Forgot your password?'), alchemy.new_password_path %><br /> | ||
<% end %> | ||
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> | ||
<%= link_to t('.confirmation_instructions', default: "Didn't receive confirmation instructions?"), alchemy.new_confirmation_path %><br /> | ||
<% end %> |
5 changes: 5 additions & 0 deletions
5
app/views/alchemy/notifications/confirmation_instructions.en.html.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p>Welcome <%= @user.fullname %>!</p> | ||
|
||
<p>You can confirm your account email through the link below:</p> | ||
|
||
<p><%= link_to 'Confirm my account', alchemy.confirmation_url(@user, confirmation_token: @token) %></p> |
5 changes: 5 additions & 0 deletions
5
app/views/alchemy/notifications/confirmation_instructions.en.text.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Welcome <%= @user.fullname %>! | ||
|
||
You can confirm your account email through the link below: | ||
|
||
<%= alchemy.confirmation_url(@user, confirmation_token: @token) %> |
8 changes: 8 additions & 0 deletions
8
app/views/alchemy/notifications/member_reset_password_instructions.de.text.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Hallo <%= @user.fullname %>. | ||
|
||
Sie haben angefordert Ihr Passwort zurückzusetzen. Dies kann durch anklicken des nachfolgenden Links bestätigt werden. | ||
|
||
<%= alchemy.edit_password_url(@user, reset_password_token: @token) %> | ||
|
||
Wenn Sie diese Zurücksetzung nicht angefragt haben, dann können Sie diese E-Mail einfach ignorieren. | ||
Ihr Passwort wird erst dann zurückgesetzt, wenn Sie den Link anklicken. |
8 changes: 8 additions & 0 deletions
8
app/views/alchemy/notifications/member_reset_password_instructions.en.text.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Hello <%= @user.name %>. | ||
|
||
You have requested to change your password. Please confirm this by clicking the link below. | ||
|
||
<%= alchemy.edit_password_url(@user, 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. |
8 changes: 8 additions & 0 deletions
8
app/views/alchemy/notifications/member_reset_password_instructions.es.text.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Hola <%= @user.name %>. | ||
|
||
Has solicitado modificar tu contraseña. Por favor, confírmalo pulsando en el siguiente enlace. | ||
|
||
<%= alchemy.edit_password_url(@user, reset_password_token: @token) %> | ||
|
||
Si no has sido tu el que ha hecho la solicitud, ignora este correo. | ||
Tu contraseña no cambiará hasta que no accedas al enlace de arriba y generes una nueva. |
8 changes: 8 additions & 0 deletions
8
app/views/alchemy/notifications/member_reset_password_instructions.ru.text.erb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Здравствуйте, <%= @user.name %>. | ||
|
||
Вы сделали запрос на смену пароля. Пожалуйста подтвердите это, нажав на ссылку ниже. | ||
|
||
<%= alchemy.edit_password_url(@user, reset_password_token: @token) %> | ||
|
||
Если вы не делали запрос, просто проигнорируйте это письмо. | ||
Ваш пароль не изменится до тех пор, пока вы не перейдете по ссылке и сами не измените его. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<h2><%= t('.title', default: 'Change your password') %></h2> | ||
|
||
<%= simple_form_for(@user, as: :user, url: alchemy.password_path, html: { method: :put }) do |f| %> | ||
<%= f.error_notification %> | ||
<%= f.input :reset_password_token, as: :hidden %> | ||
<%= f.full_error :reset_password_token %> | ||
|
||
<div class="form-inputs"> | ||
<%= f.input :password, | ||
label: t('.password.label', default: 'New password'), | ||
required: true, | ||
autofocus: true, | ||
hint: t('.hint', default: '%{minimum} characters minimum', minimum: @minimum_password_length) if @minimum_password_length, | ||
input_html: { autocomplete: "new-password" } %> | ||
<%= f.input :password_confirmation, | ||
label: t('.password_confirmation.label', default: 'Confirm your new password'), | ||
required: true, | ||
input_html: { autocomplete: "new-password" } %> | ||
</div> | ||
|
||
<div class="form-actions"> | ||
<%= f.button :submit, t('.button.label', default: 'Change my password') %> | ||
</div> | ||
<% end %> | ||
<%= render "alchemy/devise/shared/links" %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<h2><%= t('.title', default: 'Forgot your password?') %></h2> | ||
|
||
<%= simple_form_for(@user, as: :user, url: alchemy.password_path, html: { method: :post }) do |f| %> | ||
<%= f.error_notification %> | ||
|
||
<div class="form-inputs"> | ||
<%= f.input :email, | ||
required: true, | ||
autofocus: true, | ||
input_html: { autocomplete: "email" } %> | ||
</div> | ||
|
||
<div class="form-actions"> | ||
<%= f.button :submit, t('.button.label', default: 'Send me reset password instructions') %> | ||
</div> | ||
<% end %> | ||
<%= render "alchemy/devise/shared/links" %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<h2><%= t('.title', default: 'Log in') %></h2> | ||
|
||
<% if flash[:alert] %> | ||
<div class="alert alert-danger"> | ||
<%= flash[:alert] %> | ||
</div> | ||
<% end %> | ||
<% if flash[:notice] %> | ||
<div class="alert alert-info"> | ||
<%= flash[:notice] %> | ||
</div> | ||
<% end %> | ||
<%= simple_form_for(@user, as: :user, url: alchemy.login_path) do |f| %> | ||
<div class="form-inputs"> | ||
<%= f.input :email, | ||
required: false, | ||
autofocus: true, | ||
input_html: { autocomplete: "email" } %> | ||
<%= f.input :password, | ||
required: false, | ||
input_html: { autocomplete: "current-password" } %> | ||
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %> | ||
</div> | ||
|
||
<div class="form-actions"> | ||
<%= f.button :submit, t('.button.label', default: 'Log in') %> | ||
</div> | ||
<% end %> | ||
<%= render "alchemy/devise/shared/links" %> |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'rails_helper' | ||
|
||
describe Alchemy::AccountsController do | ||
routes { Alchemy::Engine.routes } | ||
|
||
context 'with user accounts enabled' do | ||
before do | ||
allow(Alchemy::Devise).to receive(:enable_user_accounts?) { true } | ||
Rails.application.reload_routes! | ||
@request.env["devise.mapping"] = Devise.mappings[:user] | ||
end | ||
|
||
describe '#show' do | ||
let(:user) { create(:alchemy_member_user) } | ||
|
||
context 'with authorized user' do | ||
before { authorize_user(user) } | ||
|
||
render_views | ||
|
||
it 'shows account' do | ||
get :show | ||
is_expected.to render_template(:show) | ||
end | ||
end | ||
|
||
context 'with unauthorized user' do | ||
it 'redirects to login' do | ||
get :show | ||
is_expected.to redirect_to(login_path) | ||
end | ||
|
||
it 'stores current location' do | ||
get :show | ||
expect(session[:user_return_to]).to eq(account_path) | ||
end | ||
|
||
it 'shows warning message' do | ||
get :show | ||
expect(flash[:warning]).to eq I18n.t(:unauthenticated, scope: 'devise.failure') | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.