Alexander Trauzzi
Alexander Trauzzi

Reputation: 7396

Optional password during authentication with Devise

If I've got a rails application and I'd like to add authentication to with Devise, how would I allow users who have a null password in the database to sign in without one?

I'm interested in hearing answers along the lines of the lifecycle and what files I'd have to author to get it done.

Upvotes: 0

Views: 370

Answers (2)

Alexander Trauzzi
Alexander Trauzzi

Reputation: 7396

It turns out, Devise is built on Warden. This means that I only have to create my own custom Warden strategy:

https://github.com/hassox/warden/wiki/Strategies

Upvotes: 0

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

Step 1: Allow the record to be saved.
Step 2: Sign in the record

To allow the record to be saved, you'll want to do validations yourself. I describe here how to do custom validations: http://jessewolgamott.com/blog/2011/12/08/the-one-where-devise-validations-are-customized/ .... In your case, you'll want to remove the password validations.

To sign in the record, you'll need to have a custom sign in path. You can override the devise sessions controller, but this could do the trick:

class SessionsController < ApplicationController
  def create
    user = User.find_by_email!(params[:session][:email])
    sign_in user
    redirect_to root_path
  end
end

Upvotes: 1

Related Questions