Пример #1
0
func GetUserByToken(token string) Domain.User {
	collection := DAO.Collection("User")
	user := Domain.User{}
	collection.Find(bson.M{
		"token": token,
	}).One(&user)
	return user
}
Пример #2
0
func AddUser(user Domain.User) {
	user.Token = ""
	user.Forms = []Domain.Form{}
	user.Password = Hash(user.Password)

	collection := DAO.Collection("User")
	collection.Insert(user)
}
Пример #3
0
func GetPrivateKey() string {
	collection := DAO.Collection("Keys")

	private := bson.M{}
	collection.Find(bson.M{
		"name": "private",
	}).One(&private)

	result, ok := private["value"].(string)
	if ok {
		return result
	} else {
		return ""
	}
}
Пример #4
0
func GetPublicKey() string {
	collection := DAO.Collection("Keys")

	public := bson.M{}
	collection.Find(bson.M{
		"name": "public",
	}).One(&public)

	result, ok := public["value"].(string)
	if ok {
		return result
	} else {
		return ""
	}
}
Пример #5
0
func Login(email string, password string) string {
	password = Hash(password)
	collection := DAO.Collection("User")
	count, _ := collection.Find(bson.M{
		"email":    email,
		"password": password,
	}).Count()
	if count != 1 {
		return ""
	}

	token := Hash(time.Now().String() + password)
	collection.Update(bson.M{
		"email":    email,
		"password": password,
	}, bson.M{"$set": bson.M{
		"token": token,
	}})

	return token
}
Пример #6
0
func AddForm(user Domain.User, form Domain.Form) {
	collection := DAO.Collection("User")
	collection.Update(user, bson.M{"$set": bson.M{
		"forms": append(user.Forms, form),
	}})
}
Пример #7
0
func RemoveUser(user Domain.User) {
	collection := DAO.Collection("User")
	collection.Remove(user)
}