コード例 #1
0
ファイル: utils.go プロジェクト: Chandler/goflesh
func InsertTestUser() *models.User {
	first_name := GenerateWord().(string)
	last_name := GenerateWord().(string)
	sep := "."
	screen_name_long := first_name + sep + last_name
	screen_name := screen_name_long[:int(math.Min(20, float64(len(screen_name_long))))]
	email := screen_name + "@gmail.com"
	user, statusCode, err := models.NewUser(email, first_name, last_name, screen_name, "", "password")
	if err != nil {
		revel.WARN.Print(statusCode, err)
	}
	return user
}
コード例 #2
0
ファイル: user.go プロジェクト: Chandler/goflesh
func (c *Users) Create() revel.Result {
	data, err := ioutil.ReadAll(c.Request.Body)
	if err != nil {
		return c.RenderError(err)
	}

	const keyName string = "users"
	var typedJson map[string][]*models.User

	err = json.Unmarshal(data, &typedJson)
	if err != nil {
		c.Response.Status = 400
		return c.RenderError(err)
	}

	users := typedJson[keyName]

	for i, user := range users {
		insertedUser, statusCode, err := models.NewUser(
			user.Email,
			user.First_name,
			user.Last_name,
			user.Screen_name,
			*user.Phone,
			user.Password,
		)
		if err != nil {
			c.Response.Status = statusCode
			return c.RenderError(err)
		}
		insertedUser.CleanSensitiveFields(false)
		users[i] = insertedUser
	}

	return c.RenderJson(users)
}