Ejemplo n.º 1
0
// GenerateOneOnOneHash returns a hash for a one-on-one room
func GenerateOneOnOneHash(user1 string, user2 string) (hash string) {
	// Sort users so hashes are in alphabetical order
	users := []string{user1, user2}
	sort.Strings(users)

	return crypto.Hash(users[0] + users[1])
}
Ejemplo n.º 2
0
// SaveHandler saves a item
func SaveHandler(w http.ResponseWriter, r *http.Request) {
	u, _ := auth.GetAuthenticatedUser(r)

	hash := r.FormValue("hash")
	name := r.FormValue("name")
	kind := Open
	folder := r.FormValue("folder")
	created := time.Now()

	if hash == "" {
		hash = crypto.UniqueHash(name)
	}

	room, err := repo.Load(hash)
	if err == nil {
		created = room.Created
	}

	room = &Room{Hash: hash, Name: name, Kind: kind, Folder: folder, Created: created}
	err = repo.Save(room)
	render.Check(err, w)

	// Add members to room
	members := r.Form["members"]
	members = append(members, u.Key)
	for _, user := range members {
		hash = crypto.Hash(room.Hash + user)
		rm := &RoomMember{Hash: hash, User: user, Room: room.Hash}
		err = roomMemberRepo.Save(rm)
		render.Check(err, w)
	}

	http.Redirect(w, r, "/r/"+room.Hash, http.StatusFound)
}
Ejemplo n.º 3
0
// JoinRoom joins a user with a room
func JoinRoom(room string, user string) error {
	hash := crypto.Hash(room + user)
	rm := &RoomMember{Hash: hash, User: user, Room: room}
	err := roomMemberRepo.Save(rm)
	return err
}