scottmotte-merb_auth_slice_multisite 0.7.0 → 0.7.1

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/README.textile CHANGED
@@ -76,6 +76,14 @@ def get_site
76
76
  end
77
77
  </code></pre>
78
78
 
79
+ 8. Configure forgot_password functionality. Add the following into merb/merb-auth/setup.rb
80
+ <pre><code># To change the parameter names for the password or login field you may set either of these two options
81
+ #
82
+ # Merb::Plugins.config[:"merb-auth"][:login_param] = :email
83
+ # Merb::Plugins.config[:"merb-auth"][:password_param] = :my_password_field_name
84
+ Merb::Slices::config[:merb_auth_slice_multisite][:send_password_from_email] = "no-reply@yourapp.com"
85
+ Merb::Slices::config[:merb_auth_slice_multisite][:domain] = "example.com"</code></pre>
86
+
79
87
 
80
88
  h2. Additional details:
81
89
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 7
4
- :patch: 0
4
+ :patch: 1
@@ -1,25 +1,30 @@
1
1
  class MerbAuthSliceMultisite::Passwords < MerbAuthSliceMultisite::Application
2
-
3
- def forgot_password
4
- render
5
- end
6
2
 
7
3
  def send_password
8
4
  @login_param = Merb::Authentication::Strategies::Multisite::Base.login_param
9
5
  @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
6
  @user = Merb::Authentication.user_class.first(@login_param => params[@login_param], @site_id_param => params[@site_id_param])
12
7
 
13
8
  if @user
14
9
  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)
10
+ raise "No :send_password_from_email option set for Merb::Slices::config[:merb_auth_slice_multisite][:send_password_from_email]" unless from
11
+ @user.password = @user.password_confirmation = new_generated_password
12
+ send_mail(MerbAuthSliceMultisite::SendPasswordMailer, :send_password, { :subject => (MerbAuthSliceMultisite[:send_password_subject] || "Forgetful? :)"), :from => from, :to => @user.email }, { :user => @user })
13
+ @user.save
18
14
  redirect "/", :message => {:notice => "Password sent".t}
19
15
  else
20
16
  message[:error] = "User with #{@login_param} \"%s\" not found".t(params[@login_param].freeze)
21
17
  render :forgot_password
22
18
  end
23
19
  end
20
+
21
+ private
22
+
23
+ def new_generated_password
24
+ chars = ("a".."z").to_a
25
+ start_password = ""
26
+ 1.upto(6) { |i| start_password << chars[rand(chars.size-1)] }
27
+ @password = start_password
28
+ end
24
29
 
25
30
  end # MerbAuthSliceMultisite::Passwords
@@ -1,3 +1,3 @@
1
- Your password is <%= @user.password %>
1
+ Your new password is <%= @user.password %>
2
2
 
3
3
  Log on at http://<%= @user.site.subdomain %>.<%= Merb::Slices::config[:merb_auth_slice_multisite][:domain] %>
@@ -1,7 +1,6 @@
1
- <h3>Login</h3>
2
-
3
- <div>
4
-
1
+ <div id="login">
2
+ <h3>Login</h3>
3
+
5
4
  <%= error_messages_for session.authentication %>
6
5
  <% @login_param = Merb::Authentication::Strategies::Multisite::Base.login_param %>
7
6
  <% @password_param = Merb::Authentication::Strategies::Multisite::Base.password_param %>
@@ -13,9 +12,9 @@
13
12
  @current_site = Site.first(:subdomain => request.first_subdomain)
14
13
  %>
15
14
 
16
- <form action="<%= slice_url(:merb_auth_slice_multisite, :perform_login) %>" method="POST" accept-charset="utf-8">
15
+ <form action="<%= slice_url(:merb_auth_slice_multisite, :perform_login) %>" method="POST" accept-charset="utf-8" id="login_form">
17
16
  <input type="hidden" name="<%= @site_id_param.to_s %>" value="<%= @current_site.id %>" id="<%= @site_id_param.to_s %>">
18
- <input type="hidden" name="_method" value="PUT" />
17
+ <input type="hidden" name="_method" value="PUT" />
19
18
  <div class="formRow">
20
19
  <label><%= @login_param.to_s.capitalize %>: <input type="text" name="<%= @login_param.to_s %>" value="" id="<%= @login_param.to_s %>"></label>
21
20
  </div> <!-- close: formRow -->
@@ -29,4 +28,16 @@
29
28
  <a href="/forgot_password">Forgot password</a>
30
29
  </div> <!-- close: formRow -->
31
30
  </form>
31
+ </div>
32
+
33
+ <div id="forgot_password">
34
+ <form action="/send_password" method="post" accept-charset="utf-8" id="send_password_form">
35
+ <input type="hidden" name="<%= @site_id_param.to_s %>" value="<%= @current_site.id %>" id="<%= @site_id_param.to_s %>">
36
+ <div class="formRow">
37
+ <label for="<%= @login_param.to_s %>"><%= @login_param.to_s.capitalize %>: <input type="text" class="text" name="<%= @login_param.to_s %>" id="<%= @login_param.to_s %>" /></label>
38
+ </div> <!-- close: formRow -->
39
+ <div class="formRow">
40
+ <input type="submit" name="Reset" value="Reset password" id="Reset" />
41
+ </div> <!-- close: formRow -->
42
+ </form>
32
43
  </div>
@@ -87,12 +87,10 @@ if defined?(Merb::Plugins)
87
87
  # @note prefix your named routes with :merb_auth_slice_multisite_
88
88
  # to avoid potential conflicts with global named routes.
89
89
  def self.setup_router(scope)
90
- # example of a named route
90
+ scope.match("/send_password", :method => :post).to(:controller => "passwords", :action => "send_password").name(:send_password)
91
91
  scope.match("/login", :method => :get ).to(:controller => "/exceptions", :action => "unauthenticated").name(:login)
92
92
  scope.match("/login", :method => :put ).to(:controller => "sessions", :action => "update").name(:perform_login)
93
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)
96
94
  end
97
95
 
98
96
  end
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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - scottmotte
@@ -63,8 +63,6 @@ files:
63
63
  - app/views/exceptions/unauthenticated.html.erb
64
64
  - app/views/layout
65
65
  - app/views/layout/merb_auth_slice_multisite.html.erb
66
- - app/views/passwords
67
- - app/views/passwords/forgot_password.html.erb
68
66
  - config/database.yml
69
67
  - config/dependencies.rb
70
68
  - config/init.rb
@@ -1,18 +0,0 @@
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>