func (self *AuthorityResource) Get(ctx *rfweb.Context) { res := RespData{} id := ctx.Get("id") if id == "all" { authoritys, err := auth.GetAllAuthority() if err != nil { res.Error = err.Error() } else { res.Success = true res.Data = authoritys } } else if id != "" { authority, err := auth.GetAuthorityByID(id) if err != nil { res.Error = err.Error() } else { res.Success = true res.Data = authority } } else { email := ctx.Get("email") if email != "" { authority, err := auth.GetAuthorityByEmail(email) if err != nil { res.Error = err.Error() } else { res.Success = true res.Data = authority } } } util.WriteJson(ctx.W, res) }
// delete role func (self *RoleResource) Delete(ctx *rfweb.Context) { res := RespData{} id := ctx.Get("id") if len(id) < 1 { res.Error = "no id" } else { err := auth.DeleteRole(id) if err == nil { res.Success = true res.Data = id } else { res.Error = err.Error() } } util.WriteJson(ctx.W, res) }
func (self *RoleResource) Get(ctx *rfweb.Context) { res := RespData{} id := ctx.Get("id") if id == "all" { roles, err := auth.GetAllRole() if err != nil { res.Error = err.Error() } else { res.Success = true res.Data = roles } } else { role, err := auth.GetRoleByID(id) if err != nil { res.Error = err.Error() } else { res.Success = true res.Data = role } } util.WriteJson(ctx.W, res) }
func (self *UserResource) Get(ctx *rfweb.Context) { res := RespData{} email := ctx.Get("email") if email == "all" { users, err := auth.GetAllUsers() if err != nil { res.Error = err.Error() } else { res.Success = true res.Data = users } } else { user, err := auth.GetUserByEmail(email) if err != nil { res.Error = err.Error() } else { res.Success = true res.Data = user } } util.WriteJson(ctx.W, res) }
func (self *BackendConfResource) Get(ctx *rfweb.Context) { res := RespData{} hostname := ctx.Get("hostname") if hostname == "all" { bcs, err := bkconf.GetAll() if err != nil { res.Error = err.Error() } else { res.Success = true res.Data = bcs } } else { bc, err := bkconf.Get(hostname) if err != nil { res.Error = err.Error() } else { res.Success = true res.Data = bc } } util.WriteJson(ctx.W, res) }
func (self LoginResource) Post(ctx *rfweb.Context) { res := RespData{} email := strings.ToLower(ctx.Get("email")) email = strings.TrimSpace(email) pwd := strings.TrimSpace(ctx.Get("pwd")) // remember := ctx.Get("remember") user, err := auth.LoginUser(email, pwd) if err != nil { res.Error = err.Error() } else { res.Success = true // res.Data = ctx.Get("returnurl") session := ctx.Session() session.SetStuct(constant.SS_KEY_USER, user) } util.WriteJson(ctx.W, res) }
func (self *LogoutResource) Get(ctx *rfweb.Context) { session := ctx.Session() session.Clear(ctx.W) redirectToLogin(ctx.W, ctx.R, false) }