Esempio n. 1
0
func (h *HighLev) ownLev() (int, bool) {
	verbL, ok := jsonp.Get(h.nouns, fmt.Sprintf("%v.verbs.%v.ownLevel", h.desc.Sentence.Noun, h.desc.Sentence.Verb))
	if ok {
		return numcon.IntP(verbL), true
	}
	nounL, ok := jsonp.GetM(h.nouns, fmt.Sprintf("%v.ownLevel", h.desc.Sentence.Noun))
	if ok {
		return numcon.IntP(nounL), true
	}
	return 0, false
}
Esempio n. 2
0
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
}
Esempio n. 3
0
func igniteReadOps(session *mgo.Session, db *mgo.Database, boots_opt map[string]interface{}, inp map[string][]string) (map[string]interface{}, string, error) {
	if session == nil {
		return nil, "", fmt.Errorf("This is not an admin instance.")
	}
	r := newSiteRules()
	dat, err := extract.New(r).Extract(inp)
	if err != nil {
		return nil, "", err
	}
	// Need to check it here too, not just at admin_model.RegFirstAdmin!
	if dat["password"].(string) != dat["password_again"].(string) {
		return nil, "", fmt.Errorf("Passwords do not match.")
	}
	max_cap := numcon.IntP(boots_opt["max_cap"])
	hasroom, err := hasRoom(db, max_cap)
	if err != nil {
		return nil, "", err
	}
	if !hasroom {
		return nil, "", fmt.Errorf("Server is at full capacity.")
	}
	sitename := dat["sitename"].(string)
	root_db := boots_opt["root_db"].(string)
	if sitename == root_db || strings.HasPrefix(sitename, "www") {
		return nil, "", fmt.Errorf("Sitename cant equal to root sitename or start with www.")
	}
	default_must := boots_opt["default_must"].(bool)
	def_opts, err := defaultOpts(db)
	if default_must && err != nil {
		return nil, "", fmt.Errorf("Cant read default option document.")
	}
	return def_opts, sitename, sitenameIsOk(db, sitename)
}
Esempio n. 4
0
// Similar to OkayToDoAction but it works directly on the auth_options map.
func AuthAction(uni *context.Uni, auth_options map[string]interface{}) (error, error) {
	err := UserAllowed(uni, auth_options)
	if err != nil {
		return err, nil
	}
	user_level := scut.Ulev(uni.Dat["_user"])
	no_puzzles_lev := numcon.IntP(auth_options["no_puzzles_lev"])
	var hot_reg int
	if val, has := auth_options["hot_reg"]; has {
		hot_reg = numcon.IntP(val)
	}
	var puzzle_err error
	if user_level < no_puzzles_lev {
		puzzle_err = SolvePuzzles(uni, auth_options)
	}
	if user_level == 0 && ((puzzle_err == nil && hot_reg >= 1) || (puzzle_err != nil && hot_reg == 2)) {
		err = RegLoginBuild(uni, puzzle_err == nil)
	}
	return err, puzzle_err
}
Esempio n. 5
0
File: scut.go Progetto: Laller/chill
// Gives back the user level.
func Ulev(useri interface{}) int {
	if useri == nil {
		return 0 // useri should never be nil BTW
	}
	user := useri.(map[string]interface{})
	ulev, has := user["level"]
	if !has {
		return 0
	}
	return numcon.IntP(ulev)
}
Esempio n. 6
0
func (h *H) BeforeDisplay() {
	uni := h.uni
	opt, has := jsonp.GetM(uni.Opt, "Modules.bootstrap")
	if !has {
		return
	}
	count, err := bm.SiteCount(uni.Db)
	if err != nil {
		return
	}
	max_cap := numcon.IntP(opt["max_cap"])
	ratio := float64(count) / float64(max_cap)
	perc := float64(ratio * 100)
	uni.Dat["capacity_percentage"] = perc
}
Esempio n. 7
0
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
}