Class: Users

Inherits:
Object
  • Object
show all
Includes:
DRbUndumped, Eprint
Defined in:
lib/DrbDB/Users.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the owner of manqod is Dobai-Pataky Balint([email protected])

Constant Summary

Constants included from Eprint

Eprint::TERM_COLOUR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Eprint

#ecode, #edebug, #eerror, #eeval, #eexception, #efatal, #einfo, #eprint, #ewarn, #getBinding, #report_mail

Constructor Details

#initialize(drbdb) ⇒ Users

Returns a new instance of Users.



8
9
10
11
12
13
# File 'lib/DrbDB/Users.rb', line 8

def initialize(drbdb)
	@drbdb=drbdb
	@users=Hash.new
	@groups=Hash.new
	@usergroups=Hash.new
end

Instance Attribute Details

#drbdbObject (readonly)

Returns the value of attribute drbdb.



14
15
16
# File 'lib/DrbDB/Users.rb', line 14

def drbdb
  @drbdb
end

Instance Method Details

#auth?(nick, password) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
# File 'lib/DrbDB/Users.rb', line 56

def auth?(nick,password)
	found=false
	@users.each{|key,user|
		found=true if nick.to_s == user["nick"].to_s && user["passwd"].to_s == password.to_s
	}
	found
end

#eachObject



53
54
55
# File 'lib/DrbDB/Users.rb', line 53

def each
	@users.each_key{|im_key| yield im_key}
end

#get_user(user_id) ⇒ Object



49
50
51
# File 'lib/DrbDB/Users.rb', line 49

def get_user(user_id)
	@users[user_id]
end

#load_allObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/DrbDB/Users.rb', line 16

def load_all
	@users.clear
	@groups.clear
	@usergroups.clear
	drbdb.admin.rows("select * from users").each{|row|
		@users[row["id"].to_i]=row
	}
	einfo("#{@users.length} users\n")
	drbdb.admin.rows("select * from groups").each{|row|
		@groups[row["id"].to_i]=row
	}
	drbdb.admin.rows("select * from usergroups").each{|row|
		@usergroups[row["id"].to_i]=row
	}
	self
end

#mygroups(nick) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/DrbDB/Users.rb', line 41

def mygroups(nick)
	gr=Hash.new
	@usergroups.each_value{|ugrp|
		gr[ugrp["groupid"].to_i]=@groups[ugrp["groupid"].to_i]["name"] if @groups.has_key?(ugrp["groupid"].to_i) && @users.has_key?(ugrp["userid"].to_i) && @users[ugrp["userid"].to_i]['nick'] == nick 
	}
	gr
end

#to_sObject



65
66
67
# File 'lib/DrbDB/Users.rb', line 65

def to_s
	"Users of #{drbdb}"
end

#user_in_group?(user_id, group_id) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/DrbDB/Users.rb', line 33

def user_in_group?(user_id,group_id)
	found=false
	@usergroups.each_value{|ugrp|
		found=true if ugrp["userid"].to_i == user_id && ugrp["groupid"].to_i == group_id
	}
	found
end