Ejemplo n.º 1
0
func (self *User) SignUp(params *ess.Command) error {
	err := ess.NewValidationError()

	if self.signedUp {
		err.Add("username", "not_unique")
	}

	if err.Ok() {
		self.events.PublishEvent(
			ess.NewEvent("user.signed-up").
				For(self).
				Add("username", params.Get("username").String()).
				Add("password", params.Get("password").String()).
				Add("email", params.Get("email").String()),
		)
	}

	return err.Return()
}
Ejemplo n.º 2
0
func (self *User) HandleCommand(command *ess.Command) error {
	switch command.Name {
	case "sign-up":
		return self.SignUp(command)
	case "login":
		return self.Login(command.Get("session").String(), command.Get("password").(*ess.BcryptedPassword))
	case "logout":
		return self.Logout(command.Get("session").String())
	}
	return nil
}
Ejemplo n.º 3
0
func (self *User) HandleCommand(command *ess.Command) error {
	switch command.Name {
	case "sign-up":
		return self.SignUp(
			command.Get("name").String(),
			command.Get("email").String(),
			command.Get("password").String(),
		)
	}

	return nil
}
Ejemplo n.º 4
0
func ShowEditPostFormError(w http.ResponseWriter, params *ess.Command, err error) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	NewHTMLDocument("Edit Post",
		EditPostForm.
			Fill(params, err).
			Action("/posts/"+params.AggregateId()+"/edit").
			Param("id", params.AggregateId()).
			Param("username", params.Get("username").String()).
			ToHTML("Edit post"),
	).WriteHTML(w, "", "  ")

}
Ejemplo n.º 5
0
func NewUserFromCommand(command *ess.Command) ess.Aggregate {
	return NewUser(command.Get("username").String())
}
Ejemplo n.º 6
0
func UserFromCommand(params *ess.Command) ess.Aggregate {
	return NewUser(params.Get("username").String())
}
Ejemplo n.º 7
0
func PostFromCommand(params *ess.Command) ess.Aggregate {
	return NewPost(params.AggregateId())
}
Ejemplo n.º 8
0
func (self *Post) HandleCommand(command *ess.Command) error {
	switch command.Name {
	case "write-post":
		return self.Write(
			command.Get("title").String(),
			command.Get("body").String(),
			command.Get("username").String(),
		)
	case "edit-post":
		return self.Edit(
			command.Get("title").String(),
			command.Get("body").String(),
			command.Get("reason").String(),
			command.Get("username").String(),
		)
	}

	return nil
}