Exemplo n.º 1
0
func (e *Entries) othersAlreadyTook(a iface.Filter, from, to int64) error {
	entryQ := map[string]interface{}{
		"$or": []interface{}{
			map[string]interface{}{
				"from": map[string]interface{}{
					"$gt": from,
					"$lt": to,
				},
			},
			map[string]interface{}{
				"to": map[string]interface{}{
					"$gt": from,
					"$lt": to,
				},
			},
		},
	}
	a.AddQuery(entryQ)
	eC, err := a.Count()
	if err != nil {
		return err
	}
	if eC > 0 {
		return fmt.Errorf("That time is already taken.")
	}
	return nil
}
Exemplo 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
}
Exemplo n.º 3
0
func FindLogin(a iface.Filter, name, password string) (iface.Document, error) {
	encoded_pass := hashPass(password)
	q := map[string]interface{}{
		"name":     name,
		"password": encoded_pass,
	}
	return a.AddQuery(q).SelectOne()
}
Exemplo n.º 4
0
// This way professionals will only see entries posted for them,
// and users will only see entries posted by them.
// However, a professional will not be able to act as a user: he wont see entries posted by him, posted for other professionals.
func (e *Entries) TopModFilter(a iface.Filter) {
	if e.userIsProfessional {
		a.AddQuery(map[string]interface{}{
			"forProfessional": e.userId,
		})
	} else {
		a.AddQuery(map[string]interface{}{
			"createdBy": e.userId,
		})
	}
}
Exemplo n.º 5
0
func (tt *TimeTable) TopModFilter(a iface.Filter) {
	if tt.userIsProfessional {
		a.AddQuery(map[string]interface{}{
			"createdBy": tt.userId,
		})
	} else {
		a.AddQuery(map[string]interface{}{
			// Hehe.
			"clientsShouldNotViewTimeTables": true,
		})
	}
}
Exemplo n.º 6
0
func hasAdmin(f iface.Filter) error {
	q := map[string]interface{}{
		"level": 300,
	}
	f.AddQuery(q)
	c, err := f.Count()
	if err != nil {
		return err
	}
	if c > 0 {
		return fmt.Errorf("Site already has an admin.")
	}
	return nil
}