Example #1
0
package api

import (
	"net/http"
	"strings"

	"github.com/wujiang/chatable"
	"github.com/wujiang/chatable/forms"
)

var usersForm = forms.New()

func init() {
	usersForm.WithField("first_name", new(forms.FieldBuilder).
		Required().
		Loader(forms.StringLoader).
		WithValidators(forms.NameValidator()))
	usersForm.WithField("last_name", new(forms.FieldBuilder).
		Required().
		Loader(forms.StringLoader).
		WithValidators(forms.NameValidator()))
	usersForm.WithField("username", new(forms.FieldBuilder).
		Required().
		Loader(forms.StringLoader).
		WithValidators(forms.UsernameValidator()))
	usersForm.WithField("password", new(forms.FieldBuilder).
		Required().
		Loader(forms.StringLoader).
		WithValidators(forms.PasswordValidator()))
	usersForm.WithField("email", new(forms.FieldBuilder).
		Required().
Example #2
0
package api

import (
	"net/http"
	"strconv"

	"github.com/wujiang/chatable"
	"github.com/wujiang/chatable/auth"
	"github.com/wujiang/chatable/forms"
)

var (
	authTokenForm = forms.New()
)

func init() {
	authTokenForm.WithField("username", new(forms.FieldBuilder).
		Required().
		Loader(forms.StringLoader))
	authTokenForm.WithField("password", new(forms.FieldBuilder).
		Required().
		Loader(forms.StringLoader))
}

// createNewAuthToken creates a new auth token
func createNewAuthToken(w http.ResponseWriter, r *http.Request, u *chatable.User) (*chatable.PublicToken, chatable.CompoundError) {
	// create a new token for the user
	// client_id is on the header
	clientID := r.Header.Get("ClientID")
	cid, err := strconv.Atoi(clientID)
	if err != nil {