如何利用设计来锁定用户? [英] How to lock users using Devise?

查看:149
本文介绍了如何利用设计来锁定用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序添加订阅类型的功能为账户持有人的用户,这样一个固定的时间间隔后,他们将无法访问他们的帐户?注:我不想从数据库中删除自己的帐户。我已经安装了设计-2.1.2 在我的应用程序。做任何身体有任何想法如何能不能做到?我是新手,轨道上的Ruby 所以这将是对我很大的帮助,如果你请解释的步骤。

I want to add a subscription type functionality in my application for the account holder users such that after a fixed interval of time they will not be able to access their account? Note: I dont want to delete their account from the database. I've already installed devise-2.1.2 in my application. Do any body have any idea how can it be done? I am newbie to Ruby on rails so it will be very helpful to me if you please explain the steps.

感谢

推荐答案

设计有一个BUIL,在溶液中的:在选项检查= http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable\">Devise可锁定文档

Devise have a buil-in solution with the :lockable option check in the Devise Lockable Documentation

您必须设置 lock_strategy 设置为:failed_attempts

第1步
设置你的配置/初始化/ devise.rb使用方法:

Step 1 Set your config/initializers/devise.rb to use:

# Defines which strategy will be used to lock an account.
config.lock_strategy = :failed_attempts

# Defines which key will be used when locking and unlocking an account
config.unlock_keys = [ :time ]

# Defines which strategy will be used to unlock an account.
# :time  = Re-enables login after a certain amount of time (see :unlock_in below)
config.unlock_strategy = :time

# Number of authentication tries before locking an account if lock_strategy
# is failed attempts.
config.maximum_attempts = 3

# Time interval to unlock the account if :time is enabled as unlock_strategy.
config.unlock_in = 2.hours

第2步
您应可锁定模型添加到你的心情:

Step 2 Your should add the lockable to you Model as this:

class Example < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, 
         :lockable

第3步
产生迁移,使色器件的工作

Step 3 Generate the migrations to make devise work

class AddLockableToExamples < ActiveRecord::Migration
  def change
    add_column :examples, :failed_attempts, :integer, default: 0
    add_column :examples, :unlock_token, :string
    add_column :examples, :locked_at, :datetime
  end
end

商祺!

这篇关于如何利用设计来锁定用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