Beispiel #1
0
func (self *User) SignUp(name, email, password string) error {
	err := ess.NewValidationError()

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

	if password == "" {
		err.Add("password", "empty")
	}

	if email == "" {
		err.Add("email", "empty")
	}

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

	return err.Return()
}
Beispiel #2
0
func (self *Post) Write(title, body, author string) error {
	err := ess.NewValidationError()

	if self.written {
		err.Add("post", "not_unique")
	}

	if title == "" {
		err.Add("title", "empty")
	}

	if body == "" {
		err.Add("body", "empty")
	}

	if author == "" {
		err.Add("username", "empty")
	}

	if err.Ok() {
		self.events.PublishEvent(
			ess.NewEvent("post.written").
				For(self).
				Add("title", title).
				Add("author", author).
				Add("body", body),
		)
	}

	return err.Return()
}
Beispiel #3
0
func (self *User) Logout(session string) error {
	err := ess.NewValidationError()

	if !self.signedUp {
		err.Add("user", "not_found")
	}

	if session == "" {
		err.Add("session", "empty")
	}

	if !self.HasActiveSession(session) {
		err.Add("session", "expired")
	}

	if err.Ok() {
		self.events.PublishEvent(
			ess.NewEvent("user.logged-out").
				For(self).
				Add("session", session),
		)
	}

	return err.Return()
}
Beispiel #4
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 #5
0
func (self *User) Login(session string, password *ess.BcryptedPassword) error {
	err := ess.NewValidationError()

	if !self.signedUp {
		err.Add("user", "not_found")
	}

	if !password.Matches(self.password) {
		err.Add("password", "mismatch")
	}

	if err.Ok() {
		self.events.PublishEvent(
			ess.NewEvent("user.logged-in").
				For(self).
				Add("session", session),
		)
	}

	return err.Return()
}
Beispiel #6
0
func (self *Post) Edit(title, body, reason, username string) error {
	err := ess.NewValidationError()

	if !self.written {
		err.Add("post", "not_found")
	}

	if title == "" {
		err.Add("title", "empty")
	}

	if body == "" {
		err.Add("body", "empty")
	}

	if username != self.author {
		err.Add("username", "mismatch")
	}

	if reason == "" {
		err.Add("reason", "empty")
	}

	if err.Ok() {
		self.events.PublishEvent(
			ess.NewEvent("post.edited").
				For(self).
				Add("title", title).
				Add("body", body).
				Add("author", username).
				Add("reason", reason),
		)
	}

	return err.Return()
}