Skip to content

Commit 9813b2a

Browse files
committed
Add frontend controllers and views
for user account management. Needs to be enabled via # config/initializers/alchemy.rb Alchemy::Devise.enable_user_accounts = true
1 parent dff0c4a commit 9813b2a

29 files changed

Lines changed: 846 additions & 61 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Alchemy
2+
class AccountsController < ::Devise::RegistrationsController
3+
helper 'Alchemy::Pages'
4+
5+
def show
6+
authorize! :show, current_alchemy_user
7+
@user = current_alchemy_user
8+
end
9+
10+
private
11+
12+
def permission_denied(*)
13+
store_location_for(:user, account_path)
14+
flash[:warning] = t(:unauthenticated, scope: 'devise.failure')
15+
redirect_to alchemy.login_path
16+
end
17+
end
18+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Alchemy
2+
class ConfirmationsController < ::Devise::ConfirmationsController
3+
helper 'Alchemy::Pages'
4+
5+
private
6+
7+
def new_session_path(*)
8+
alchemy.login_path
9+
end
10+
end
11+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Alchemy
2+
class PasswordsController < ::Devise::PasswordsController
3+
helper 'Alchemy::Pages'
4+
5+
private
6+
7+
def new_session_path(*)
8+
alchemy.login_path
9+
end
10+
end
11+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Alchemy
2+
class SessionsController < ::Devise::SessionsController
3+
helper 'Alchemy::Pages'
4+
5+
private
6+
7+
def after_sign_in_path_for(user)
8+
stored_location_for(user) || alchemy.account_path
9+
end
10+
end
11+
end

app/mailers/alchemy/notifications.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Alchemy
2-
class Notifications < ActionMailer::Base
2+
class Notifications < ::Devise::Mailer
33

44
default(from: Config.get(:mailer)['mail_from'])
55

@@ -21,6 +21,15 @@ def alchemy_user_created(user)
2121
)
2222
end
2323

24+
def member_reset_password_instructions(user, token, opts={})
25+
@user = user
26+
@token = token
27+
mail(
28+
to: user.email,
29+
subject: Alchemy.t("Reset password instructions")
30+
)
31+
end
32+
2433
def reset_password_instructions(user, token, opts={})
2534
@user = user
2635
@token = token
@@ -29,5 +38,14 @@ def reset_password_instructions(user, token, opts={})
2938
subject: Alchemy.t("Reset password instructions")
3039
)
3140
end
41+
42+
def confirmation_instructions(user, token, opts={})
43+
@user = user
44+
@token = token
45+
mail(
46+
to: user.email,
47+
subject: Alchemy.t("Account confirmation instructions")
48+
)
49+
end
3250
end
3351
end

app/models/alchemy/user.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ def deliver_welcome_mail
157157
end
158158
end
159159

160+
# Overwritten to send a different email to members
161+
def send_reset_password_instructions_notification(token)
162+
if has_role?('member')
163+
send_devise_notification(:member_reset_password_instructions, token, {})
164+
else
165+
send_devise_notification(:reset_password_instructions, token, {})
166+
end
167+
end
168+
160169
private
161170

162171
def logged_in_timeout
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h2>Hallo <%= @user.fullname %></h2>
2+
3+
<%= link_to 'Edit account', alchemy.edit_account_path %>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%- if controller_name != 'sessions' %>
2+
<%= link_to t('.login', default: 'Log in'), alchemy.login_path %><br />
3+
<% end %>
4+
5+
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6+
<%= link_to t('.sign_up', default: 'Sign up'), alchemy.new_account_path %><br />
7+
<% end %>
8+
9+
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
10+
<%= link_to t('.forgot_password', default: 'Forgot your password?'), alchemy.new_password_path %><br />
11+
<% end %>
12+
13+
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14+
<%= link_to t('.confirmation_instructions', default: "Didn't receive confirmation instructions?"), alchemy.new_confirmation_path %><br />
15+
<% end %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Willkommen <%= @user.fullname %>!
2+
3+
Bitte bestätigen Sie Ihre E-Mail-Adresse durch klicken auf folgenden Link:
4+
5+
<%= alchemy.confirmation_url(@user, confirmation_token: @token) %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Welcome <%= @user.fullname %>!
2+
3+
You can confirm your account email through the link below:
4+
5+
<%= alchemy.confirmation_url(@user, confirmation_token: @token) %>

0 commit comments

Comments
 (0)