2021-03-13 23:06:03 +08:00
|
|
|
// Copyright 2021 The casbin Authors. All Rights Reserved.
|
2020-10-20 21:57:29 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package controllers
|
|
|
|
|
|
|
|
import "github.com/astaxie/beego"
|
|
|
|
|
|
|
|
type ApiController struct {
|
|
|
|
beego.Controller
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:15:22 +08:00
|
|
|
func (c *ApiController) GetSessionUsername() string {
|
2020-10-20 23:14:03 +08:00
|
|
|
user := c.GetSession("username")
|
|
|
|
if user == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return user.(string)
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:15:22 +08:00
|
|
|
func (c *ApiController) SetSessionUsername(user string) {
|
2020-10-20 23:14:03 +08:00
|
|
|
c.SetSession("username", user)
|
2020-10-20 21:57:29 +08:00
|
|
|
}
|
2021-03-28 00:48:34 +08:00
|
|
|
|
|
|
|
func wrapActionResponse(affected bool) *Response {
|
|
|
|
if affected {
|
2021-03-28 08:59:12 +08:00
|
|
|
return &Response{Status: "ok", Msg: "", Data: "Affected"}
|
2021-03-28 00:48:34 +08:00
|
|
|
} else {
|
2021-03-28 08:59:12 +08:00
|
|
|
return &Response{Status: "ok", Msg: "", Data: "Unaffected"}
|
2021-03-28 00:48:34 +08:00
|
|
|
}
|
|
|
|
}
|