Fixed Forgot password

This commit is contained in:
saurabhbhatia 2014-01-02 17:53:05 +08:00
parent 684f2c75be
commit 9643de5d56
9 changed files with 92 additions and 55 deletions

View File

@ -8,7 +8,7 @@ gem 'bson_ext'
gem 'carrierwave' gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid' gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem "net-ldap", "~> 0.3.1" gem "net-ldap", "~> 0.3.1"
gem 'devise', '1.5.3' gem 'devise', '2.0'
gem 'exception_notification' # Send error trace gem 'exception_notification' # Send error trace
gem 'execjs' gem 'execjs'
gem 'jquery-rails', '3.0.4' gem 'jquery-rails', '3.0.4'

View File

@ -1,21 +1,21 @@
class ConfirmationsController < Devise::ConfirmationsController class ConfirmationsController < Devise::ConfirmationsController
layout "devise" layout "devise"
def show def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token]) self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty? if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_navigational_format? set_flash_message(:notice, :confirmed) if is_navigational_format?
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) } respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new } respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
end
end end
end
protected protected
def after_confirmation_path_for(resource_name, resource) def after_confirmation_path_for(resource_name, resource)
basic_infos_path(:user_id =>resource.id.to_s) basic_infos_path(:user_id =>resource.id.to_s)
end end
end end

View File

@ -1,21 +1,18 @@
class PasswordsController < Devise::PasswordsController class PasswordsController < Devise::PasswordsController
prepend_before_filter :require_no_authentication prepend_before_filter :require_no_authentication
include Devise::Controllers::InternalHelpers
# GET /resource/password/new # GET /resource/password/new
def new def new
build_resource({}) build_resource({})
render_with_scope :new
end end
# POST /resource/password
# POST /resource/password
def create def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name]) self.resource = resource_class.send_reset_password_instructions(params[resource_name])
if successfully_sent?(resource) if successfully_sent?(resource)
respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name)) respond_with({}, :location => root_path)
else else
respond_with_navigational(resource){ render_with_scope :new } respond_with(resource)
end end
end end
@ -23,7 +20,6 @@ class PasswordsController < Devise::PasswordsController
def edit def edit
self.resource = resource_class.new self.resource = resource_class.new
resource.reset_password_token = params[:reset_password_token] resource.reset_password_token = params[:reset_password_token]
render_with_scope :edit
end end
# PUT /resource/password # PUT /resource/password
@ -36,15 +32,15 @@ class PasswordsController < Devise::PasswordsController
sign_in(resource_name, resource) sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource) respond_with resource, :location => after_sign_in_path_for(resource)
else else
respond_with_navigational(resource){ render_with_scope :edit } respond_with resource
end end
end end
protected # protected
# The path used after sending reset password instructions # The path used after sending reset password instructions
def after_sending_reset_password_instructions_path_for(resource_name) # def after_sending_reset_password_instructions_path_for(resource_name)
new_session_path(resource_name) # new_session_path(resource_name)
end # end
end end

View File

@ -8,7 +8,31 @@ class User
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :validatable, :confirmable #, :timeoutable devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :validatable, :confirmable #, :timeoutable
mount_uploader :avatar, AvatarUploader 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 :admin, :type => Boolean, :default => false
field :active_role field :active_role
field :user_id field :user_id
@ -22,7 +46,7 @@ class User
field :cache_dept,type: Hash field :cache_dept,type: Hash
field :status_record,type: Hash field :status_record,type: Hash
field :approved, type: Boolean, :default => false 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 :approving_apps, class_name: 'AuthApproval', inverse_of: 'authorized_users'
has_and_belongs_to_many :managing_apps, class_name: 'AuthManager', inverse_of: 'authorized_users' has_and_belongs_to_many :managing_apps, class_name: 'AuthManager', inverse_of: 'authorized_users'

View File

@ -1,7 +1,18 @@
<h2>Change your password</h2> <section id="main-wrap">
<div class="sign-in have-other-sign-in">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %> <div class="form">
<h3 class="login-logo">Change your password</h3>
<div>
<input name="utf8" type="hidden" value="" />
<input name="authenticity_token" type="hidden" value="" />
</div>
<div class="form-block">
<div class="form-list clearfix">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put, :class => 'user_new form-horizontal content' }) do |f| %>
<%= devise_error_messages! %> <%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %> <%= f.hidden_field :reset_password_token %>
<div><%= f.label :password, "New password" %><br /> <div><%= f.label :password, "New password" %><br />
@ -9,8 +20,14 @@
<div><%= f.label :password_confirmation, "Confirm new password" %><br /> <div><%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation %></div> <%= f.password_field :password_confirmation %></div>
<p></p>
<div><%= f.submit "Change my password" %></div> <div><%= f.submit "Change my password", :class => 'btn btn-primary' %></div>
<% end %> </div>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %> <%= render :partial => "devise/shared/links" %>
</div>
</div>
</section>

