-
Notifications
You must be signed in to change notification settings - Fork 1
Configuration
britishtea edited this page Feb 13, 2013
·
2 revisions
Cinch-authentication can be configured globally and on a per-plugin basis. To configure globally:
bot = Cinch::Bot.new do
configure do |c|
# ...
c.authentication = Cinch::Configuration::Authentication.new
c.authentication.strategy = :channel_status # or :list / :login
c.authentication.level = :o
end
end
To configure it on a per-plugin basis:
bot = Cinch::Bot.new do
configure do |c|
# ...
c.plugins.plugins << Admin
c.plugins.options[Admin] = {
:authentication_strategy => :channel_status
:authentication_level => :o
}
end
end
Plugin settings always trump global settings, so you can safely configure some basic settings and use different settings for specific plugins.
Cinch-authentication requires two settings to be configured: strategy
and level
. Note that when configuring a plugin, the names of these settings are prefixed with authentication_
(see the examples above).
The level
settings can be an Array (e.g. [:admins, :users]
) when the strategy is :list
or :login
.
-
channel
: The name of the channel where the statuses are pulled from. The channel defaults to the channel the message was sent on.
None.
When using the :login
strategy, cinch-authentication needs to know how to create, fetch and check users for their level. This is done by configuring lambdas.
-
registration
: A lambda that registers a new user. It takes two arguments: a nickname String and a password String. The lambda should returnfalse
if registering a new user fails.
c.authentication.registration = lambda { |nickname, password|
User.create :nickname => nickname, :password => password
}
-
fetch_user
: A lambda that fetches a user by nickname. It should take one argument: a nickname String. Note that the returned user object should have anauthenticate
instance method.
c.authentication.fetch_user = lambda { |nickname|
User.first :nickname => nickname
}
- For each level there should be a lambda that checks if a user has a certain level. The lambda should take one argument: a user instance. The lambda should return a Boolean.
c.authentication.admins = lambda { |user| user.type == 'admin' }
c.authentication.users = lambda { |user| user.type == 'user' }