我的問題很簡單,¿我如何才能通過客戶的電子郵件進行身份驗證(我的意思是根本沒有密碼)?我知道這是一種不好的做法,但這是客戶的要求之一。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