Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UsersController < ApplicationController
- include Authentication::ControllerUtils
- AUTHENTICATION_SETTINGS =
- {:action_on =>
- {:create => {
- :success => Proc.new { redirect_to_stored },
- :fail => Proc.new { render :action => :new }
- },
- :change_password => {
- :success => Proc.new { redirect_to @model }
- },
- :recover_password => {
- :success => Proc.new { redirect_to :action => :change_password }
- }
- }}
- def new
- @user = User.new
- end
- def create
- @model = model = auth_model.create(params[auth_model_name])
- if model.errors.empty?
- session[auth_model_name] = model.id # auto signing in
- self.send("#{auth_model_name.to_s}=".to_sym, model)
- #self.mailer.deliver_signup(model)
- save_cookies({:id => model.id, :password => model.password})
- flash[:message] = "You've successfully created an account"
- action_on(:success)
- else
- self.send("#{auth_model_name.to_s}=".to_sym, model)
- action_on(:fail)
- end
- end
- def change_password
- @model = model = auth_model.find(session[auth_model_name])
- if request.put?
- model.update_attributes(params[auth_model_name])
- if model.errors.empty?
- save_cookies({:password => model.password, :id => model.id})
- flash[:message] = "Password has been changed successfully"
- action_on(:success)
- end
- end
- # If get request or errors, then just render the form
- self.send("#{auth_model_name.to_s}=".to_sym, model)
- end
- def lost_password
- if request.post?
- if model = auth_model.find_by_email(
- params[auth_model_name][:email]
- )
- model.set_password_token
- model.save!
- UserMailer.deliver_lost_password(model)
- flash[:message] = "You password recovery token has been emailed to you"
- else # just render form again
- flash.now[:error] = "Sorry, there's no such email in our database"
- end
- end
- end
- def recover_password
- model = self.auth_model.find_by_password_token(params[:token]) if params[:token]
- if model && model.password_token_expires > Time.now
- session[auth_model_name] = model.id
- action_on(:success)
- else
- flash.now[:error] = "This token is invalid"
- end
- model.destroy_password_token if model
- end
- end
Add Comment
Please, Sign In to add comment