我正在使用设备对管理员和用户进行身份验证。 管理员可以注册用户,但是,每次管理员要注册多个用户时,管理员必须销毁并为要注册的每个用户创建其管理员会话。即,管理员会话仅允许注册一个用户。
这是在管理员登录后立即成功注册的用户(alunos)。
Started POST "/alunos" for ::1 at 2019-09-30 10:39:29 -0300
Processing by Alunos::RegistrationsController#create as HTML
Parameters: {"authenticity_token"=>"WBl6StcQuSl+v/rCuvm/xUPp6u/Cpz137gHunvUtE1yWUXkwoCu5AvXYfKX1PfxhNoV3JtzluHK9P+uHb+LDyw==", "x"=>"31", "y"=>"25", "aluno"=>{"matricula"=>"M1", "nome"=>"AA", "rg"=>"11", "cpf"=>"11", "nascimento"=>"2001-01-01", "sexo"=>"Masculino", "estadocivil"=>"solteiro", "telefone"=>"11", "email"=>"test1@test", "cidade"=>"AA", "rua"=>"AA", "numero"=>"11", "bairro"=>"AA", "complemento"=>"AA", "estado"=>"AA", "pais"=>"AA", "cep"=>"AA", "naturalidade"=>"AA", "ingresso"=>"11", "turma"=>"AA", "conjuge"=>"AA", "mae"=>"AA", "pai"=>"AA", "igreja_id"=>"1", "residenocampus"=>"1", "password"=>"[FILTERED]"}}
(0.2ms) BEGIN
Aluno Exists? (0.3ms) SELECT 1 AS one FROM `alunos` WHERE `alunos`.`email` = BINARY 'test1@test' LIMIT 1
Aluno Create (0.3ms) INSERT INTO `alunos` (`matricula`, `nome`, `rg`, `cpf`, `telefone`, `email`, `sexo`, `ingresso`, `turma`, `nascimento`, `cidade`, `igreja_id`, `estado`, `rua`, `bairro`, `complemento`, `cep`, `numero`, `pais`, `created_at`, `updated_at`, `naturalidade`, `estadocivil`, `residenocampus`, `conjuge`, `mae`, `pai`, `encrypted_password`) VALUES ('M1', 'AA', '11', '11', '11', 'test1@test', 'Masculino', 11, 'AA', '2001-01-01', 'AA', 1, 'AA', 'AA', 'AA', 'AA', 'AA', 11, 'AA', '2019-09-30 13:39:29.269375', '2019-09-30 13:39:29.269375', 'AA', 'solteiro', TRUE, 'AA', 'AA', 'AA', '$2a$11$jh1UODTYW40mnf2Tc.rJ/ubDhZWc3nH/qfc1CJeAOijDYccEBhXIy')
(3.6ms) COMMIT
这是第一个寄存器之后的不成功寄存器。
Started POST "/alunos" for ::1 at 2019-09-30 10:40:17 -0300
Processing by Alunos::RegistrationsController#create as HTML
Parameters: {"authenticity_token"=>"0HM5IujlLKwLOVdfVEMi6zoYM2WDCNS3SWOZnLncnkkeOzpYn94sh4Be0Tgbh2FPT3SurJ1KUbIaXZyFIxNO3g==", "x"=>"16", "y"=>"19", "aluno"=>{"matricula"=>"BB", "nome"=>"BB", "rg"=>"22", "cpf"=>"22", "nascimento"=>"2001-01-02", "sexo"=>"Feminino", "estadocivil"=>"casado", "telefone"=>"22", "email"=>"test2@test", "cidade"=>"BB", "rua"=>"BB", "numero"=>"22", "bairro"=>"BB", "complemento"=>"BB", "estado"=>"BB", "pais"=>"BB", "cep"=>"BB", "naturalidade"=>"BB", "ingresso"=>"22", "turma"=>"BB", "conjuge"=>"BB", "mae"=>"BB", "pai"=>"BB", "igreja_id"=>"2", "residenocampus"=>"1", "password"=>"[FILTERED]"}}
Aluno Load (0.8ms) SELECT `alunos`.* FROM `alunos` WHERE `alunos`.`id` = 9 ORDER BY `alunos`.`id` ASC LIMIT 1
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 7ms (ActiveRecord: 0.8ms | Allocations: 1819)
我意识到错误“过滤器链由于呈现或重定向的require_no_authentication而停止”是导致错误的原因!
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
好,解决起来很简单!
如果有人遇到相同的问题,我只会阻止devise尝试登录刚刚注册的用户:
class Alunos::RegistrationsController < Devise::RegistrationsController
def create
super
end
protected
def sign_up(resource_name, resource)
true
end
end