Exemplo n.º 1
0
func (l *LoginController) Logout(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson
	sessionId := toolkit.ToString(r.Session("sessionid", ""))
	if toolkit.ToString(sessionId) == "" {
		return helper.CreateResult(true, nil, "Active sessionid not found")
	}

	err := acl.Logout(sessionId)
	if err != nil && (err.Error() == "Session id not found" || err.Error() == "Session id is expired") {
		return helper.CreateResult(true, nil, "Active sessionid not found")
	} else if err != nil {
		return helper.CreateResult(true, nil, toolkit.Sprintf("Error found : %v", err.Error()))
	}

	r.SetSession("sessionid", "")

	return helper.CreateResult(true, nil, "Logout success")
}
Exemplo n.º 2
0
func (a *AclController) Logout(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := toolkit.M{}
	err := r.GetPayload(&payload)
	sessionid := ""
	switch {
	case err != nil:
		return helper.CreateResult(false, nil, err.Error())
	case !payload.Has("username") && !payload.Has("sessionid"):
		return helper.CreateResult(false, nil, "username or session not found")
	case payload.Has("sessionid"):
		sessionid = toolkit.ToString(payload["sessionid"])
	case payload.Has("username"):
		tUser := new(acl.User)
		err = acl.FindUserByLoginID(tUser, toolkit.ToString(payload["username"]))
		if err != nil {
			return helper.CreateResult(false, nil, "fail to get userid")
		}

		tSession := new(acl.Session)
		err = acl.FindActiveSessionByUser(tSession, tUser.ID)
		if err != nil {
			return helper.CreateResult(false, nil, "fail to get sessionid")
		}
		sessionid = tSession.ID
	}

	if sessionid == "" {
		return helper.CreateResult(true, nil, "Active sessionid not found")
	}

	err = acl.Logout(sessionid)
	if err != nil && (err.Error() == "Session id not found" || err.Error() == "Session id is expired") {
		return helper.CreateResult(true, nil, "Active sessionid not found")
	} else if err != nil {
		return helper.CreateResult(true, nil, toolkit.Sprintf("Error found : %v", err.Error()))
	}

	return helper.CreateResult(true, nil, "Logout success")
}