scottmotte-merb_auth_slice_multisite 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +2 -2
- data/app/controllers/passwords.rb +25 -0
- data/app/mailers/send_password_mailer.rb +11 -0
- data/app/mailers/views/send_password_mailer/send_password.text.erb +3 -0
- data/app/views/exceptions/unauthenticated.html.erb +3 -0
- data/app/views/passwords/forgot_password.html.erb +18 -0
- data/config/init.rb +8 -1
- data/lib/merb_auth_slice_multisite.rb +6 -3
- data/spec/mailers/send_password_mailer_spec.rb +47 -0
- data/spec/spec_helper.rb +4 -0
- metadata +12 -3
- data/spec/merb_auth_slice_multisite_spec.rb +0 -20
data/VERSION.yml
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
class MerbAuthSliceMultisite::Passwords < MerbAuthSliceMultisite::Application
|
2
|
+
|
3
|
+
def forgot_password
|
4
|
+
render
|
5
|
+
end
|
6
|
+
|
7
|
+
def send_password
|
8
|
+
@login_param = Merb::Authentication::Strategies::Multisite::Base.login_param
|
9
|
+
@site_id_param = Merb::Authentication::Strategies::Multisite::Base.site_id_param
|
10
|
+
@user = Merb::Authentication.user_class.find_with_login_param(@login_param, params[@login_param])
|
11
|
+
@user = Merb::Authentication.user_class.first(@login_param => params[@login_param], @site_id_param => params[@site_id_param])
|
12
|
+
|
13
|
+
if @user
|
14
|
+
from = MerbAuthSliceMultisite[:send_password_from_email]
|
15
|
+
raise "No :send_password_from_email option set for Merb::Slices::config[:merb_auth_slice_multisite][:send_password_from_email]" unless from
|
16
|
+
send_mail(MerbAuthSliceMultisite::SendPasswordMailer, :send_password, { :subject => (MerbAuthSliceMultisite[:send_password_subject] || "Your password"), :from => from, :to => @user.email }, { :user => @user })
|
17
|
+
# MerbAuthSliceMultisite::SendPasswordMailer.dispatch_and_deliver(:send_password, :subject => (MerbAuthSliceMultisite[:send_password_subject] || "Your password"), :from => from, :to => @user.email), :user => @user)
|
18
|
+
redirect "/", :message => {:notice => "Password sent".t}
|
19
|
+
else
|
20
|
+
message[:error] = "User with #{@login_param} \"%s\" not found".t(params[@login_param].freeze)
|
21
|
+
render :forgot_password
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end # MerbAuthSliceMultisite::Passwords
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class MerbAuthSliceMultisite::SendPasswordMailer < Merb::MailController
|
2
|
+
|
3
|
+
controller_for_slice MerbAuthSliceMultisite, :templates_for => :mailer, :path => "views"
|
4
|
+
|
5
|
+
def send_password
|
6
|
+
@user = params[:user]
|
7
|
+
Merb.logger.info "Sending Password to #{@user.email}"
|
8
|
+
render_mail :layout => nil
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -24,6 +24,9 @@
|
|
24
24
|
</div> <!-- close: formRow -->
|
25
25
|
<div class="formRow">
|
26
26
|
<input type="submit" name="Submit" value="Log In" id="Submit">
|
27
|
+
</div> <!-- close: formRow -->
|
28
|
+
<div class="formRow">
|
29
|
+
<a href="/forgot_password">Forgot password</a>
|
27
30
|
</div> <!-- close: formRow -->
|
28
31
|
</form>
|
29
32
|
</div>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% @login_param = Merb::Authentication::Strategies::Multisite::Base.login_param %>
|
2
|
+
<% @site_id_param = Merb::Authentication::Strategies::Multisite::Base.site_id_param %>
|
3
|
+
<%
|
4
|
+
# make @current_site value. application.rb does not get call
|
5
|
+
# because the authentication is protected at the rack level - which is better,
|
6
|
+
# but it means I have to add the following duplicate line of code as far as I know.
|
7
|
+
@current_site = Site.first(:subdomain => request.first_subdomain)
|
8
|
+
%>
|
9
|
+
|
10
|
+
<form action="" method="post">
|
11
|
+
<input type="hidden" name="<%= @site_id_param.to_s %>" value="<%= @current_site.id %>" id="<%= @site_id_param.to_s %>">
|
12
|
+
<input type="hidden" name="_method" value="PUT" />
|
13
|
+
<p>
|
14
|
+
<label for="<%= @login_param.to_s %>"><%= @login_param.to_s.capitalize.t %></label>
|
15
|
+
<input type="text" class="text" name="<%= @login_param.to_s %>" id="<%= @login_param.to_s %>" />
|
16
|
+
</p>
|
17
|
+
<input type="submit" value="Reset password" />
|
18
|
+
</form>
|
data/config/init.rb
CHANGED
@@ -27,7 +27,11 @@ use_orm :datamapper
|
|
27
27
|
use_test :rspec
|
28
28
|
use_template_engine :erb
|
29
29
|
|
30
|
-
#
|
30
|
+
# Setup the required configuration for the slice
|
31
|
+
Merb::Slices::config[:merb_auth_slice_multisite][:send_password_from_email] = "no-reply@yourapp.com"
|
32
|
+
Merb::Slices::config[:merb_auth_slice_multisite][:domain] = "example.com"
|
33
|
+
|
34
|
+
|
31
35
|
Merb::BootLoader.before_app_loads do
|
32
36
|
DataMapper.setup(:default, "sqlite3::memory:")
|
33
37
|
|
@@ -38,6 +42,9 @@ Merb::BootLoader.before_app_loads do
|
|
38
42
|
property :id, Serial
|
39
43
|
property :email, String
|
40
44
|
property :login, String
|
45
|
+
property :password, String
|
46
|
+
|
47
|
+
belongs_to :site
|
41
48
|
end
|
42
49
|
|
43
50
|
class Merb::Authentication
|
@@ -2,6 +2,7 @@ if defined?(Merb::Plugins)
|
|
2
2
|
|
3
3
|
$:.unshift File.dirname(__FILE__)
|
4
4
|
|
5
|
+
dependency 'merb-mailer'
|
5
6
|
dependency 'merb-slices', :immediate => true
|
6
7
|
dependency 'merb-auth-core'
|
7
8
|
dependency 'merb-auth-more'
|
@@ -87,9 +88,11 @@ if defined?(Merb::Plugins)
|
|
87
88
|
# to avoid potential conflicts with global named routes.
|
88
89
|
def self.setup_router(scope)
|
89
90
|
# example of a named route
|
90
|
-
scope.match("/login", :method => :get ).to(:controller => "/exceptions",
|
91
|
-
scope.match("/login", :method => :put ).to(:controller => "sessions",
|
92
|
-
scope.match("/logout"
|
91
|
+
scope.match("/login", :method => :get ).to(:controller => "/exceptions", :action => "unauthenticated").name(:login)
|
92
|
+
scope.match("/login", :method => :put ).to(:controller => "sessions", :action => "update").name(:perform_login)
|
93
|
+
scope.match("/logout").to(:controller => "sessions", :action => "destroy").name(:logout)
|
94
|
+
scope.match("/forgot_password", :method => :get).to(:controller => "passwords", :action => "forgot_password").name(:forgot_password)
|
95
|
+
scope.match("/forgot_password", :method => :post).to(:controller => "passwords", :action => "send_password").name(:send_password)
|
93
96
|
end
|
94
97
|
|
95
98
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "SendPasswordMailer" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Merb::Router.prepare { add_slice(:merb_auth_slice_password_reset)}
|
7
|
+
User.auto_migrate!
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
Merb::Router.reset!
|
12
|
+
end
|
13
|
+
|
14
|
+
describe MerbAuthSliceMultisite::SendPasswordMailer do
|
15
|
+
|
16
|
+
def deliver(action, mail_opts= {},opts = {})
|
17
|
+
MerbAuthSliceMultisite::SendPasswordMailer.dispatch_and_deliver action, mail_opts, opts
|
18
|
+
@last_delivered_mail = Merb::Mailer.deliveries.last
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
Merb::Mailer.deliveries.clear
|
23
|
+
Site.all.destroy!
|
24
|
+
User.all.destroy!
|
25
|
+
@site = Site.create(valid_site_attributes)
|
26
|
+
@user = @site.users.build(:email => "homer@simpsons.com", :login => "homer", :password => "donuts" )
|
27
|
+
@mailer_params = { :from => "info@mysite.com", :to => @user.email, :subject => "Welcome to MySite.com" }
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should send mail to homer@simpsons.com for the send password email" do
|
31
|
+
deliver(:send_password, @mailer_params, :user => @user)
|
32
|
+
@last_delivered_mail.assigns(:headers).should include("to: homer@simpsons.com")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should send the mail from 'info@mysite.com' for the the send password email" do
|
36
|
+
deliver(:send_password, @mailer_params, :user => @user)
|
37
|
+
@last_delivered_mail.assigns(:headers).should include("from: info@mysite.com")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have the link to the subdomain site" do
|
41
|
+
deliver(:send_password, @mailer_params, :user => @user)
|
42
|
+
@last_delivered_mail.text.should include("http://#{@user.site.subdomain}.#{Merb::Slices::config[:merb_auth_slice_multisite][:domain] = "example.com"}")
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scottmotte-merb_auth_slice_multisite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- scottmotte
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -37,7 +37,8 @@ files:
|
|
37
37
|
- lib/merb_auth_slice_multisite/slicetasks.rb
|
38
38
|
- lib/merb_auth_slice_multisite/spectasks.rb
|
39
39
|
- lib/merb_auth_slice_multisite.rb
|
40
|
-
- spec/
|
40
|
+
- spec/mailers
|
41
|
+
- spec/mailers/send_password_mailer_spec.rb
|
41
42
|
- spec/mixins
|
42
43
|
- spec/mixins/user_belongs_to_site_spec.rb
|
43
44
|
- spec/models
|
@@ -46,9 +47,15 @@ files:
|
|
46
47
|
- app/controllers
|
47
48
|
- app/controllers/application.rb
|
48
49
|
- app/controllers/exceptions.rb
|
50
|
+
- app/controllers/passwords.rb
|
49
51
|
- app/controllers/sessions.rb
|
50
52
|
- app/helpers
|
51
53
|
- app/helpers/application_helper.rb
|
54
|
+
- app/mailers
|
55
|
+
- app/mailers/send_password_mailer.rb
|
56
|
+
- app/mailers/views
|
57
|
+
- app/mailers/views/send_password_mailer
|
58
|
+
- app/mailers/views/send_password_mailer/send_password.text.erb
|
52
59
|
- app/models
|
53
60
|
- app/models/site.rb
|
54
61
|
- app/views
|
@@ -56,6 +63,8 @@ files:
|
|
56
63
|
- app/views/exceptions/unauthenticated.html.erb
|
57
64
|
- app/views/layout
|
58
65
|
- app/views/layout/merb_auth_slice_multisite.html.erb
|
66
|
+
- app/views/passwords
|
67
|
+
- app/views/passwords/forgot_password.html.erb
|
59
68
|
- config/database.yml
|
60
69
|
- config/dependencies.rb
|
61
70
|
- config/init.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe "MerbAuthSliceMultisite (module)" do
|
4
|
-
|
5
|
-
# Implement your MerbAuthSliceMultisite specs here
|
6
|
-
|
7
|
-
# To spec MerbAuthSliceMultisite you need to hook it up to the router like this:
|
8
|
-
|
9
|
-
# before :all do
|
10
|
-
# Merb::Router.prepare { add_slice(:MerbAuthSliceMultisite) } if standalone?
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# after :all do
|
14
|
-
# Merb::Router.reset! if standalone?
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# it "should have proper specs"
|
19
|
-
|
20
|
-
end
|