Skip to content

Instantly share code, notes, and snippets.

@ppworks
Created January 7, 2012 13:33
Show Gist options
  • Save ppworks/1574754 to your computer and use it in GitHub Desktop.
Save ppworks/1574754 to your computer and use it in GitHub Desktop.
How to allow user to signup providing email address only(updated)
--- a/app/controllers/confirmations_controller.rb
+++ b/app/controllers/confirmations_controller.rb
@@ -1,20 +1,19 @@
class ConfirmationsController < Devise::ConfirmationsController
def show
@user = User.find_by_confirmation_token(params[:confirmation_token])
- if !@user.present?
- render_with_scope :new
- end
+ head :not_found unless @user.present?
end
def confirm_user
- @user = User.find(params[:user][:confirmation_token])
- if @user.update_attributes(params[:user]) and @user.password_match?
+ return head :not_found unless params[:user][:confirmation_token].present?
+ @user = User.find_by_confirmation_token(params[:user][:confirmation_token])
+ return head :not_found unless @user.present?
+ if @user.update_attributes(params[:user])
@user = User.confirm_by_token(@user.confirmation_token)
set_flash_message :notice, :confirmed
sign_in_and_redirect("user", @user)
else
render :action => "show"
end
end
-
end
--- a/config/initializers/extentions/devise.rb
+++ b/config/initializers/extentions/devise.rb
@@ -1,11 +1,12 @@
module Devise
module Models
module Validatable
-
def password_required?
- false
+ return false unless persisted?
+ return true if respond_to?(:confirmed?) && !confirmed?
+ return true if password.present? || password_confirmation.present?
+ return false
end
-
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -10,10 +10,4 @@ class User < ActiveRecord::Base
-
- def password_match?
- self.errors[:password] << 'password not match' if password != password_confirmation
- self.errors[:password] << 'you must provide a password' if password.blank?
- password == password_confirmation and !password.blank?
- end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment