示例#1
0
文件: user.go 项目: cmdrkeene/ess
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()
}
示例#2
0
文件: user.go 项目: cmdrkeene/ess
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
}
示例#3
0
文件: main.go 项目: cmdrkeene/ess
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
}
示例#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, "", "  ")

}
示例#5
0
文件: main.go 项目: cmdrkeene/ess
func NewUserFromCommand(command *ess.Command) ess.Aggregate {
	return NewUser(command.Get("username").String())
}
示例#6
0
文件: main.go 项目: cmdrkeene/ess
func UserFromCommand(params *ess.Command) ess.Aggregate {
	return NewUser(params.Get("username").String())
}
示例#7
0
文件: main.go 项目: cmdrkeene/ess
func PostFromCommand(params *ess.Command) ess.Aggregate {
	return NewPost(params.AggregateId())
}
示例#8
0
文件: post.go 项目: cmdrkeene/ess
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
}