Permalink
Browse files

addding a bunch of changes

  • Loading branch information...
1 parent 672f375 commit b6f26beea8cc24c505149be6e3c01a2b4d178f71 Christian Sanz committed Nov 29, 2010
View
@@ -20,6 +20,7 @@ gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => '
# Add support for sqlite3 for dev and test DBs
gem 'sqlite3-ruby', :require => 'sqlite3'
+gem 'ruby-debug'
group :development do
# Add additional generators for Rails in the development environment
View
@@ -0,0 +1,113 @@
+GIT
+ remote: git://github.com/odorcicd/authlogic.git
+ revision: a087ad0cba3c165ba22fcf176c28b6f7517931e8
+ branch: rails3
+ specs:
+ authlogic (2.1.3)
+ activesupport
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ mail (~> 2.2.3)
+ actionpack (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.5)
+ i18n (~> 0.4.1)
+ rack (~> 1.1.0)
+ rack-mount (~> 0.6.3)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.16)
+ activemodel (3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ arel (~> 0.4.0)
+ tzinfo (~> 0.3.16)
+ activeresource (3.0.0.beta4)
+ activemodel (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ activesupport (3.0.0.beta4)
+ arel (0.4.0)
+ activesupport (>= 3.0.0.beta)
+ builder (2.1.2)
+ columnize (0.3.1)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ factory_girl (1.3.2)
+ factory_girl_rails (1.0)
+ factory_girl (~> 1.3)
+ rails (>= 3.0.0.beta4)
+ haml (3.0.21)
+ i18n (0.4.1)
+ linecache (0.43)
+ mail (2.2.7)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ polyglot (0.3.1)
+ rack (1.1.0)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rails (3.0.0.beta4)
+ actionmailer (= 3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activerecord (= 3.0.0.beta4)
+ activeresource (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ bundler (>= 0.9.26)
+ railties (= 3.0.0.beta4)
+ rails3-generators (0.14.0)
+ railties (3.0.0.beta4)
+ actionpack (= 3.0.0.beta4)
+ activesupport (= 3.0.0.beta4)
+ rake (>= 0.8.3)
+ thor (~> 0.13.6)
+ rake (0.8.7)
+ rspec (2.0.0.rc)
+ rspec-core (= 2.0.0.rc)
+ rspec-expectations (= 2.0.0.rc)
+ rspec-mocks (= 2.0.0.rc)
+ rspec-core (2.0.0.rc)
+ rspec-expectations (2.0.0.rc)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.rc)
+ rspec-core (= 2.0.0.rc)
+ rspec-expectations (= 2.0.0.rc)
+ rspec-rails (2.0.0.rc)
+ rspec (= 2.0.0.rc)
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
+ sqlite3-ruby (1.3.1)
+ thor (0.13.8)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ authlogic!
+ factory_girl_rails
+ haml
+ rails (= 3.0.0.beta4)
+ rails3-generators
+ rspec-rails (>= 2.0.0.beta.13)
+ ruby-debug
+ sqlite3-ruby
@@ -1,7 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery
layout 'application'
-
helper_method :current_user_session, :current_user
private
@@ -14,7 +13,6 @@ def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
-
def require_user
unless current_user
store_location
@@ -23,7 +21,6 @@ def require_user
return false
end
end
-
def require_no_user
if current_user
store_location
@@ -32,11 +29,9 @@ def require_no_user
return false
end
end
-
def store_location
session[:return_to] = request.fullpath
end
-
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
@@ -0,0 +1,58 @@
+class PasswordResetsController < ApplicationController
+ before_filter :load_user_using_perishable_token, :only => [:edit, :update]
+ before_filter :require_no_user
+
+ def index
+ render :action => :new
+ end
+ def new
+ @user = User.new
+ end
+ def create
+ @user = User.find_by_email(params[:email])
+ if @user
+ @user.deliver_password_reset_instructions!
+ flash[:notice] = "Instructions to reset your password have been emailed to you. " +
+ "Please check your email."
+ redirect_to root_url
+ else
+ @user = User.new if !@user
+ @user.errors.add(:email, "missing") if params[:email].blank?
+ @user.errors.add(:email, "doesn't exist") if !User.find_by_email(params[:email])
+ render :action => :new
+ end
+ end
+ def edit
+ render
+ end
+ def update
+ @user.errors.add(:password, "missing") if params[:user][:password].blank?
+ @user.errors.add(:password_confirmation, "missing") if params[:user][:password_confirmation].blank?
+ if !@user.errors.any?
+ @user.password = params[:user][:password]
+ @user.password_confirmation = params[:user][:password_confirmation]
+ @user.save
+ if !@user.verified then
+ @user.verify!
+ flash[:notice] = "Password successfully updated and we also went ahead and verified your account"
+ else
+ flash[:notice] = "Password successfully updated"
+ end
+ redirect_to users_path, :format => params[:format]
+ else
+ render :action => :edit
+ end
+
+ end
+ private
+ def load_user_using_perishable_token
+ @user = User.find_by_perishable_token(params[:id])
+ unless @user
+ flash[:notice] = "we're sorry, but we could not locate your account." +
+ "if you are having issues try copying and pasting the URL " +
+ "from your email into your browser or restarting the " +
+ "reset password process."
+ redirect_to root_url
+ end
+ end
+end
@@ -2,19 +2,13 @@ class UserSessionController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => :destroy
- # GET /login
- # GET /login.xml
def new
@user_session = UserSession.new
-
respond_to do |format|
format.html # new.html.haml
format.xml { render :xml => @user_session }
end
end
-
- # POST /login
- # POST /login.xml
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
@@ -24,9 +18,6 @@ def create
render :action => 'new', :format => params[:format]
end
end
-
- # DELETE /logout
- # DELETE /logout.xml
def destroy
@user_session = UserSession.find
@user_session.destroy
@@ -0,0 +1,18 @@
+class UserVerificationsController < ApplicationController
+ before_filter :load_user_using_perishable_token
+
+ def index
+ if @user
+ @user.verify!
+ flash[:notice] = "Thank you for verifying your account. You may now login."
+ else
+ flash[:warning] = "Sorry, your code is invalid or it has already been verified"
+ end
+ redirect_to '/login'
+ end
+private
+ def load_user_using_perishable_token
+ @user = User.find_using_perishable_token(params[:id])
+ flash[:notice] = "Unable to find your account." unless @user
+ end
+end
@@ -1,82 +1,58 @@
class UsersController < ApplicationController
before_filter :require_user, :except => [:new, :create]
- # GET /users
- # GET /users.xml
def index
@users = User.all
-
respond_to do |format|
format.html # index.html.haml
format.xml { render :xml => @users }
end
end
-
- # GET /users/1
- # GET /users/1.xml
def show
@user = User.find(params[:id])
-
respond_to do |format|
format.html # show.html.haml
format.xml { render :xml => @user }
end
end
-
- # GET /users/new
- # GET /users/new.xml
def new
@user = User.new
-
respond_to do |format|
format.html # new.html.haml
format.xml { render :xml => @user }
end
end
-
- # GET /users/1/edit
def edit
@user = User.find(params[:id])
end
-
- # POST /users
- # POST /users.xml
def create
@user = User.new(params[:user])
-
respond_to do |format|
if @user.save
- format.html { redirect_to(@user, :notice => 'User was successfully created.') }
+ @user.deliver_verification_instructions!
+ format.html { redirect_to(root_url, :notice => 'thanks for signing up, we\'ve delivered an email to you with instructions on how to complete your registration!') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
-
- # PUT /users/1
- # PUT /users/1.xml
def update
@user = User.find(params[:id])
-
respond_to do |format|
if @user.update_attributes(params[:user])
- format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
+ format.html { redirect_to(@user, :notice => 'user was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
-
- # DELETE /users/1
- # DELETE /users/1.xml
def destroy
@user = User.find(params[:id])
@user.destroy
-
respond_to do |format|
format.html { redirect_to(users_url) }
format.xml { head :ok }
View
@@ -0,0 +1,20 @@
+class Notifier < ActionMailer::Base
+ default_url_options[:host] = "#{APP_CONFIG[:domain]}"
+
+ def password_reset_instructions(user)
+ subject "[#{APP_CONFIG[:domain]}] password reset instructions"
+ from "#{APP_CONFIG[:domain]} <noreply@#{APP_CONFIG[:domain]}>"
+ recipients user.email
+ sent_on Time.now
+ body :user => user
+ end
+
+ def verification_instructions(user)
+ subject "[#{APP_CONFIG[:domain]}] email verification"
+ from "#{APP_CONFIG[:domain]} <noreply@#{APP_CONFIG[:domain]}>"
+ recipients user.email
+ sent_on Time.now
+ body :user => user
+ end
+
+end
View
@@ -6,4 +6,17 @@ class User < ActiveRecord::Base
c.login_field = :email # email is the login field
c. validate_login_field = false # There is no login field, so don't validate it
end
+
+ def deliver_password_reset_instructions!
+ reset_perishable_token!
+ Notifier.deliver_password_reset_instructions(self)
+ end
+ def deliver_verification_instructions!
+ reset_perishable_token!
+ Notifier.deliver_verification_instructions(self)
+ end
+ def verify!
+ self.verified = true
+ self.save
+ end
end
Oops, something went wrong.

0 comments on commit b6f26be

Please sign in to comment.