Skip to content

Commit

Permalink
Forgot login
Browse files Browse the repository at this point in the history
  • Loading branch information
ariejan committed Feb 28, 2008
1 parent 24c49b2 commit 62f9a9d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
31 changes: 26 additions & 5 deletions app/controllers/users_controller.rb
@@ -1,30 +1,49 @@
class UsersController < ApplicationController
before_filter :find_user, :only => [:profile, :destroy, :edit_password, :update_password]

layout 'login', :only => [:troubleshooting, :forgot_password, :reset_password, :forgot_login, :clueless]
layout 'application', :only => [:edit_password]


# render new.rhtml
def new
end

def troubleshooting
# Render troubleshooting.html.erb
render :layout => 'login'
end

def forgot_login
if request.put?
begin
@user = User.find_by_email(params[:email])
rescue
@user = nil
end

if @user.nil?
flash.now[:error] = 'No account was found with that email address.'
else
UserMailer.deliver_forgot_login(@user)
end
else
# Render forgot_login.html.erb
end

render :layout => 'login'
end

def forgot_password
if request.put?
@user = User.find_by_login_or_email(params[:email_or_login])

if @user.nil?
flash.now[:error] = 'No user was found by that login or email address.'
flash.now[:error] = 'No account was found by that login or email address.'
else
@user.forgot_password if @user.active?
end
else
# Render forgot_password.html.erb
end

render :layout => 'login'
end

def reset_password
Expand All @@ -37,6 +56,8 @@ def reset_password
unless @user.nil? || !@user.active?
@user.reset_password!
end

render :layout => 'login'
end

def create
Expand Down
6 changes: 6 additions & 0 deletions app/models/user_mailer.rb
Expand Up @@ -18,6 +18,12 @@ def forgot_password(user)
@body[:url] = "http://base_app_url.host/users/reset_password/#{user.password_reset_code}"
end

def forgot_login(user)
setup_email(user)
@subject += "Forgotten account login"
@body[:url] = "http://base_app_url.host/login"
end

def activation(user)
setup_email(user)
@subject += 'Your account has been activated!'
Expand Down
13 changes: 13 additions & 0 deletions app/views/user_mailer/forgot_login.rhtml
@@ -0,0 +1,13 @@
Hello,

Your base_app account login is:

<%= @user.login %>

You may login by visiting the following link:

<%= @url %>

Best regards,

The base_app Team
22 changes: 22 additions & 0 deletions app/views/users/forgot_login.html.erb
@@ -0,0 +1,22 @@
<% content_for :header do -%>
Login Recovery
<% end -%>
<% unless @user.nil? %>
<p>An email containing your base_app account's login has been dispatched to you at <em><%= @user.email %></em>.</p>

<div id="submitbutton">
<p><%= link_to "Login now &raquo;", login_url %></p>
</div>
<% else %>
<p>Please enter the email address associated with your account. We will send you an email with your login shortly.</p>

<% form_tag user_forgot_login_url, :method => :put do %>
<p><label>Your email address</label><br />
<%= text_field_tag :email %></p>

<div id="submitbutton">
<p><%= submit_tag 'Send me my login &raquo;' %></p>
</div>
<% end %>
<% end %>

0 comments on commit 62f9a9d

Please sign in to comment.