// Save guest configuration to path from JSON format. func saveGuestConfig(config *gabs.Container, path string) (err error) { s := config.String() dst, err := os.Create(path) if err != nil { return } defer dst.Close() _, err = dst.WriteString(s) return }
func PublicUserString(token *gabs.Container) string { s, err := gabs.ParseJSON([]byte(token.String())) if err != nil { return "{}" } s.SetP("", "privid") s.SetP("", "alertaddress") return s.String() }
func appendOpenID(t *testing.T, stmt *gabs.Container) *gabs.Container { stmt, err := gabs.ParseJSON([]byte(stmt.String())) fatalIfError(t, err) domainPrefix := uuid.NewV4().String() openID := "http://" + domainPrefix + ".openid.example.com/" _, err = stmt.SetP(openID, "actor.openid") fatalIfError(t, err) return stmt }
func appendMbox(t *testing.T, stmt *gabs.Container) *gabs.Container { stmt, err := gabs.ParseJSON([]byte(stmt.String())) fatalIfError(t, err) domainPrefix := uuid.NewV4().String() mbox := "mbox:test@" + domainPrefix + ".example.com" _, err = stmt.SetP(mbox, "actor.mbox") fatalIfError(t, err) return stmt }
func appendMboxSHA1(t *testing.T, stmt *gabs.Container) *gabs.Container { stmt, err := gabs.ParseJSON([]byte(stmt.String())) fatalIfError(t, err) data := make([]byte, 16) _, err = rand.Read(data) fatalIfError(t, err) mboxSHA1 := fmt.Sprintf("%x", sha1.Sum(data)) _, err = stmt.SetP(mboxSHA1, "actor.mbox_sha1sum") fatalIfError(t, err) return stmt }
func appendAccount(t *testing.T, stmt *gabs.Container) *gabs.Container { stmt, err := gabs.ParseJSON([]byte(stmt.String())) fatalIfError(t, err) suffix := uuid.NewV4().String() name := "name-example-" + suffix homePage := "http://example.com" _, err = stmt.SetP(name, "actor.account.name") fatalIfError(t, err) _, err = stmt.SetP(homePage, "actor.account.homePage") fatalIfError(t, err) return stmt }
func testGetMultStatementOfActor(t *testing.T, stmt *gabs.Container) { db := initDatabase(t) defer db.Close() mart := initHandler(db) id1 := uuid.NewV4().String() id2 := uuid.NewV4().String() putStatement(t, mart, stmt.String(), id1) putStatement(t, mart, stmt.String(), id2) // construct query v := &url.Values{} v.Add("agent", stmt.Search("actor").String()) respstmt, err := gabs.ParseJSON(getStatement(t, mart, v)) fatalIfError(t, err) cnt, err := respstmt.ArrayCount("statements") fatalIfError(t, err) if cnt != 2 { t.Fatalf("Expected 2 statements in response; got %d", cnt) } s0, err := respstmt.ArrayElement(0, "statements") fatalIfError(t, err) if id, ok := s0.Search("id").Data().(string); !ok || id != id1 { t.Fatalf("Got invalid order of statement array") } s1, err := respstmt.ArrayElement(1, "statements") fatalIfError(t, err) if id, ok := s1.Search("id").Data().(string); !ok || id != id2 { t.Fatalf("Got invalid order of statement array") } }
// signupHandler controls the signup and user profile update forms func signupHandler(w http.ResponseWriter, r *http.Request) { if strings.ToUpper(r.Method) == "POST" { invite, ok := service.Invites[r.FormValue("invite")] tokenenc := r.FormValue("token") var token *gabs.Container if ok { delete(service.Invites, r.FormValue("invite")) token, _ = assemble.CreateNewUserToken( r.FormValue("nick"), r.FormValue("name"), r.FormValue("email"), r.FormValue("phone"), r.FormValue("url"), r.FormValue("desc"), r.FormValue("avatar"), r.FormValue("alertaddress")) } else if tokenenc != "" { uid, tokerr := service.ValidateUserToken(nil, tokenenc) if tokerr == nil { privid := service.Users[uid].Token.Path("privid").Data().(string) token, _ = assemble.CreateUpdatedUserToken( r.FormValue("nick"), r.FormValue("name"), r.FormValue("email"), r.FormValue("phone"), r.FormValue("url"), r.FormValue("desc"), r.FormValue("avatar"), r.FormValue("alertaddress"), uid, privid) log.Println(uid, "updated user token") } else { tokenenc = "" } } if ok || tokenenc != "" { competok := utils.Compress([]byte(token.String())) etok, _ := utils.Encrypt(service.UserKey, competok.Bytes()) service.AddToRoom(nil, token.Path("uid").Data().(string), "lobby") //TODO use templates fmt.Fprintf(w, `<html>`) fmt.Fprintf(w, `<meta http-equiv="refresh" content="10; url=/#%s">`, base64.StdEncoding.EncodeToString(etok)) if ok { fmt.Fprintf(w, `<strong>SUCCESS!</strong> `+invite+`<br><br>`) } else { fmt.Fprintf(w, `<strong>Delete your old login bookmark and close the window or you will still be using your old profile!</strong><br><br>`) } //fmt.Fprintf(w, "Token (KEEP THIS SOMEWHERE SAFE OR SAVE THE LOGIN LINK): <br><textarea rows='10' cols='60'>%s</textarea><br><br>", base64.StdEncoding.EncodeToString(etok)) fmt.Fprintf(w, "<a href='/#%s' target='_blank'>Assemble Chat Login - CLICK HERE AND BOOKMARK THE CHAT!</a> <strong>DO NOT SHARE THIS LINK</strong>", base64.StdEncoding.EncodeToString(etok)) fmt.Fprintf(w, "<br>You will automatically enter the chat in 10 seconds...") fmt.Fprintf(w, `</html>`) } else { fmt.Fprintf(w, `Invalid Invite ID or Token`) } } else { fc, _ := ioutil.ReadFile("./static/signup.html") if fc != nil { fmt.Fprintf(w, string(fc[:])) } } }