Пример #1
0
// SetupApp allows the creation of a admin account if no accounts exist.
func SetupApp(c echo.Context) error {
	db := ToDB(c)
	accts, err := db.GetAccountList()
	if len(accts) > 0 || err != nil {
		return ErrForbidden.Log(err, fmt.Sprintf("total accounts: %s", len(accts)))
	}

	p := &Setup{}
	if err := c.Bind(p); err != nil {
		return ErrBind.Log(err)
	}

	p.IsAdmin = true
	if err := db.InsertPerson(&p.Person); err != nil {
		return ErrSaving.Log(err)
	}

	u, _ := model.NewAccountFor(p.PersonID, p.Email)
	if err := u.SetPassword(p.Password); err != nil {
		return ErrPasswordSimple.Log(err)
	}

	u.SetActive()

	if err := db.InsertAccount(u); err != nil {
		return ErrSaving.Log(err)
	}

	return c.NoContent(http.StatusCreated)
}
Пример #2
0
func (s *Store) EnsureAdmin() {

	accts, err := s.GetAccountList()
	if err != nil {
		log.Fatal("error retrieving accounts: ", err)
	}

	if len(accts) > 0 {
		return
	}

	p := &model.Person{
		FirstName: "admin",
	}

	if err := s.InsertPerson(p); err != nil {
		log.Fatal(err)
	}

	u, _ := model.NewAccountFor(p.PersonID, "*****@*****.**")
	if err := u.SetPassword("admin123"); err != nil {
		log.Fatal(err)
	}

	u.SetActive()

	if err := s.InsertAccount(u); err != nil {
		log.Fatal(err)
	}

	log.Println("created default admin account")

}
Пример #3
0
func CreateAccount(c echo.Context) error {
	a := &model.Account{}
	if err := c.Bind(a); err != nil {
		return ErrBind.Log(err)
	}

	na, err := model.NewAccountFor(a.PersonID, a.Email)
	if err != nil {
		return ErrServerError.Log(err)
	}

	db := ToDB(c)
	if err := db.InsertAccount(na); err != nil {
		return ErrSaving.Log(err)
	}

	return c.JSON(http.StatusCreated, na)
}