设计无法保存用户

时间:2018-07-30 23:38:34

标签: ruby-on-rails ruby devise

将devise_usf_fido gem(https://github.com/CyberDeck/devise-fido-u2f)添加到我的RoR项目中之后,我无法使用注册页面保存任何已创建的devise用户。任何新用户只会持续大约一分钟,然后完全消失。

应用程序控制器

class ApplicationController < ActionController::Base
protect_from_forgery with: :exception, prepend: true

before_action :configure_permitted_parameters, if: :devise_controller?

  protected

def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation) }
end

def authenticate_admin!
    authenticate_user!
    redirect_to :root, status: :unauthorized unless current_user.admin?
end

end

用户模型

  class User < ApplicationRecord
 # Include default devise modules. Others available are:
 # :confirmable, :lockable, :timeoutable and :omniauthable
 devise :database_authenticatable, :registerable,
      :recoverable, :rememberable, :trackable, :validatable,
      :fido_usf_registerable, :fido_usf_authenticatable

 attr_accessor :email, :password, :password_confirmation

 has_many :articles
end

设计用户迁移

   # frozen_string_literal: true

    class DeviseCreateUsers < ActiveRecord::Migration[5.1]
     def change
   create_table :users do |t|
  ## Database authenticatable
  t.string :email,              null: false, default: ""
  t.string :encrypted_password, null: false, default: ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## 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: 5, 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_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token,   unique: true
# add_index :users, :unlock_token,         unique: true  
 end

结束

路线

  Rails.application.routes.draw do
     devise_for :users, path: '', path_names: { sign_in: 'login', sign_out: 'logout' }
  get 'homepage/index'

  resources :articles
  resources :about
  resources :history
  resources :empire do
    resources :articles
    resources :capital
    resources :kadrin
    resources :norn
    resources :varr
    resources :azul
    resources :drak
    resources :izor
    resources :zhufbar
    resources :peaks
    resources :azgul
    resources :drazh
    resources :agilwutraz
    resources :gunbad
    resources :varn
    resources :vlag
    resources :ungor
    resources :ekrund
    match '*path' => redirect('empire/'), via: :get
 end
 resources :society do
   resources :articles
   resources :social
   resources :military
   resources :magic
   resources :religion
   resources :guilds
   resources :government
   resources :economy
   resources :prominent
   resources :language
 end
  get "*path" => redirect { |p, req| req.flash[:notice] = "Error, #{req.env["HTTP_HOST"]}#{req.env["REQUEST_PATH"]} is not a valid URL"; '/' }
  root 'homepage#index'

通过设计注册页面

<h2>Sign up</h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>

<div class="field">
  <%= f.label :email %><br />
  <%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</div>

<div class="field">
  <%= f.label :password %>
  <% if @minimum_password_length %>
  <em>(<%= @minimum_password_length %> characters minimum)</em>
  <% end %><br />
  <%= f.password_field :password, autocomplete: "off" %>
</div>

<div class="field">
  <%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>

<div class="actions">
  <%= f.submit "Sign up" %>
</div>
<% end %>

<%= render "devise/shared/links" %>

0 个答案:

没有答案