Skip to content

Commit 02fc58c

Browse files
authored
Merge pull request #97 from AlchemyCMS/admin-controllers
Move session controllers into admin module namespace
2 parents 81f084a + 11af94f commit 02fc58c

26 files changed

Lines changed: 145 additions & 140 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Alchemy
2+
module Admin
3+
class PasswordsController < ::Devise::PasswordsController
4+
include Alchemy::Admin::Locale
5+
6+
before_action { enforce_ssl if ssl_required? && !request.ssl? }
7+
8+
helper 'Alchemy::Admin::Base'
9+
10+
layout 'alchemy/admin'
11+
12+
private
13+
14+
# Override for Devise method
15+
def new_session_path(resource_name)
16+
alchemy.admin_login_path
17+
end
18+
19+
def admin_edit_password_url(resource, options={})
20+
alchemy.admin_edit_password_url(options)
21+
end
22+
23+
def after_resetting_password_path_for(resource)
24+
if can? :index, :alchemy_admin_dashboard
25+
alchemy.admin_dashboard_path
26+
else
27+
alchemy.root_path
28+
end
29+
end
30+
31+
end
32+
end
33+
end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module Alchemy
2+
module Admin
3+
class UserSessionsController < ::Devise::SessionsController
4+
include Alchemy::Admin::Locale
5+
6+
protect_from_forgery prepend: true
7+
8+
before_action except: 'destroy' do
9+
enforce_ssl if ssl_required? && !request.ssl?
10+
end
11+
12+
before_action :check_user_count, :only => :new
13+
14+
helper 'Alchemy::Admin::Base'
15+
16+
layout 'alchemy/admin'
17+
18+
def create
19+
authenticate_user!
20+
21+
if user_signed_in?
22+
if session[:redirect_path].blank?
23+
redirect_path = admin_dashboard_path
24+
else
25+
# We have to strip double slashes from beginning of path, because of strange rails/rack bug.
26+
redirect_path = session[:redirect_path].gsub(/\A\/{2,}/, '/')
27+
end
28+
redirect_to redirect_path,
29+
notice: t(:signed_in, scope: 'devise.sessions')
30+
else
31+
super
32+
end
33+
end
34+
35+
def destroy
36+
current_alchemy_user.try(:unlock_pages!)
37+
cookies.clear
38+
session.clear
39+
super
40+
end
41+
42+
private
43+
44+
def check_user_count
45+
if User.count == 0
46+
redirect_to admin_signup_path
47+
end
48+
end
49+
50+
# Overwriting the default of Devise
51+
def after_sign_out_path_for(resource_or_scope)
52+
if request.referer.blank? || request.referer.to_s =~ /admin/
53+
root_path
54+
else
55+
request.referer
56+
end
57+
end
58+
end
59+
end
60+
end

app/controllers/alchemy/passwords_controller.rb

Lines changed: 0 additions & 31 deletions
This file was deleted.

app/controllers/alchemy/user_sessions_controller.rb

Lines changed: 0 additions & 62 deletions
This file was deleted.

app/mailers/alchemy/notifications.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Notifications < ActionMailer::Base
55

66
def member_created(user)
77
@user = user
8-
@url = login_url
8+
99
mail(
1010
to: user.email,
1111
subject: Alchemy.t("Your user credentials")

app/views/alchemy/passwords/edit.html.erb renamed to app/views/alchemy/admin/passwords/edit.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
<%= devise_error_messages! %>
1111
</div>
1212
<% end %>
13-
<%= alchemy_form_for resource, as: resource_name, url: update_password_path, method: 'patch' do |f| %>
13+
<%= alchemy_form_for resource, as: resource_name, url: admin_update_password_path, method: 'patch' do |f| %>
1414
<%= f.hidden_field :reset_password_token %>
1515
<%= f.input :password, autofocus: true, label: Alchemy.t("New password") %>
1616
<%= f.input :password_confirmation, label: Alchemy.t("Confirm new password") %>
1717
<div class="input link">
1818
<small>
19-
<%= link_to Alchemy.t(:back), alchemy.login_path %>
19+
<%= link_to Alchemy.t(:back), alchemy.admin_login_path %>
2020
</small>
2121
</div>
2222
<%= f.submit Alchemy.t("Change password") %>

app/views/alchemy/passwords/new.html.erb renamed to app/views/alchemy/admin/passwords/new.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
<%= devise_error_messages! %>
1111
</div>
1212
<% end %>
13-
<%= alchemy_form_for :user, url: reset_password_path, html: {method: 'post'} do |f| %>
13+
<%= alchemy_form_for :user, url: admin_reset_password_path, html: {method: 'post'} do |f| %>
1414
<%= f.input :email,
1515
autofocus: true,
1616
input_html: {value: params[:email]} %>
1717
<div class="input link">
1818
<small>
19-
<%= link_to Alchemy.t(:back), alchemy.login_path %>
19+
<%= link_to Alchemy.t(:back), alchemy.admin_login_path %>
2020
</small>
2121
</div>
2222
<%= f.submit Alchemy.t("Send reset instructions"), input_html: {class: 'secondary'} %>

app/views/alchemy/user_sessions/new.html.erb renamed to app/views/alchemy/admin/user_sessions/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<%= f.input :password %>
66
<div class="input link">
77
<small>
8-
<%= link_to Alchemy.t('Forgot your password?'), new_password_path %>
8+
<%= link_to Alchemy.t('Forgot your password?'), admin_new_password_path %>
99
</small>
1010
</div>
1111
<div class="submit">

app/views/alchemy/notifications/alchemy_user_created.de.text.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Aus Sicherheitsgründen stellen wir Ihr Passwort hier nicht dar.
1010

1111
Wenn Sie Ihr Passwort vergessen haben oder dies Ihr erster Login ist, gehen Sie bitte auf:
1212

13-
<%= alchemy.new_password_url %>
13+
<%= alchemy.admin_new_password_url %>
1414

1515
Viel Spaß mit Alchemy!

app/views/alchemy/notifications/alchemy_user_created.en.text.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ For security reasons we do not show your password here.
1010

1111
If you forgot your password or this is your first login, please goto:
1212

13-
<%= alchemy.new_password_url %>
13+
<%= alchemy.admin_new_password_url %>
1414

1515
Have much fun with Alchemy!

0 commit comments

Comments
 (0)