more invite thoughts
This commit is contained in:
parent
0a25e9fa99
commit
70a19ba6d7
5 changed files with 43 additions and 5 deletions
|
@ -1,8 +1,17 @@
|
|||
package invite
|
||||
|
||||
import "time"
|
||||
|
||||
// Generate makes a new invite
|
||||
func (i *InviteKV) Generate(email string) (url string) {
|
||||
// generate opaque token
|
||||
opaque := "ASDF" //rand.// had old thing to generate this...
|
||||
inv := Invite{
|
||||
Email: email,
|
||||
Generated: time.Now(),
|
||||
}
|
||||
// store relationship in store
|
||||
i.store.Set(opaque, inv)
|
||||
// return domain + token
|
||||
return i.URL + opaque
|
||||
}
|
||||
|
|
6
new.go
6
new.go
|
@ -2,5 +2,9 @@ package invite
|
|||
|
||||
// New creates a new invite store
|
||||
func New(root_url string, store Store) InviteKV {
|
||||
|
||||
res := InviteKV{
|
||||
URL: root_url,
|
||||
store: store,
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
|
17
redeem.go
17
redeem.go
|
@ -1,6 +1,19 @@
|
|||
package invite
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// returns the email allowed for this invite
|
||||
func (i *InviteKV) Redeem(given_url string) string {
|
||||
// check URL signature
|
||||
func (i *InviteKV) Redeem(given_url string) (string, bool) {
|
||||
// check URL
|
||||
opaque := strings.Split(given_url, i.URL)[1]
|
||||
potential, exists := i.store.Get(opaque)
|
||||
if !exists {
|
||||
return "", false
|
||||
}
|
||||
potential.Redeemed = time.Now()
|
||||
i.store.Set(opaque, potential)
|
||||
return potential.Email, true
|
||||
}
|
||||
|
|
5
store.go
5
store.go
|
@ -1,6 +1,7 @@
|
|||
package invite
|
||||
|
||||
type Store interface {
|
||||
Get(string) string
|
||||
Set(string, string)
|
||||
Get(string) (Invite, bool)
|
||||
Set(string, Invite)
|
||||
Del(string)
|
||||
}
|
||||
|
|
11
type.go
Normal file
11
type.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package invite
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Invite struct {
|
||||
Email string
|
||||
Generated time.Time
|
||||
Redeemed time.Time
|
||||
}
|
Loading…
Add table
Reference in a new issue