-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.go
More file actions
74 lines (64 loc) · 1.46 KB
/
user.go
File metadata and controls
74 lines (64 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package citadel
import (
"fmt"
)
const (
USE_LEVEL_DELETED = "0"
USE_LEVEL_NEW = "1"
USE_LEVEL_PROBLEM = "2"
USE_LEVEL_LOCAL = "3"
USE_LEVEL_NETWORK = "4"
USE_LEVEL_PREFERED = "5"
USE_LEVEL_ADMIN = "6"
)
func (c *Citadel) UserCreate(username, password string) (ok bool) {
if ok = Validate(username, Rx_USERNAME); !ok {
c.Error = fmt.Errorf("Username not Valid")
return
}
if ok = Validate(password, Rx_PASSWORD); !ok {
c.Error = fmt.Errorf("Password not Valid")
return
}
cmd := fmt.Sprintf("NEWU %s", username)
c.Request(cmd)
if ok = c.code(); !ok {
return
}
ok = c.userSetPassword(password)
return
}
func (c *Citadel) Login(username, password string) (ok bool) {
cmd := fmt.Sprintf("USER %s", username)
c.Request(cmd)
ok = c.code()
if ok {
cmd := fmt.Sprintf("PASS %s", password)
c.Request(cmd)
ok = c.code()
}
c.FloorsLoader()
return
}
func (c *Citadel) Logout() {
c.Request("LOUT")
}
// This command sets a new password for the currently logged in user.
func (c *Citadel) UserSetPassword(password string) (ok bool) {
if ok = Validate(password, Rx_PASSWORD); !ok {
c.Error = fmt.Errorf("Password not Valid")
} else {
ok = c.userSetPassword(password)
}
return
}
func (c *Citadel) userSetPassword(password string) bool {
cmd := fmt.Sprintf("SETP %s", password)
c.Request(cmd)
return c.code()
}
func (c *Citadel) UserCfg(username string) bool {
cmd := fmt.Sprintf("AGUP %s", username)
c.Request(cmd)
return c.code()
}