func routeFindIdentity(res http.ResponseWriter, req *http.Request) {
	log_request(req)

	dec := json.NewDecoder(req.Body)

	type pass struct {
		Passphrase string
	}

	var j pass
	if err := dec.Decode(&j); err != nil {
		respond(res, 400, err)
		return
	}

	i, ok := plong.FindIdentity(j.Passphrase)
	if !ok {
		respond(res, 404, nil)
		return
	}

	type identityResponse struct {
		PublicId string
		Created  time.Time
	}

	respond(res, 200, identityResponse{i.Subject.PublicId, i.CreatedAt})
}
Esempio n. 2
0
func wsFindIdentity(c *Connection, args []string) {
	arg := []byte(strings.Join(args, " "))
	type pass struct {
		Passphrase string
	}

	var j pass
	if err := json.Unmarshal(arg, &j); err != nil {
		wsJson(c, err, true)
		return
	}

	i, ok := plong.FindIdentity(j.Passphrase)
	if !ok {
		wsJson(c, "Identity not found.", true)
		return
	}

	type identityResponse struct {
		PublicId string
		Created  time.Time
	}

	wsJson(c, identityResponse{i.Subject.PublicId, i.CreatedAt}, false)
}