Esempio n. 1
0
// 获得当前登录用户
func CurrentUser(req *http.Request) (user map[string]interface{}, succ bool) {

	defer func() {
		// 判断用户是否能登陆
		if !service.IsNormalUser(user["status"]) {
			user, succ = nil, false
		}
	}()

	succ = true

	user = getUser(req)
	if len(user) != 0 {
		return
	}
	session, _ := Store.Get(req, "user")
	username, ok := session.Values["username"]
	if !ok {
		succ = false
		return
	}

	var err error
	user, err = service.FindCurrentUser(username.(string))
	if err != nil {
		succ = false
		return
	}

	setUser(req, user)
	return
}
Esempio n. 2
0
// 获得当前登录用户
func CurrentUser(req *http.Request) (map[string]interface{}, bool) {
	user := getUser(req)
	if len(user) != 0 {
		return user, true
	}
	session, _ := Store.Get(req, "user")
	username, ok := session.Values["username"]
	if !ok {
		return nil, false
	}
	user, err := service.FindCurrentUser(username.(string))
	if err != nil {
		return nil, false
	}
	setUser(req, user)
	return user, true
}