예제 #1
0
func helperCreateUser() *chatable.User {
	u := chatable.NewUser(testUserFirst, testUserLast, testUsername,
		testUserPass, testUserEmail, testUserPhoneNumber,
		testUserIP)
	if err := store.UserStore.Create(u); err != nil {
		return nil
	} else {
		return u
	}
}
예제 #2
0
파일: users.go 프로젝트: wujiang/chatable
func serveCreateUser(w http.ResponseWriter, r *http.Request) chatable.CompoundError {
	if err := r.ParseForm(); err != nil {
		return chatable.NewServerError(err.Error())
	}
	valid := usersForm.Valid(r.PostForm)
	if !valid {
		return usersForm.ConsolidateErrors()
	}
	u := chatable.NewUser(usersForm.Values["first_name"].(string),
		usersForm.Values["last_name"].(string),
		usersForm.Values["username"].(string),
		usersForm.Values["password"].(string),
		usersForm.Values["email"].(string),
		usersForm.Values["phone"].(string),
		r.RemoteAddr)
	err := store.UserStore.Create(u)
	// TODO: refine the error message
	if err != nil {
		msg := err.Error()
		if strings.Contains(msg, "violates") {
			return chatable.NewUserError("Some fileds are not unique")
		}
		return chatable.NewServerError(msg)
	}
	// create a auth token
	token, err := createNewAuthToken(w, r, u)
	if err != nil {
		return chatable.NewServerError(err.Error())
	}
	data := []chatable.UserWithToken{
		chatable.UserWithToken{
			FirstName:   u.FirstName,
			LastName:    u.LastName,
			Username:    u.Username,
			Email:       u.Email,
			PhoneNumber: u.PhoneNumber,
			Token:       *token,
		},
	}
	return writeJSON(w, chatable.NewJSONResult(data, 1))
}
예제 #3
0
	testSenderEmail    = "*****@*****.**"
	testSenderPhone    = "1234567890"
	testIPAddr         = "0.0.0.0"
	testPassword       = "******"
	testRecipientFirst = "Recipient"
	testRecipientLast  = "Receive"
	testRecipientUname = "recipient"
	testRecipientEmail = "*****@*****.**"
	testRecipientPhone = "0123456789"
)

var (
	testStore = NewDataStore(nil)

	testSender = chatable.NewUser(testSenderFirst, testSenderLast,
		testSenderUname, testPassword, testSenderEmail,
		testSenderPhone, testIPAddr)
	testRecipient = chatable.NewUser(testRecipientFirst, testRecipientLast,
		testRecipientUname, testPassword, testRecipientEmail,
		testRecipientPhone, testIPAddr)
)

func newTestUsers() error {
	if err := testStore.UserStore.Create(testSender); err != nil {
		return err
	}
	if err := testStore.UserStore.Create(testRecipient); err != nil {
		return err
	}
	return nil
}