本文整理汇总了Golang中github.com/martini-contrib/sessionauth.User.IsAuthenticated方法的典型用法代码示例。如果您正苦于以下问题:Golang User.IsAuthenticated方法的具体用法?Golang User.IsAuthenticated怎么用?Golang User.IsAuthenticated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/martini-contrib/sessionauth.User
的用法示例。
在下文中一共展示了User.IsAuthenticated方法的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)
}
示例2: getRegisterPage
func getRegisterPage(user sessionauth.User, r render.Render) {
if user.IsAuthenticated() {
r.Redirect(INDEX_PAGE)
return
}
r.HTML(200, REGISTER_PAGE, nil)
}
示例3: 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, ""
}
示例4: 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))
}
示例5: 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))
}
示例6: 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, ""
}
示例7: 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, ""
}
示例8: 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, ""
}
示例9: 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, ""
}
示例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))
}
示例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, ""
}