Class: ModSpox::Models::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/mod_spox/models/Auth.rb

Overview

Attributes provided by model:

password

Password to autenticate against

services

Authentication by nickserv

mask

Mask to authenticate source against

authed

Nick has authenticated

Instance Method Summary collapse

Instance Method Details

#check_mask(source) ⇒ Object

source

source to apply mask to

Check and authenticate by mask against source



78
79
80
81
82
# File 'lib/mod_spox/models/Auth.rb', line 78

def check_mask(source)
    if(source =~ /^#{mask}$/)
        update_with_params :authed => true
    end
end

#check_password(pass) ⇒ Object

pass

password to compare

Check and authenticate against password



63
64
65
66
67
68
69
70
# File 'lib/mod_spox/models/Auth.rb', line 63

def check_password(pass)
    if(Digest::SHA1.hexdigest(pass) == password)
        update_with_params :authed => true
        return true
    else
        return false
    end
end

#clear_auth_groupsObject

Clear relations before destroying



15
16
17
# File 'lib/mod_spox/models/Auth.rb', line 15

def clear_auth_groups
    AuthGroup.filter(:auth_id => pk).destroy
end

#group=(group) ⇒ Object

Add group to this auth’s list



47
48
49
# File 'lib/mod_spox/models/Auth.rb', line 47

def group=(group)
    AuthGroup.find_or_create(:auth_id => pk, :group_id => group.pk)
end

#groupsObject

Groups this auth is a member of



35
36
37
38
39
40
41
42
43
44
# File 'lib/mod_spox/models/Auth.rb', line 35

def groups
    # we grab IDs, then the object. Otherwise we get sync problems
    group_id = []
    AuthGroup.filter(:auth_id => pk).each do |ag|
        group_id << ag.group_id
    end
    group = []
    group_id.each{|id| group << Group[id]}
    return group
end

#nickObject

Nick associated with this Auth



20
21
22
# File 'lib/mod_spox/models/Auth.rb', line 20

def nick
    Nick[nick_id]
end

#password=(pass) ⇒ Object



72
73
74
# File 'lib/mod_spox/models/Auth.rb', line 72

def password=(pass)
    update_values :password => Digest::SHA1.hexdigest(pass)
end

#remove_group(group) ⇒ Object

Remove given group from auth



52
53
54
# File 'lib/mod_spox/models/Auth.rb', line 52

def remove_group(group)
    AuthGroup.filter(:auth_id => pk, :group_id => group.pk).each{|g|g.destroy}
end

#servicesObject

Is nick identified with services



25
26
27
28
29
30
31
32
# File 'lib/mod_spox/models/Auth.rb', line 25

def services
    s = values[:services]
    if(s == 0 || s == '0' || !s)
        return false
    else
        return true
    end
end

#services_identified=(val) ⇒ Object

Set services (nickserv) identification



57
58
59
# File 'lib/mod_spox/models/Auth.rb', line 57

def services_identified=(val)
    update_with_params :authed => true if val && services
end