本文整理汇总了Golang中github.com/apexskier/httpauth.UserData.Role方法的典型用法代码示例。如果您正苦于以下问题:Golang UserData.Role方法的具体用法?Golang UserData.Role怎么用?Golang UserData.Role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/apexskier/httpauth.UserData
的用法示例。
在下文中一共展示了UserData.Role方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newPost
func (controller *usersController) newPost(rw http.ResponseWriter, req *http.Request) (int, error) {
err := req.ParseForm()
if err != nil {
return http.StatusInternalServerError, err
}
decoder := schema.NewDecoder()
// Ignore unknown keys to prevent errors from the CSRF token.
decoder.IgnoreUnknownKeys(true)
formUser := new(viewmodels.UsersEditViewModel)
err = decoder.Decode(formUser, req.PostForm)
if err != nil {
return http.StatusInternalServerError, err
}
valErrors := validateUserForm(formUser, false)
if len(valErrors) > 0 {
isAuthenticated, user := getCurrentUser(rw, req, controller.authorizer)
vm := viewmodels.NewUserViewModel(formUser, controller.roles, isAuthenticated, user, valErrors)
vm.CsrfField = csrf.TemplateField(req)
return http.StatusOK, controller.newTemplate.Execute(rw, vm)
}
var user httpauth.UserData
user.Username = formUser.Username
user.Email = formUser.Email
password := formUser.Password
user.Role = formUser.Role
err = controller.authorizer.Register(rw, req, user, password)
if err != nil {
return http.StatusInternalServerError, err
}
http.Redirect(rw, req, "/settings/users", http.StatusSeeOther)
return http.StatusSeeOther, nil
}
示例2: adminUsersHandler
func adminUsersHandler(w http.ResponseWriter, r *http.Request, admin Location) {
isAuth(w, r, admin, "admin")
if r.Method == "POST" {
var user httpauth.UserData
user.Username = r.PostFormValue("username")
user.Email = r.PostFormValue("email")
password := r.PostFormValue("password")
user.Role = r.PostFormValue("role")
if err := aaa.Register(w, r, user, password); err != nil {
// maybe something
}
}
if user, err := aaa.CurrentUser(w, r); err == nil {
type data struct {
User httpauth.UserData
Roles map[string]httpauth.Role
Users []httpauth.UserData
Msg []string
}
messages := aaa.Messages(w, r)
users, err := backend.Users()
if err != nil {
panic(err)
}
d := data{User: user, Roles: roles, Users: users, Msg: messages}
var templates = template.Must(template.ParseGlob("admin/templates/*"))
t_err := templates.ExecuteTemplate(w, "manage-accounts.html", d)
if t_err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
示例3: postAddUser
func postAddUser(rw http.ResponseWriter, req *http.Request) {
var user httpauth.UserData
user.Username = req.PostFormValue("username")
user.Email = req.PostFormValue("email")
password := req.PostFormValue("password")
user.Role = req.PostFormValue("role")
if err := aaa.Register(rw, req, user, password); err != nil {
// maybe something
}
http.Redirect(rw, req, "/admin", http.StatusSeeOther)
}