示例#1
0
文件: user.go 项目: Laller/nocrud
// When no user cookie is found, or there was a problem during building the user,
// we proceed with an empty user.
func emptyUser(client iface.Client) *User {
	langs := client.Languages()
	if langs == nil {
		langs = []string{"en"}
	}
	return &User{
		nil,
		0,
		langs,
	}
}
示例#2
0
文件: user.go 项目: Laller/nocrud
func _new(db iface.Db, f iface.Filter, hooks iface.Hooks, client iface.Client) (*User, error) {
	uidI, err := client.GetDecrypted("user")
	if err != nil {
		return nil, err
	}
	id, err := db.ToId(uidI.(string))
	if err != nil {
		return nil, err
	}
	q := map[string]interface{}{
		"_id": id,
	}
	f.AddQuery(q)
	userDoc, err := f.SelectOne()
	if err != nil {
		return nil, err
	}
	var langs []string
	if langz, ok := userDoc.Data()["languages"].([]interface{}); ok {
		for _, v := range langz {
			langs = append(langs, v.(string))
		}
	} else if client.Languages() != nil {
		langs = client.Languages()
	} else {
		langs = []string{"en"}
	}
	return &User{
		userDoc,
		numcon.IntP(userDoc.Data()["level"]),
		langs,
	}, nil
}
示例#3
0
文件: user.go 项目: crufter/nocrud
func _new(db iface.Db, client iface.Client) (*User, error) {
	uidI, err := client.GetDecrypted("user")
	if err != nil {
		return nil, err
	}
	uidStr := uidI.(string)
	coll := "users"
	spl := strings.Split(uidStr, "|")
	if len(spl) > 1 {
		coll = spl[0]
		uidStr = spl[1]
	}
	f, err := db.NewFilter(coll, nil)
	if err != nil {
		return nil, err
	}
	id, err := db.ToId(uidStr)
	if err != nil {
		return nil, err
	}
	q := map[string]interface{}{
		"_id": id,
	}
	f.AddQuery(q)
	userDoc, err := f.SelectOne()
	if err != nil {
		return nil, err
	}
	var langs []string
	if langz, ok := userDoc.Data()["languages"].([]interface{}); ok {
		for _, v := range langz {
			langs = append(langs, v.(string))
		}
	} else if client.Languages() != nil {
		langs = client.Languages()
	} else {
		langs = []string{"en"}
	}
	return &User{
		userDoc,
		numcon.IntP(userDoc.Data()["level"]),
		langs,
	}, nil
}