Beispiel #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()
}
Beispiel #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
}
Beispiel #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
}
Beispiel #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, "", "  ")

}
Beispiel #5
0
func NewUserFromCommand(command *ess.Command) ess.Aggregate {
	return NewUser(command.Get("username").String())
}
Beispiel #6
0
func UserFromCommand(params *ess.Command) ess.Aggregate {
	return NewUser(params.Get("username").String())
}
Beispiel #7
0
func PostFromCommand(params *ess.Command) ess.Aggregate {
	return NewPost(params.AggregateId())
}
Beispiel #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
}