Class: PostyCli::Command::User

Inherits:
Thor
  • Object
show all
Defined in:
lib/posty_cli/command/user.rb

Instance Method Summary collapse

Instance Method Details

#add(name) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/posty_cli/command/user.rb', line 30

def add(name)
	split = name.split("\@")
	if(name =~ /\@/ && split.length < 3 )
		i = true
		while i		
						
			
			puts "password:"
			pw = STDIN.noecho(&:gets).chomp	
			puts "enter password again: "							
			if(STDIN.noecho(&:gets).chomp==pw)
				json = {name: split[0], password: pw}.to_json
				domain = split[1]
				
				PostyCli::Util::User.create(json, domain, split[0])
				i=false
			else
				puts "password not equal, sorry!!"
			end
		end					
	else
		puts "you have to enter a valid email adress like [email protected]"
	end
end

#delete(name) ⇒ Object


90
91
92
93
94
95
96
97
98
99
# File 'lib/posty_cli/command/user.rb', line 90

def delete(name)
	split = name.split("\@")
	if(name =~ /\@/ && split.length < 3 )
		name_del = split[0]
		domain = split[1]
		if(yes? "Are you sure you want to delete #{name}? Yes\\No")
			PostyCli::Util::User.delete(name_del, domain)				
		end
	end
end

#edit(name, new_name) ⇒ Object


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/posty_cli/command/user.rb', line 61

def edit(name, new_name)
	split = name.split("\@")
	if(name =~ /\@/ && split.length < 3 )
		i = true
		while i		
			puts "password:"
			pw = STDIN.noecho(&:gets).chomp	
			puts "enter password again: "							
			if(STDIN.noecho(&:gets).chomp==pw)
				json = {name: new_name, password: pw}.to_json
				domain = split[1]
				
				PostyCli::Util::User.edit(json, domain, new_name, split[0], new_name)
				i=false
			else
				puts "password not equal, sorry!!"
			end
		end					
	else
		puts "you have to enter a valid email adress like [email protected]"
	end
end

#list(domain) ⇒ Object


14
15
16
17
18
19
# File 'lib/posty_cli/command/user.rb', line 14

def list(domain)
	out = PostyCli::Util::User.get_all(domain)
	
	print_table(out)
	
end