我的问题很简单,¿我如何才能通过客户的电子邮件进行身份验证(我的意思是根本没有密码)?我知道这是一种不好的做法,但这是客户的要求之一。Devise Gem:只用电子邮件登录
目前我已经完成注册,没有密码,当它完成注册后,它重定向到合适的页面(需要验证的视图)。问题是,如果我删除Cookie,并尝试登入它显示“不正确的登录名或密码”
目前是我到目前为止有:
用户模型:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable,
:validatable, :confirmable,:authentication_keys => [:login]
attr_accessor :login
def password_required?
false
end
end
Application_Controller:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
added_attrs = [:email, :remember_me]
devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
devise_parameter_sanitizer.permit :account_update, keys: added_attrs
devise_parameter_sanitizer.permit :sign_in, keys: added_attrs
end
end
用户迁移:
class DeviseCreateUsers < ActiveRecord::Migration[5.0]
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :users, :email, unique: true
add_foreign_key :users, :doctores, column: :email, primary_key: :email
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end
很显然,我alread变化会议的新观点和登记的新观点
你见过这样的职位? http://stackoverflow.com/questions/4662659/devise-authentication-without-password-using-just-username – gwalshington
Nop我没有,但我确实想过这件事。我在跳跃以获得更“优雅”的解决方案。 – HFR1994