Esempio n. 1
0
// FolderHandler returns a list of resources pertaining to the room
func FolderHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	hash := vars["hash"]

	room, err := repo.Load(hash)
	render.Check(err, w)

	var folder dropbox.Entry

	if room.Folder != "" {
		session, _ := cookieStore.Get(r, "dropbox")
		token := fmt.Sprintf("%v", session.Values["token"])
		if token == "<nil>" { // FIXME: This could be more presentable
			http.Redirect(w, r, "/dropbox", 302)
		}

		url := fmt.Sprintf("https://api.dropbox.com/1/metadata/auto/%s", room.Folder)
		response, err := dropbox.Request("GET", url, token)
		render.Check(err, w)

		dropbox.DecodeResponse(response, &folder)
	}

	render.Render(w, r, "room_folder", map[string]interface{}{
		"request": r,
		"room":    room,
		"folder":  folder,
	})
}
Esempio n. 2
0
// FormHandler presents a form for creating a board
func FormHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	room := vars["room"]

	render.Render(w, r, "board_form", map[string]interface{}{
		"request": r,
		"room":    room,
	})
}
Esempio n. 3
0
func userListHandler(w http.ResponseWriter, r *http.Request) {
	users, err := authRepo.List(100)
	render.Check(err, w)

	render.Render(w, r, "user_list", map[string]interface{}{
		"request": r,
		"users":   users,
	})
}
Esempio n. 4
0
// FormHandler presents a form for creating a new room
func FormHandler(w http.ResponseWriter, r *http.Request) {
	u, _ := auth.GetAuthenticatedUser(r)

	users, err := userRepo.List(100)
	render.Check(err, w)

	render.Render(w, r, "room_form", map[string]interface{}{
		"request": r,
		"users":   users,
		"user":    u,
	})
}
Esempio n. 5
0
// ListHandler returns all boards
func ListHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	hash := vars["hash"]

	boards, err := repo.List(hash)
	render.Check(err, w)

	render.Render(w, r, "board_list", map[string]interface{}{
		"request": r,
		"boards":  boards,
	})
}
Esempio n. 6
0
// ListHandler returns all available rooms
func ListHandler(w http.ResponseWriter, r *http.Request) {
	au, _ := auth.GetAuthenticatedUserKey(r)

	rooms, err := roomMemberRepo.ListRoomsForUser(au, 20)
	render.Check(err, w)

	joinable, err := roomMemberRepo.ListJoinableRoomsForUser(au, 20)
	render.Check(err, w)

	render.Render(w, r, "home", map[string]interface{}{
		"request":  r,
		"rooms":    rooms,
		"joinable": joinable,
	})
}
Esempio n. 7
0
// MemberHandler returns memebers for a room
func MemberHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	hash := vars["hash"]

	room, err := repo.Load(hash)
	render.Check(err, w)

	members, err := roomMemberRepo.ListMembers(room.Hash)
	render.Check(err, w)

	render.Render(w, r, "room_members", map[string]interface{}{
		"request": r,
		"room":    room,
		"members": members,
	})
}
Esempio n. 8
0
// BoardHandler returns board with its paths
func BoardHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	hash := vars["hash"]

	board, err := repo.Load(hash)
	render.Check(err, w)

	paths, err := pathRepo.List(board.Hash)
	render.Check(err, w)

	render.Render(w, r, "board", map[string]interface{}{
		"request": r,
		"board":   board,
		"paths":   paths,
	})
}
Esempio n. 9
0
// MessageHandler returns a message
func MessageHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	hash := vars["hash"]

	message, err := repo.Load(hash)
	render.Check(err, w)

	user, err := authRepo.Get(message.User)
	render.Check(err, w)

	render.Render(w, r, "message", map[string]interface{}{
		"request": r,
		"message": message,
		"user":    user,
	})
}
Esempio n. 10
0
// RegisterHandler registers a new user
func RegisterHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		name := strings.TrimSpace(r.FormValue("name"))
		email := strings.TrimSpace(r.FormValue("email"))
		password := r.FormValue("password")

		// If email or password are blank then redirect to register page
		// TODO: provide a sensible error to people so they understand what
		// they did wrong.
		if email == "" || password == "" {
			render.Redirect(w, r, "/register")
			return
		}

		// Check to see if person already exists by attempting to log them in.
		passwordHash := crypto.PasswordHash(password)
		user, err := Authenticate(email, password, w, r)

		// If they do exist, redirect them home else create a new user and
		// log them into the site.
		if user != nil {
			render.Redirect(w, r, "/")
			return
		}

		key := crypto.UniqueHash(name)
		user = &User{Key: key, Name: name, Email: email, Password: passwordHash}
		err = repo.Insert(user)
		render.Check(err, w)

		// Auth user and redirect them
		user, _ = Authenticate(email, password, w, r)
		render.Redirect(w, r, "/")
		return
	}

	render.Render(w, r, "auth_register", nil)
}
Esempio n. 11
0
// EditHandler handles editing of rooms
func EditHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	hash := vars["hash"]

	u, _ := auth.GetAuthenticatedUser(r)

	users, err := userRepo.List(100)
	render.Check(err, w)

	room, err := repo.Load(hash)
	render.Check(err, w)

	members, err := roomMemberRepo.ListMembers(room.Hash)
	render.Check(err, w)

	render.Render(w, r, "room_form", map[string]interface{}{
		"request": r,
		"room":    room,
		"users":   users,
		"members": members,
		"user":    u,
	})
}
Esempio n. 12
0
func roomHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	hash := vars["hash"]

	userHash, _ := auth.GetAuthenticatedUserKey(r)

	room, err := roomRepo.Load(hash)
	render.Check(err, w)

	// If this is a private one-on-one room check whether the logged
	// in user is part of that room. If not, then they shouldn't be
	// able to view this room.
	if room.Kind == rooms.OneOnOne {
		_, err := roomMemberRepo.Load(room.Hash, userHash)
		if err != nil {
			render.Redirect(w, r, "/")
			return
		}
	}

	messages, err := messageRepo.List(hash, 20)
	render.Check(err, w)

	members, err := roomMemberRepo.ListMembers(room.Hash)
	render.Check(err, w)

	isMember, _ := roomMemberRepo.Load(room.Hash, userHash)

	render.Render(w, r, "room", map[string]interface{}{
		"request":  r,
		"room":     room,
		"messages": messages,
		"members":  members,
		"isMember": isMember,
	})
}