当前位置: 首页>>代码示例>>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;未经允许,请勿转载。