當前位置: 首頁>>代碼示例>>Golang>>正文


Golang sessionauth.User類代碼示例

本文整理匯總了Golang中github.com/martini-contrib/sessionauth.User的典型用法代碼示例。如果您正苦於以下問題:Golang User類的具體用法?Golang User怎麽用?Golang User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了User類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getLoginPage

func getLoginPage(user sessionauth.User, r render.Render) {
	if user.IsAuthenticated() {
		r.Redirect(INDEX_PAGE)
		return
	}
	r.HTML(200, LOGIN_PAGE, nil)
}
開發者ID:jmptrader,項目名稱:chatgo,代碼行數:7,代碼來源:user.go

示例2: getRegisterPage

func getRegisterPage(user sessionauth.User, r render.Render) {
	if user.IsAuthenticated() {
		r.Redirect(INDEX_PAGE)
		return
	}
	r.HTML(200, REGISTER_PAGE, nil)
}
開發者ID:jmptrader,項目名稱:chatgo,代碼行數:7,代碼來源:user.go

示例3: IsAuthenticated

func IsAuthenticated(enc Encoder, user sessionauth.User, db gorp.SqlExecutor) (int, string) {

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {
		return http.StatusOK, ""
	}

	return http.StatusUnauthorized, Must(enc.EncodeOne(user))
}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:10,代碼來源:user.go

示例4: GetAuthenticatedUser

func GetAuthenticatedUser(enc Encoder, user sessionauth.User, db gorp.SqlExecutor) (int, string) {

	if user.IsAuthenticated() {

		authUser := UserById(user.UniqueId().(int), db)

		return http.StatusOK, Must(enc.EncodeOne(authUser))
	}

	return http.StatusUnauthorized, Must(enc.EncodeOne(user))
}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:11,代碼來源:user.go

示例5: GetMessagesStats

func GetMessagesStats(enc Encoder, db gorp.SqlExecutor, user sessionauth.User) (int, string) {

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {
		var messages []models.Messages

		_, err := db.Select(&messages, SQL_MESSAGES_ALL)
		if err != nil {
			checkErr(err, "select failed")
			return http.StatusBadRequest, ""
		}

		return http.StatusOK, Must(enc.Encode(messagesToIfaceM(messages)...))
	}

	return http.StatusUnauthorized, ""
}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:18,代碼來源:messages.go

示例6: GetUserById

func GetUserById(enc Encoder, db gorp.SqlExecutor, user sessionauth.User, parms martini.Params) (int, string) {

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {
		id, err := strconv.Atoi(parms["id"])

		if err != nil {
			return http.StatusNotFound, ""
		}

		entity := UserById(id, db)

		return http.StatusOK, Must(enc.EncodeOne(entity))
	}

	return http.StatusUnauthorized, ""
}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:18,代碼來源:user.go

示例7: GetWarningDetail

func GetWarningDetail(enc Encoder, db gorp.SqlExecutor, user sessionauth.User, parms martini.Params) (int, string) {

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {

		id, err := strconv.Atoi(parms["id"])
		obj, _ := db.Get(models.Warning{}, id)
		if err != nil || obj == nil {
			checkErr(err, "GET WARNING DETAIL FAILED")
			// Invalid id, or does not exist
			return http.StatusNotFound, ""
		}
		entity := obj.(*models.Warning)
		return http.StatusOK, Must(enc.EncodeOne(entity))
	}

	return http.StatusUnauthorized, ""

}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:20,代碼來源:warnings.go

示例8: WarnaCounter

// count all warnings registered
func WarnaCounter(enc Encoder, db gorp.SqlExecutor, user sessionauth.User) (int, string) {

	counts := models.CountWarning{}

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {

		err := db.SelectOne(&counts, SQL_WARN_COUNT)
		checkErr(err, "COUNT SENT WARNINGS ERROR")

		if err == nil {
			return http.StatusOK, Must(enc.EncodeOne(counts))
		} else {
			return http.StatusBadRequest, ""
		}

	}

	return http.StatusUnauthorized, ""
}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:22,代碼來源:dashboard.go

示例9: SaveOrUpdateMessage

func SaveOrUpdateMessage(entity models.MessageStruct, enc Encoder, db gorp.SqlExecutor, user sessionauth.User) (int, string) {

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {

		entity.Last_modified_by = user.UniqueId().(int)

		if entity.Id < 1 {
			err := db.Insert(&entity)
			if err != nil {
				checkErr(err, "insert failed")
				return http.StatusBadRequest, ""
			}
		} else {
			obj, _ := db.Get(models.MessageStruct{}, entity.Id)
			if obj == nil {
				// Invalid id, or does not exist
				return http.StatusBadRequest, ""
			}

			_, err := db.Update(&entity)
			if err != nil {
				checkErr(err, "update failed")
				return http.StatusBadRequest, ""
			}
		}

		return http.StatusOK, Must(enc.EncodeOne(entity))

	}

	return http.StatusUnauthorized, ""
}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:34,代碼來源:messages.go

示例10: DoLogout

func DoLogout(enc Encoder, session sessions.Session, user sessionauth.User, db gorp.SqlExecutor) (int, string) {

	status := &models.DefaultStruct{
		Id:       http.StatusOK,
		Name:     messages.GetLocaleMessage("en", "MSG_LOGIN_REQUIRED"),
		Lang_key: "en",
	}

	if user.IsAuthenticated() {

		sessionauth.Logout(session, user)
		session.Clear()
		status.Name = messages.GetLocaleMessage("en", "MSG_SUCCESSFUL_LOGOUT")
	}

	updateUser := UserById(user.UniqueId().(int), db)

	updateUser.Authenticated = false
	db.Update(updateUser)

	return http.StatusOK, Must(enc.EncodeOne(status))
}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:22,代碼來源:user.go

示例11: ListWarnings

func ListWarnings(entity models.Warn, enc Encoder, user sessionauth.User, db gorp.SqlExecutor) (int, string) {

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {
		sql := "SELECT w.id, msg.name AS message, ct.name AS contact_type, w.contact, w.sent, w.created_date FROM warnings AS w "
		sql += "INNER JOIN messages AS msg ON (msg.id = w.id_message) "
		sql += "INNER JOIN contact_types AS ct ON (ct.id = w.id_contact_type) "
		sql += "ORDER BY w.created_date DESC "

		var warns []models.Warn
		_, err := db.Select(&warns, sql)
		checkErr(err, "SELECT ALL WARNINGS ERROR")

		if err != nil {
			return http.StatusBadRequest, ""
		}
		return http.StatusOK, Must(enc.Encode(warnsToIface(warns)...))

	}

	return http.StatusUnauthorized, ""

}
開發者ID:gitter-badger,項目名稱:warnabroda-server,代碼行數:24,代碼來源:dashboard.go


注:本文中的github.com/martini-contrib/sessionauth.User類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。