Esempio n. 1
0
func (rcv *controller) serve() {
	rcv.formUser = &account{Controller: rcv.Controller}
	rcv.loggedUser = auth.GetSignedInUser(rcv.Request)
	rcv.SetTitle("text03", rcv.loggedUser.Name)

	switch rcv.Request.Method {
	case "GET":
		rcv.get()
	case "POST":

		errs := rcv.put()
		if errs == nil {
			auth.SignOut(rcv.Response, rcv.Request)
			return

		}

		for _, e := range errs {
			rcv.AppendError(e)
		}
		rcv.get()

	}
	rcv.Render()
}
Esempio n. 2
0
func (rcv *account) Validate(r *http.Request, errs binding.Errors) binding.Errors {

	// Get signed in user
	loggedUser := auth.GetSignedInUser(r)

	if rcv.Name == loggedUser.Name && rcv.Email == loggedUser.Email {
		errs = append(errs, binding.Error{
			FieldNames:     []string{"Name"},
			Classification: "NameError",
			Message:        rcv.Translate("text14"),
		})

		return errs
	}

	// Validate if the same name
	if rcv.Name != loggedUser.Name {
		if rcv.Name == "" {
			errs = append(errs, binding.Error{
				FieldNames:     []string{"Name"},
				Classification: "EmptyError",
				Message:        rcv.Translate("text01"),
			})
		} else if err := maccount.ValidateName(rcv.Name, rcv.Local); err != nil {
			errs = append(errs, binding.Error{
				FieldNames:     []string{"Name"},
				Classification: "NameError",
				Message:        err.Error(),
			})
		}
	}

	if rcv.Email != loggedUser.Email {
		if rcv.Email == "" {
			errs = append(errs, binding.Error{
				FieldNames:     []string{"Email"},
				Classification: "EmptyError",
				Message:        rcv.Translate("text02"),
			})
		} else if err := maccount.ValidateEmail(rcv.Email, rcv.Local); err != nil {
			errs = append(errs, binding.Error{
				FieldNames:     []string{"Email"},
				Classification: "EmailError",
				Message:        err.Error(),
			})
		}
	}

	return errs
}
Esempio n. 3
0
func (rcv *controller) serve() {

	rcv.loggedUser = auth.GetSignedInUser(rcv.Request)
	rcv.SetTitle("text02", rcv.loggedUser.Name)

	switch rcv.Request.Method {
	case "POST":
		auth.SignOut(rcv.Response, rcv.Request)
		if err := rcv.delete(); err != nil {
			rcv.SetFlash("E", "text20")
			rcv.Redirect("/", 303)
			return
		}
		rcv.SetFlash("I", "text21")
		rcv.Redirect("/", 303)
	}

}
Esempio n. 4
0
// If the user is signed in, it will
// the signed in user in the navbar
func (rcv *Controller) renderLoggedUser() string {
	buf := new(bytes.Buffer)

	tp, err := gotext.New("Logged").Parse(authenCache)
	if err != nil {
		panic(err)
	}
	//signed, user := logged.IsAuthenticated(rcv.Request, rcv.Response)
	user := auth.GetSignedInUser(rcv.Request)
	data := struct {
		//Signed bool
		User *account.SignedUser
	}{
		//signed,
		user,
	}

	err = tp.Execute(buf, data)
	if err != nil {
		panic(err)
	}

	return buf.String()
}
Esempio n. 5
0
func (rcv *controller) get() error {
	signedUser := auth.GetSignedInUser(rcv.Request)
	rcv.SetTitle("text12", signedUser.Name)
	rcv.RenderContentPart(viewTmpl, signedUser)
	return nil
}