Пример #1
0
// create creates a new user in the system.
func (u userAdminForm) create(request *http.Request) error {
	err := request.ParseForm()

	if err != nil {
		return err
	}

	decoder := schema.NewDecoder()
	form := new(userAdminForm)

	err = decoder.Decode(form, request.PostForm)

	if err != nil {
		return err
	}

	_, err = database.CreateUser(
		form.Email,
		form.FirstName,
		form.LastName,
		form.Password,
		form.Admin,
	)

	return err
}
Пример #2
0
func (c configForm) save(request *http.Request) (*database.User, error) {
	err := request.ParseForm()

	if err != nil {
		return nil, err
	}

	decoder := schema.NewDecoder()
	form := new(configForm)

	err = decoder.Decode(form, request.PostForm)

	if err != nil {
		return nil, err
	}

	user, err := database.CreateUser(
		form.Email,
		form.FirstName,
		form.LastName,
		form.Password,
		true,
	)

	if err != nil {
		return nil, err
	}

	database.AddConfig(
		form.Secret,
		form.URL,
		form.SSLCert,
		form.SSLKey,
	)

	database.AddMailServer(
		form.Host,
		form.Sender,
		form.SMTPUser,
		form.SMPTPassword,
		form.Port,
	)

	return user, nil
}