Ejemplo n.º 1
0
func (s *Service) GetSessionInfo(sessionId string) (si SessionInformation, err error) {
	SessionQuery := bson.M{"sessionid": sessionId}
	db := s.DB.Copy()
	defer db.Close()
	err = db.FindOne("sessions", SessionQuery, &si)
	return si, err
}
Ejemplo n.º 2
0
func (u *User) GetById(id interface{}) error {
	db := u.DB.Copy()
	defer db.Close()

	query := bson.M{"id": id}
	err := db.FindOne("users", query, &u)
	return err
}
Ejemplo n.º 3
0
func (s *Service) RemoveAllSession() int {
	db := s.DB.Copy()
	defer db.Close()
	removed, err := s.DB.RemoveCollection("sessions", bson.M{"lastupdatedtime": bson.M{"$lt": time.Now()}})
	if err != nil {
		log.Fatal(err)
	}
	return removed
}
Ejemplo n.º 4
0
func (s *Service) UpsertSession(sessionId string) {
	si := SessionInformation{}
	si.LastUpdatedTime = time.Now()
	si.SessionId = sessionId
	db := s.DB.Copy()
	defer db.Close()
	err := db.UpsertSession("sessions", bson.M{"sessionid": sessionId}, si)
	if err != nil {
		log.Fatal(err)
	}
}
Ejemplo n.º 5
0
func Create(c martini.Context, sessionService *Service, r render.Render, re *http.Request, loginForm LoginForm, f *fishhub.DBService, session sessions.Session) {
	db := f.DB.Copy()
	defer db.Close()
	userProfile := &user.User{}

	query := bson.M{"userid": loginForm.UserId, "password": loginForm.Password}
	err := db.FindOne("users", query, userProfile)
	fmt.Println(query)
	if err != nil {
		r.JSON(401, map[string]interface{}{
			"message":        "Unauthorized error",
			"classification": "UnauthorizedError",
		})
		return
	}
	session.Set("userid", userProfile.UserId)
	r.JSON(200, userProfile)

	sessionService.UpsertSession(userProfile.UserId)
	c.Map(userProfile)
	return
}