From 9643de5d56a6ee33861dd0a5f6834c1272144f3a Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Thu, 2 Jan 2014 17:53:05 +0800 Subject: [PATCH] Fixed Forgot password --- Gemfile | 2 +- app/controllers/confirmations_controller.rb | 18 +++++----- app/controllers/passwords_controller.rb | 20 +++++------ app/models/user/user.rb | 28 +++++++++++++-- app/views/devise/passwords/edit.html.erb | 39 +++++++++++++++------ app/views/devise/passwords/new.html.erb | 25 +++++-------- config/initializers/devise.rb | 9 ++++- config/locales/en.yml | 2 +- config/routes.rb | 4 +-- 9 files changed, 92 insertions(+), 55 deletions(-) diff --git a/Gemfile b/Gemfile index 837d197f..730cea7f 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'bson_ext' gem 'carrierwave' gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid' gem "net-ldap", "~> 0.3.1" -gem 'devise', '1.5.3' +gem 'devise', '2.0' gem 'exception_notification' # Send error trace gem 'execjs' gem 'jquery-rails', '3.0.4' diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb index c601a3e0..44c11304 100644 --- a/app/controllers/confirmations_controller.rb +++ b/app/controllers/confirmations_controller.rb @@ -1,21 +1,21 @@ class ConfirmationsController < Devise::ConfirmationsController layout "devise" -def show - self.resource = resource_class.confirm_by_token(params[:confirmation_token]) + def show + self.resource = resource_class.confirm_by_token(params[:confirmation_token]) if resource.errors.empty? set_flash_message(:notice, :confirmed) if is_navigational_format? respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) } - else - respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new } - end -end + else + respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new } + end + end protected -def after_confirmation_path_for(resource_name, resource) - basic_infos_path(:user_id =>resource.id.to_s) -end + def after_confirmation_path_for(resource_name, resource) + basic_infos_path(:user_id =>resource.id.to_s) + end end \ No newline at end of file diff --git a/app/controllers/passwords_controller.rb b/app/controllers/passwords_controller.rb index e17aa891..cf0c3703 100644 --- a/app/controllers/passwords_controller.rb +++ b/app/controllers/passwords_controller.rb @@ -1,21 +1,18 @@ class PasswordsController < Devise::PasswordsController prepend_before_filter :require_no_authentication - include Devise::Controllers::InternalHelpers # GET /resource/password/new def new build_resource({}) - render_with_scope :new end - - # POST /resource/password +# POST /resource/password def create self.resource = resource_class.send_reset_password_instructions(params[resource_name]) if successfully_sent?(resource) - respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name)) + respond_with({}, :location => root_path) else - respond_with_navigational(resource){ render_with_scope :new } + respond_with(resource) end end @@ -23,7 +20,6 @@ class PasswordsController < Devise::PasswordsController def edit self.resource = resource_class.new resource.reset_password_token = params[:reset_password_token] - render_with_scope :edit end # PUT /resource/password @@ -36,15 +32,15 @@ class PasswordsController < Devise::PasswordsController sign_in(resource_name, resource) respond_with resource, :location => after_sign_in_path_for(resource) else - respond_with_navigational(resource){ render_with_scope :edit } + respond_with resource end end - protected + # protected # The path used after sending reset password instructions - def after_sending_reset_password_instructions_path_for(resource_name) - new_session_path(resource_name) - end + # def after_sending_reset_password_instructions_path_for(resource_name) + # new_session_path(resource_name) + # end end \ No newline at end of file diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 814d2d3f..7a417ba6 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -8,7 +8,31 @@ class User devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :validatable, :confirmable #, :timeoutable mount_uploader :avatar, AvatarUploader - + #Devise Fields + ## Database authenticatable + field :email, :type => String, :null => false + field :encrypted_password, :type => String, :null => false + + ## Recoverable + field :reset_password_token, :type => String + field :reset_password_sent_at, :type => Time + + ## Rememberable + field :remember_created_at, :type => Time + + ## Trackable + field :sign_in_count, :type => Integer + field :current_sign_in_at, :type => Time + field :last_sign_in_at, :type => Time + field :current_sign_in_ip, :type => String + field :last_sign_in_ip, :type => String + + ## Confirmable + field :confirmation_token, :type => String + field :confirmed_at, :type => Time + field :confirmation_sent_at, :type => Time + + #Extra Fields field :admin, :type => Boolean, :default => false field :active_role field :user_id @@ -22,7 +46,7 @@ class User field :cache_dept,type: Hash field :status_record,type: Hash field :approved, type: Boolean, :default => false - field :reset_password_sent_at, :type => Time + # field :reset_password_sent_at, :type => Time has_and_belongs_to_many :approving_apps, class_name: 'AuthApproval', inverse_of: 'authorized_users' has_and_belongs_to_many :managing_apps, class_name: 'AuthManager', inverse_of: 'authorized_users' diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index e75c9371..4348da6d 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -1,16 +1,33 @@ -

Change your password

+
+ +
\ No newline at end of file diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index 2785f9b3..7a884f28 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -1,35 +1,28 @@
-