-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To enable a better on-boarding experience we need a way to correlate users and their inviter. One way is to keep a list of invites of a user that stores a unique id (e.g. facebook id, or generate random identifier) which can be kept through until the invitee hits the signup. If the invitee signs up and the conenction to the inviter is preserved we can automatically create connections for those so they can hit the ground running.
- Loading branch information
Alexander Simmerl
committed
Mar 28, 2017
1 parent
b8e4ee4
commit 47bbc60
Showing
14 changed files
with
1,036 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package core | ||
|
||
import ( | ||
"github.com/tapglue/snaas/service/app" | ||
"github.com/tapglue/snaas/service/invite" | ||
) | ||
|
||
// InviteCreateFunc stores the key and value for the users invite. | ||
type InviteCreateFunc func( | ||
currentApp *app.App, | ||
origin Origin, | ||
key, value string, | ||
) error | ||
|
||
func InviteCreate(invites invite.Service) InviteCreateFunc { | ||
return func( | ||
currentApp *app.App, | ||
origin Origin, | ||
key, value string, | ||
) error { | ||
is, err := invites.Query(currentApp.Namespace(), invite.QueryOptions{ | ||
Keys: []string{ | ||
key, | ||
}, | ||
UserIDs: []uint64{ | ||
origin.UserID, | ||
}, | ||
Values: []string{ | ||
value, | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(is) == 1 { | ||
return nil | ||
} | ||
|
||
_, err = invites.Put(currentApp.Namespace(), &invite.Invite{ | ||
Key: key, | ||
UserID: origin.UserID, | ||
Value: value, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package http | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"golang.org/x/net/context" | ||
|
||
"github.com/tapglue/snaas/core" | ||
) | ||
|
||
// InviteCreate stores the key and value for a users invite. | ||
func InviteCreate(fn core.InviteCreateFunc) Handler { | ||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) { | ||
var ( | ||
currentApp = appFromContext(ctx) | ||
origin = originFromContext(ctx) | ||
p = payloadInvite{} | ||
) | ||
|
||
err := json.NewDecoder(r.Body).Decode(&p) | ||
if err != nil { | ||
respondError(w, 0, wrapError(ErrBadRequest, err.Error())) | ||
return | ||
} | ||
|
||
err = fn(currentApp, origin, p.Key, p.Value) | ||
if err != nil { | ||
respondError(w, 0, err) | ||
return | ||
} | ||
|
||
respondJSON(w, http.StatusNoContent, nil) | ||
} | ||
} | ||
|
||
type payloadInvite struct { | ||
Key string `json:"key"` | ||
Value string `json:"value"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.