41 lines
1.7 KiB
Ruby
41 lines
1.7 KiB
Ruby
module JamRuby
|
|
class IcecastUserAuthentication < ActiveRecord::Base
|
|
|
|
has_one :mount, class_name: 'JamRuby::IcecastMount', inverse_of: :authentication
|
|
|
|
validates :authentication_type, presence: true, :inclusion => {:in => ["url", "htpasswd"]}
|
|
validates :allow_duplicate_users, :inclusion => {:in => [true, false]}, if: :htpasswd_auth?
|
|
validates :username, length: {minimum: 5}, if: :url_auth?
|
|
validates :password, length: {minimum: 5}, if: :url_auth?
|
|
validates :mount_add, presence: true, if: :url_auth?
|
|
validates :mount_remove, presence: true, if: :url_auth?
|
|
validates :listener_add, presence: true, if: :url_auth?
|
|
validates :listener_remove, presence: true, if: :url_auth?
|
|
validates :auth_header, presence: true, if: :url_auth?
|
|
validates :timelimit_header, presence: true, if: :url_auth?
|
|
|
|
|
|
def dumpXml (builder)
|
|
builder.tag! 'authentication', type: authentication_type do |auth|
|
|
auth.tag! 'option', name: 'mount_add', value: mount_add if mount_add
|
|
auth.tag! 'option', name: 'mount_remove', value: mount_remove if mount_remove
|
|
auth.tag! 'option', name: 'username', value: username if username
|
|
auth.tag! 'option', name: 'password', value: password if password
|
|
auth.tag! 'option', name: 'listener_add', value: listener_add if listener_add
|
|
auth.tag! 'option', name: 'listener_remove', value: listener_remove if listener_remove
|
|
auth.tag! 'option', name: 'auth_header', value: auth_header if auth_header
|
|
auth.tag! 'option', name: 'timelimit_header', value: timelimit_header if timelimit_header
|
|
end
|
|
end
|
|
|
|
def htpasswd_auth?
|
|
authentication_type == 'htpasswd'
|
|
end
|
|
|
|
def url_auth?
|
|
authentication_type == 'url'
|
|
end
|
|
|
|
|
|
end
|
|
end |