View File

@ -1,7 +1,5 @@
<section id="main-wrap"> <section id="main-wrap">
<div class="sign-in have-other-sign-in"> <div class="sign-in have-other-sign-in">
<!-- <p class="alert alert-error in fade">You need to sign in.</p>
-->
<div class="form"> <div class="form">
<h3 class="login-logo">Reset Your Password</h3> <h3 class="login-logo">Reset Your Password</h3>
@ -9,24 +7,19 @@
<input name="utf8" type="hidden" value="" /> <input name="utf8" type="hidden" value="" />
<input name="authenticity_token" type="hidden" value="" /> <input name="authenticity_token" type="hidden" value="" />
</div> </div>
<!-- <div class="other-sign-in">
<a class="btn btn-primary" type="submit">Other Sign In</a>
<p>or</p>
</div> -->
<div class="form-block"> <div class="form-block">
<div class="form-list clearfix"> <div class="form-list clearfix">
<form class="content" accept-charset="UTF-8" action="/users/sign_in" method="post"> <%= form_for(:user, :url => user_password_path, :html => { :method => :post, :class => 'user_new form-horizontal content' }) do |f| %>
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post, :class => 'user_new form-horizontal' }) do |f| %>
<%= devise_error_messages! %> <%= devise_error_messages! %>
<div class="control-group clear"> <div class="control-group clear">
<label for="user_email"> <label for="user_email">
<i class="icons-mail "></i> <i class="icons-mail "></i>
</label> </label>
<%= f.text_field :email, :placeholder => t(:email), :id=>"user_email" %> <%= f.email_field :email, :placeholder => t(:email), :id=>"user_email" %>
</div> </div>
<%= content_tag :button, "Reset Password", :type => :submit, :class => 'btn btn-primary' %> <%= content_tag :button, "Reset Password", :type => :submit, :class => 'btn btn-primary' %>
</form>
</div> </div>
</div> </div>
<% end %> <% end %>

View File

@ -22,7 +22,7 @@ Devise.setup do |config|
# session. If you need permissions, you should implement that in a before filter. # session. If you need permissions, you should implement that in a before filter.
# config.authentication_keys = [ :email ] # config.authentication_keys = [ :email ]
config.authentication_keys = [ :user_id ] config.authentication_keys = [ :user_id ]
config.reset_password_keys = [ :email ]
# Tell if authentication through request.params is enabled. True by default. # Tell if authentication through request.params is enabled. True by default.
# config.params_authenticatable = true # config.params_authenticatable = true
@ -82,6 +82,13 @@ Devise.setup do |config|
# config.timeout_in = 10.minutes # config.timeout_in = 10.minutes
config.timeout_in = 5.days config.timeout_in = 5.days
config.apply_schema = false
config.use_salt_as_remember_token = true
config.reset_password_within = 6.hours
# ==> Configuration for :lockable # ==> Configuration for :lockable
# Defines which strategy will be used to lock an account. # Defines which strategy will be used to lock an account.
# :failed_attempts = Locks an account after a number of failed attempts to sign in. # :failed_attempts = Locks an account after a number of failed attempts to sign in.

View File

@ -426,7 +426,7 @@ en:
index: Index index: Index
summary: Summary summary: Summary
thumbnail: Thumbnail thumbnail: Thumbnail
settings: Site setting settings: Site Setting
site: site:
backend_openness_on: Backend Openness backend_openness_on: Backend Openness
mobile_api_openness_on: Mobile API Openness mobile_api_openness_on: Mobile API Openness

View File

@ -3,8 +3,8 @@ Orbit::Application.routes.draw do
# get "robots.txt" => 'robots#index' # get "robots.txt" => 'robots#index'
devise_for :users, :controllers => { :registrations => "registrations", :confirmations => 'confirmations', :passwords => 'passwords' } do devise_for :users, :controllers => { :registrations => "registrations", :passwords => 'passwords', :confirmations => 'confirmations' } do
resources :passwords resources :passwords, :except => [:index, :show, :destroy]
match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put
end end