func (l *LoginController) SavePassword(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := toolkit.M{} err := r.GetPayload(&payload) if err != nil { return helper.CreateResult(false, nil, err.Error()) } if !payload.Has("newpassword") || !payload.Has("userid") { return helper.CreateResult(false, nil, "Data is not complete") } switch { case payload.Has("tokenid"): err = acl.ChangePasswordToken(toolkit.ToString(payload["userid"]), toolkit.ToString(payload["newpassword"]), toolkit.ToString(payload["tokenid"])) default: // check sessionid first savedsessionid := "" //change with get session //======================= userid, err := acl.FindUserBySessionID(savedsessionid) if err == nil && userid == toolkit.ToString(payload["userid"]) { err = acl.ChangePassword(toolkit.ToString(payload["userid"]), toolkit.ToString(payload["newpassword"])) } else if err == nil { err = errors.New("Userid is not match") } } return helper.CreateResult(true, nil, "save password success") }
func (a *UserController) TestFindUserLdap(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := map[string]interface{}{} err := r.GetPayload(&payload) if err != nil { return helper.CreateResult(false, nil, err.Error()) } addr := toolkit.ToString(payload["Address"]) //192.168.0.200:389 basedn := toolkit.ToString(payload["BaseDN"]) //DC=eaciit,DC=local filter := toolkit.ToString(payload["Filter"]) //(&(objectclass=person)(objectclass=organizationalPerson)(cn=*)) var attr []string err = toolkit.Serde(payload["Attribute"], &attr, "json") if err != nil { return helper.CreateResult(true, err, "error") } param := toolkit.M{} param.Set("username", toolkit.ToString(payload["Username"])) //Alip Sidik param.Set("password", toolkit.ToString(payload["Password"])) //Password.1 // param.Set("attributes", []string{"cn", "givenName"}) param.Set("attributes", attr) arrtkm, err := acl.FindDataLdap(addr, basedn, filter, param) if err != nil { return helper.CreateResult(true, err, "error") } return helper.CreateResult(true, arrtkm, "sukses") }
func (l *LoginController) ProcessLogin(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := toolkit.M{} err := r.GetPayload(&payload) switch { case err != nil: return helper.CreateResult(false, nil, err.Error()) case !payload.Has("username") || !payload.Has("password"): return helper.CreateResult(false, nil, "username or password not found") case payload.Has("username") && len(toolkit.ToString(payload["username"])) == 0: return helper.CreateResult(false, nil, "username cannot empty") case payload.Has("password") && len(toolkit.ToString(payload["password"])) == 0: return helper.CreateResult(false, nil, "password cannot empty") } sessid, err := acl.Login(toolkit.ToString(payload["username"]), toolkit.ToString(payload["password"])) if err != nil { return helper.CreateResult(true, "", err.Error()) } r.SetSession("sessionid", sessid) return helper.CreateResult(true, toolkit.M{}.Set("status", true), "Login Success") }
func (a *DataFlowController) Save(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := map[string]interface{}{} err := r.GetPayload(&payload) if err != nil { return helper.CreateResult(false, nil, err.Error()) } dataShapes := payload["DataShapes"].(map[string]interface{}) actions := payload["Actions"].([]interface{}) currentDataFlow := new(colonycore.DataFlow) currentDataFlow.DataShapes = dataShapes currentDataFlow.Actions = constructActions(actions) currentDataFlow.Name = tk.ToString(payload["Name"]) currentDataFlow.Description = tk.ToString(payload["Description"]) currentDataFlow.ID = tk.ToString(payload["ID"]) currentDataFlow.GlobalParam = tk.M{} for _, val := range payload["GlobalParam"].([]interface{}) { tmp := val.(map[string]interface{}) currentDataFlow.GlobalParam.Set(tk.ToString(tmp["key"]), tk.ToString(tmp["value"])) } dataDs := []colonycore.DataFlow{} cursor, err := colonycore.Find(new(colonycore.DataFlow), dbox.Eq("_id", currentDataFlow.ID)) if cursor != nil { cursor.Fetch(&dataDs, 0, false) defer cursor.Close() } if err != nil && cursor != nil { return helper.CreateResult(false, nil, err.Error()) } if len(dataDs) == 0 { currentDataFlow.CreatedDate = time.Now() currentDataFlow.CreatedBy = "Test User" currentDataFlow.ID = strings.Replace(currentDataFlow.Name, " ", "", -1) + cast.Date2String(time.Now(), "YYYYMMddHHmm") } else { currentDataFlow.CreatedDate = dataDs[0].CreatedDate currentDataFlow.CreatedBy = dataDs[0].CreatedBy } currentDataFlow.LastModified = time.Now() err = colonycore.Save(currentDataFlow) fmt.Println("") if err != nil { return helper.CreateResult(false, nil, err.Error()) } return helper.CreateResult(true, currentDataFlow, "success") }
func main() { jsonarg := toolkit.M{} err := toolkit.UnjsonFromString(os.Args[1], &jsonarg) if err != nil { return } jsonarg["Date"] = time.Now().Format("020106") jsonarg[`MB 62% Fe`] = "FE " + toolkit.ToString(jsonarg[`MB 62% Fe`]) jsonarg[`Platts 62% Fe IODEX`] = toolkit.ToString(toolkit.ToFloat64(jsonarg[`Platts 62% Fe IODEX`], 6, toolkit.RoundingAuto)) fmt.Println(toolkit.JsonString(jsonarg)) }
func main() { jsonarg := toolkit.M{} err := toolkit.UnjsonFromString(os.Args[1], &jsonarg) if err != nil { return } jsonarg["Date"] = "000000" jsonarg[`MB 62% Fe`] = "POST " + toolkit.ToString(jsonarg[`MB 62% Fe`]) jsonarg[`Platts 62% Fe IODEX`] = toolkit.ToString(toolkit.ToFloat64(jsonarg[`Platts 62% Fe IODEX`], 6, toolkit.RoundingAuto) * 5) fmt.Println(toolkit.JsonString(jsonarg)) }
func (c *Cursor) structValue(dataTypeList toolkit.M, col string, v interface{}) interface{} { for fieldname, datatype := range dataTypeList { if strings.ToLower(col) == fieldname { switch datatype.(string) { case "time.Time": val, e := time.Parse(c.DateFormat, toolkit.ToString(v)) if e != nil { v = toolkit.ToString(v) } else { v = val } case "int", "int32", "int64": val, e := strconv.Atoi(toolkit.ToString(v)) if e != nil { v = toolkit.ToString(v) } else { v = val } case "float", "float32", "float64": val, e := strconv.ParseFloat(toolkit.ToString(v), 64) if e != nil { v = toolkit.ToString(v) } else { v = val } case "bool": if c.driver == "mysql" { if toolkit.ToString(v) == "0" { v = false } else { v = true } } else { val, e := strconv.ParseBool(toolkit.ToString(v)) if e != nil { v = toolkit.ToString(v) } else { v = val } } default: v = toolkit.ToString(v) } } } return v }
func (a *DataFlowController) GetListData(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := map[string]interface{}{} err := r.GetPayload(&payload) if err != nil { return helper.CreateResult(false, nil, err.Error()) } search := tk.ToString(payload["search"]) var query *dbox.Filter if search != "" { query = dbox.Or(dbox.Contains("name", search), dbox.Contains("description", search), dbox.Contains("createdby", search)) } cursor, err := colonycore.Find(new(colonycore.DataFlow), query) dataDs := []colonycore.DataFlow{} if cursor != nil { cursor.Fetch(&dataDs, 0, false) defer cursor.Close() } if err != nil && cursor != nil { return helper.CreateResult(false, nil, err.Error()) } return helper.CreateResult(true, dataDs, "success") }
func saverechistory(key string, dt toolkit.M) (err error) { err = nil fullfilename := filepath.Join(toolkit.ToString(histConf.Get("recpath", "")), mapRecHistory[key]) if EC_DATA_PATH != "" { fullfilename = filepath.Join(EC_DATA_PATH, "datagrabber", "historyrec", mapRecHistory[key]) } // fmt.Println(fullfilename, " - Key - ", key, " - filename - ", mapRecHistory) cconfig := toolkit.M{"newfile": true, "useheader": true, "delimiter": ","} conn, err := prepareconnection("csv", fullfilename, "", "", "", cconfig) if err != nil { return } q := conn.NewQuery().SetConfig("multiexec", true).Insert() for k, v := range dt { if toolkit.TypeName(v) == "toolkit.M" { dt.Set(k, fmt.Sprintf("%v", v)) } } err = q.Exec(toolkit.M{}.Set("data", dt)) conn.Close() return }
func (c *Connection) RdbmsConnect(drivername string, stringConnection string) error { if drivername == "hive" { connInfo := strings.Split(stringConnection, ",") c.Hive = hive.HiveConfig(connInfo[0], connInfo[1], connInfo[2], connInfo[3], connInfo[4], connInfo[5]) c.Drivername = drivername c.Hive.Conn.Open() e := c.Hive.Conn.TestConnection() if e != nil { return err.Error(packageName, modConnection, "Connect", e.Error()) } } else { sqlcon, e := sql.Open(drivername, stringConnection) if e != nil { return err.Error(packageName, modConnection, "Connect", e.Error()) } c.Sql = *sqlcon c.Drivername = drivername e = sqlcon.Ping() if e != nil { return err.Error(packageName, modConnection, "Connect", e.Error()) } } if c.Info().Settings.Has("dateformat") { c.DateFormat = toolkit.ToString(c.Info().Settings.Get("dateformat", "")) } return nil }
func StringValue(v interface{}, db string) string { var ret string switch v.(type) { case string: t, e := time.Parse(time.RFC3339, toolkit.ToString(v)) if e != nil { ret = fmt.Sprintf("%s", "'"+v.(string)+"'") } else { if strings.Contains(db, "oci8") { // toolkit.Println(t.Format("2006-01-02 15:04:05")) ret = "to_date('" + t.Format("02-01-2006 15:04:05") + "','DD-MM-YYYY hh24:mi:ss')" } else { ret = "'" + t.Format("2006-01-02 15:04:05") + "'" } } case time.Time: t := v.(time.Time).UTC() if strings.Contains(db, "oci8") { ret = "to_date('" + t.Format("2006-01-02 15:04:05") + "','yyyy-mm-dd hh24:mi:ss')" } else { ret = "'" + t.Format("2006-01-02 15:04:05") + "'" } case int, int32, int64, uint, uint32, uint64: ret = fmt.Sprintf("%d", v.(int)) case nil: ret = "" default: ret = fmt.Sprintf("%v", v) } return ret }
func getSQLScript(path string, params tk.M) (script string) { file, err := os.Open(wd + path) if err == nil { defer file.Close() reader := bufio.NewReader(file) for { line, _, e := reader.ReadLine() if e != nil { break } script += string(line[:len(line)]) } } else { tk.Println(err.Error()) } for idx, val := range params { script = strings.Replace(script, idx, tk.ToString(val), -1) } script = strings.Replace(script, "\t", "", -1) return }
func decodeTSV(file []byte) (retVal interface{}, e error) { reader := csv.NewReader(strings.NewReader(string(file))) reader.Comma = '\t' records, e := reader.ReadAll() if e != nil { return } var list []interface{} for _, row := range records { line := toolkit.M{} for idx, val := range row { line.Set(toolkit.ToString(idx), val) } list = append(list, line) } if len(list) > 0 { retVal = list[0] } return }
func (q *Query) DataType(data interface{}) interface{} { if data != nil { rf := toolkit.TypeName(data) // toolkit.Println("data>", rf) if rf == "[]uint8" { uintToString := string(data.([]uint8)) spChar := strings.Contains(uintToString, "\x00") if spChar { uintToString = strings.Replace(uintToString, "\x00", "", 1) } floatVal, e := strconv.ParseFloat(uintToString, 64) if e != nil { } else { data = floatVal } } else { intVal, e := strconv.Atoi(toolkit.ToString(data)) if e != nil { e = nil floatVal, e := strconv.ParseFloat(toolkit.ToString(data), 64) if e != nil { e = nil boolVal, e := strconv.ParseBool(toolkit.ToString(data)) if e != nil { e = nil dateVal, e := time.Parse(q.DateFormat, toolkit.ToString(data)) if e != nil { data = data } else { /*if string is date*/ data = dateVal } } else { /*if string is bool*/ data = boolVal } } else { /*if string is float*/ data = floatVal } } else { /*if string is int*/ data = intVal } } } return data }
func (l *LoginController) Logout(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson sessionId := toolkit.ToString(r.Session("sessionid", "")) if toolkit.ToString(sessionId) == "" { return helper.CreateResult(true, nil, "Active sessionid not found") } err := acl.Logout(sessionId) if err != nil && (err.Error() == "Session id not found" || err.Error() == "Session id is expired") { return helper.CreateResult(true, nil, "Active sessionid not found") } else if err != nil { return helper.CreateResult(true, nil, toolkit.Sprintf("Error found : %v", err.Error())) } r.SetSession("sessionid", "") return helper.CreateResult(true, nil, "Logout success") }
func (l *LoginController) ResetPassword(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := toolkit.M{} err := r.GetPayload(&payload) if err != nil { return helper.CreateResult(false, nil, err.Error()) } fmt.Println(payload.Has("email")) fmt.Println(payload.Has("baseurl")) if !payload.Has("email") || !payload.Has("baseurl") { return helper.CreateResult(false, nil, "Data is not complete") } uname, tokenid, err := acl.ResetPassword(toolkit.ToString(payload["email"])) fmt.Printf("%v, %v, %v \n\n", uname, tokenid, err) if err != nil { return helper.CreateResult(false, nil, err.Error()) } linkstr := fmt.Sprintf("<a href='%v/web/confirmreset?1=%v&2=%v'>Click</a>", toolkit.ToString(payload["baseurl"]), uname, tokenid) mailmsg := fmt.Sprintf("Hi, <br/><br/> We received a request to reset your password, <br/><br/>") mailmsg = fmt.Sprintf("%vFollow the link below to set a new password : <br/><br/> %v <br/><br/>", mailmsg, linkstr) mailmsg = fmt.Sprintf("%vIf you don't want to change your password, you can ignore this email <br/><br/> Thanks,</body></html>", mailmsg) m := gomail.NewMessage() m.SetHeader("From", "*****@*****.**") m.SetHeader("To", toolkit.ToString(payload["email"])) m.SetHeader("Subject", "[no-reply] Self password reset") m.SetBody("text/html", mailmsg) d := gomail.NewPlainDialer("smtp.office365.com", 587, "*****@*****.**", "******") err = d.DialAndSend(m) if err != nil { return helper.CreateResult(false, nil, err.Error()) } return helper.CreateResult(true, nil, "reset password success") }
func constructFilters(operator string, field string, value interface{}, logic string) { condition := "" switch operator { case "eq": condition = "=" case "neq": condition = "<>" case "startswith": condition = "like" case "contains": condition = "like" case "endswith": condition = "like" case "doesnotcontain": condition = "not like" case "gt": condition = ">" case "gte": condition = ">=" case "lte": condition = "<=" case "lt": condition = "<" } sort.Strings(FiltersDB) sort.Strings(FiltersWO) sort.Strings(FiltersMain) sort.Strings(FiltersPlant) sort.Strings(FieldStr) val := tk.ToString(value) str := sort.SearchStrings(FieldStr, field) if str < len(FieldStr) && FieldStr[str] == field { val = "'" + val + "'" } db := sort.SearchStrings(FiltersDB, field) wo := sort.SearchStrings(FiltersWO, field) main := sort.SearchStrings(FiltersMain, field) plant := sort.SearchStrings(FiltersPlant, field) if db < len(FiltersDB) && FiltersDB[db] == field { FilDB = append(FilDB, " "+logic+" "+field+" "+condition+" "+val) } else if wo < len(FiltersWO) && FiltersWO[wo] == field { FilWO = append(FilWO, " "+logic+" "+"RESULT."+field+" "+condition+" "+val+" ") } else if main < len(FiltersMain) && FiltersMain[main] == field { FilMain = append(FilMain, " "+logic+" "+field+" "+condition+" "+val+" ") } else if plant < len(FiltersPlant) && FiltersPlant[plant] == field { FilPlant = append(FilPlant, " "+logic+" "+field+" "+condition+" "+val+" ") } }
func savehistory(dt toolkit.M) (err error) { err = nil filename := fmt.Sprintf("%s-%s.csv", toolkit.ToString(histConf.Get("filename", "")), toolkit.Date2String(sedotan.TimeNow(), toolkit.ToString(histConf.Get("filepattern", "")))) fullfilename := filepath.Join(toolkit.ToString(histConf.Get("histpath", "")), filename) if EC_DATA_PATH != "" { fullfilename = filepath.Join(EC_DATA_PATH, "webgrabber", "history", filename) } cconfig := toolkit.M{"newfile": true, "useheader": true, "delimiter": ","} conn, err := prepareconnection("csv", fullfilename, "", "", "", cconfig) if err != nil { return } err = conn.NewQuery().SetConfig("multiexec", true).Insert().Exec(toolkit.M{}.Set("data", dt)) conn.Close() return }
func (a *SessionController) GetSession(r *knot.WebContext) interface{} { var filter *dbox.Filter r.Config.OutputType = knot.OutputJson _ = a.InitialSetDatabase() payload := map[string]interface{}{} err := r.GetForms(&payload) if err != nil { return helper.CreateResult(false, nil, err.Error()) } if strings.Contains(toolkit.TypeName(payload["find"]), "float") { payload["find"] = toolkit.ToInt(payload["find"], toolkit.RoundingAuto) } tSession := new(acl.Session) if find := toolkit.ToString(payload["find"]); find != "" { filter = new(dbox.Filter) filter = dbox.Contains("loginid", find) } take := toolkit.ToInt(payload["take"], toolkit.RoundingAuto) skip := toolkit.ToInt(payload["skip"], toolkit.RoundingAuto) // c, err := acl.Find(tAccess, filter, toolkit.M{}.Set("take", take).Set("skip", skip)) // c, err := acl.Find(tSession, nil, toolkit.M{}.Set("take", payload["take"].(int)).Set("skip", payload["skip"].(int))) c, err := acl.Find(tSession, filter, toolkit.M{}.Set("take", take).Set("skip", skip)) if err != nil { return helper.CreateResult(true, nil, err.Error()) } data := toolkit.M{} arrm := make([]toolkit.M, 0, 0) err = c.Fetch(&arrm, 0, false) for i, val := range arrm { arrm[i].Set("duration", time.Since(val["created"].(time.Time)).Hours()) arrm[i].Set("status", "ACTIVE") if val["expired"].(time.Time).Before(time.Now().UTC()) { arrm[i].Set("duration", val["expired"].(time.Time).Sub(val["created"].(time.Time)).Hours()) arrm[i].Set("status", "EXPIRED") } } c.Close() c, err = acl.Find(tSession, filter, nil) data.Set("Datas", arrm) data.Set("total", c.Count()) if err != nil { return helper.CreateResult(true, nil, err.Error()) } else { return helper.CreateResult(true, data, "") } }
func GetLogs() (interface{}, error) { filepath := toolkit.ToString(*fLocation) bytes, err := ioutil.ReadFile(filepath) if err != nil { return nil, err } logs := string(bytes) return logs, err }
func GetUser(r *knot.WebContext) (tUser acl.User, err error) { sessionId := r.Session("sessionid", "") if toolkit.ToString(sessionId) == "" { err = error(errors.New("Sessionid is not found")) return } userid, err := acl.FindUserBySessionID(toolkit.ToString(sessionId)) if err != nil { return } err = acl.FindByID(&tUser, userid) if err != nil { return } return }
func (a *AclController) Logout(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := toolkit.M{} err := r.GetPayload(&payload) sessionid := "" switch { case err != nil: return helper.CreateResult(false, nil, err.Error()) case !payload.Has("username") && !payload.Has("sessionid"): return helper.CreateResult(false, nil, "username or session not found") case payload.Has("sessionid"): sessionid = toolkit.ToString(payload["sessionid"]) case payload.Has("username"): tUser := new(acl.User) err = acl.FindUserByLoginID(tUser, toolkit.ToString(payload["username"])) if err != nil { return helper.CreateResult(false, nil, "fail to get userid") } tSession := new(acl.Session) err = acl.FindActiveSessionByUser(tSession, tUser.ID) if err != nil { return helper.CreateResult(false, nil, "fail to get sessionid") } sessionid = tSession.ID } if sessionid == "" { return helper.CreateResult(true, nil, "Active sessionid not found") } err = acl.Logout(sessionid) if err != nil && (err.Error() == "Session id not found" || err.Error() == "Session id is expired") { return helper.CreateResult(true, nil, "Active sessionid not found") } else if err != nil { return helper.CreateResult(true, nil, toolkit.Sprintf("Error found : %v", err.Error())) } return helper.CreateResult(true, nil, "Logout success") }
func (a *SessionController) GetSession(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson _ = a.InitialSetDatabase() // payload := map[string]interface{}{} // err := r.GetPayload(&payload) // if err != nil { // return helper.CreateResult(false, nil, err.Error()) // } tSession := new(acl.Session) data := toolkit.M{} arrm := make([]toolkit.M, 0, 0) // c, err := acl.Find(tSession, nil, toolkit.M{}.Set("take", payload["take"].(int)).Set("skip", payload["skip"].(int))) c, err := acl.Find(tSession, nil, toolkit.M{}.Set("take", 10).Set("skip", 0)) if err != nil { return helper.CreateResult(true, nil, err.Error()) } err = c.Fetch(&arrm, 0, false) for i, val := range arrm { tUser := new(acl.User) e := acl.FindByID(tUser, toolkit.ToString(val.Get("userid", ""))) if e != nil { continue } arrm[i].Set("username", tUser.LoginID) arrm[i].Set("duration", time.Since(val["created"].(time.Time)).Hours()) arrm[i].Set("status", "ACTIVE") if val["expired"].(time.Time).Before(time.Now().UTC()) { arrm[i].Set("duration", val["expired"].(time.Time).Sub(val["created"].(time.Time)).Hours()) arrm[i].Set("status", "EXPIRED") } arrm[i].Set("username", tUser.LoginID) // toolkit.Printf("Debug date : %v : %v\n", toolkit.TypeName(val["created"]), val["created"].(time.Time)) } c.Close() c, err = acl.Find(tSession, nil, nil) data.Set("Datas", arrm) data.Set("total", c.Count()) // data.Set("total", 100) if err != nil { return helper.CreateResult(true, nil, err.Error()) } else { return helper.CreateResult(true, data, "") } }
func (l *LoginController) GetUserName(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson sessionId := r.Session("sessionid", "") if toolkit.ToString(sessionId) == "" { return helper.CreateResult(true, "", "Sessionid is not found") } userid, err := acl.FindUserBySessionID(toolkit.ToString(sessionId)) if err != nil { return helper.CreateResult(false, "", "Get username failed") } tUser := new(acl.User) err = acl.FindByID(tUser, userid) if err != nil { return helper.CreateResult(false, "", "Get username failed") } return helper.CreateResult(true, toolkit.M{}.Set("username", tUser.LoginID), "") }
func finUpdateObj(jsonData []toolkit.M, replaceData toolkit.M, isType string) []toolkit.M { var ( mapVal []toolkit.M ) if isType == "update" { iReplaceData := toolkit.Id(replaceData) //reflectIs := reflect.ValueOf(iReplaceData).Kind() //dataUptId := ToString(reflectIs, iReplaceData) dataUptId := toolkit.ToString(iReplaceData) for _, v := range jsonData { iSubV := toolkit.Id(v) //reflectIs := reflect.ValueOf(iSubV).Kind() subvIdString := toolkit.ToString(iSubV) if strings.ToLower(subvIdString) == strings.ToLower(dataUptId) { for key, _ := range v { delete(v, key) } } var newData = make(map[string]interface{}) for i, dataUpt := range replaceData { newData[i] = dataUpt } for i, newSubV := range v { newData[i] = newSubV } mapVal = append(mapVal, newData) } return mapVal } else if isType == "insert" { val := append(jsonData, replaceData) return val } return nil }
/* ========================================== var payload = { sessionid:"t7AuS0YIE9w8gOWY22HPJaj1pSxEjBNU", accesscheck:[""], accessid:"" }; app.ajaxPost("/acl/authenticate", payload) ============================================= */ func (a *AclController) Authenticate(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson var iaccenum acl.AccessTypeEnum payload := toolkit.M{} result := toolkit.M{} result.Set("hasaccess", false) err := r.GetPayload(&payload) switch { case err != nil: return helper.CreateResult(false, nil, err.Error()) } switch toolkit.TypeName(payload["accesscheck"]) { case "[]interface {}": for _, val := range payload["accesscheck"].([]interface{}) { tacc := acl.GetAccessEnum(toolkit.ToString(val)) if !acl.Matchaccess(int(tacc), int(iaccenum)) { iaccenum += tacc } } default: iaccenum = acl.GetAccessEnum(toolkit.ToString(payload["accesscheck"])) } // toolkit.Println("Type name : ", toolkit.TypeName(payload["accesscheck"])) found := acl.HasAccess(toolkit.ToString(payload["sessionid"]), acl.IDTypeSession, toolkit.ToString(payload["accessid"]), iaccenum) if found { result.Set("hasaccess", found) } return helper.CreateResult(true, result, "") }
func (a *AdministrationController) GetAccess(r *knot.WebContext) interface{} { var filter *dbox.Filter r.Config.OutputType = knot.OutputJson a.InitialSetDatabase() payload := map[string]interface{}{} err := r.GetForms(&payload) if strings.Contains(toolkit.TypeName(payload["find"]), "float") { payload["find"] = toolkit.ToInt(payload["find"], toolkit.RoundingAuto) } tAccess := new(acl.Access) if find := toolkit.ToString(payload["find"]); find != "" { filter = new(dbox.Filter) filter = dbox.Or(dbox.Contains("id", find), dbox.Contains("title", find), dbox.Contains("group1", find), dbox.Contains("group2", find), dbox.Contains("group3", find), dbox.Contains("specialaccess1", find), dbox.Contains("specialaccess2", find), dbox.Contains("specialaccess3", find), dbox.Contains("specialaccess4", find)) } data := toolkit.M{} arrm := make([]toolkit.M, 0, 0) take := toolkit.ToInt(payload["take"], toolkit.RoundingAuto) skip := toolkit.ToInt(payload["skip"], toolkit.RoundingAuto) c, err := acl.Find(tAccess, filter, toolkit.M{}.Set("take", take).Set("skip", skip)) if err == nil { err = c.Fetch(&arrm, 0, false) } c.Close() c, err = acl.Find(tAccess, filter, nil) data.Set("Datas", arrm) data.Set("total", c.Count()) if err != nil { return helper.CreateResult(true, nil, err.Error()) } else { return helper.CreateResult(true, data, "") } }
func (a *DataFlowController) Start(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := map[string]interface{}{} err := r.GetPayload(&payload) if err != nil { return helper.CreateResult(false, nil, err.Error()) } dataFlowId := tk.ToString(payload["dataFlowId"]) globalParam := tk.M{} for _, val := range payload["globalParam"].([]interface{}) { tmp := val.(map[string]interface{}) globalParam.Set(tk.ToString(tmp["key"]), tk.ToString(tmp["value"])) } dataDs := []colonycore.DataFlow{} cursor, err := colonycore.Find(new(colonycore.DataFlow), dbox.Eq("_id", dataFlowId)) if cursor != nil { cursor.Fetch(&dataDs, 0, false) defer cursor.Close() } if err != nil && cursor != nil { return helper.CreateResult(false, nil, err.Error()) } if len(dataDs) > 0 { dataflow.Start(dataDs[0], "user test", globalParam) } else { return helper.CreateResult(false, nil, "Flow Not Found") } return helper.CreateResult(true, nil, "success") }
func (a *UserController) GetUser(r *knot.WebContext) interface{} { var filter *dbox.Filter r.Config.OutputType = knot.OutputJson _ = a.InitialSetDatabase() payload := map[string]interface{}{} err := r.GetForms(&payload) if err != nil { return helper.CreateResult(false, nil, err.Error()) } if strings.Contains(toolkit.TypeName(payload["find"]), "float") { payload["find"] = toolkit.ToInt(payload["find"], toolkit.RoundingAuto) } tUser := new(acl.User) if find := toolkit.ToString(payload["find"]); find != "" { filter = new(dbox.Filter) filter = dbox.Or(dbox.Contains("id", find), dbox.Contains("fullname", find), dbox.Contains("email", find)) } take := toolkit.ToInt(payload["take"], toolkit.RoundingAuto) skip := toolkit.ToInt(payload["skip"], toolkit.RoundingAuto) c, err := acl.Find(tUser, filter, toolkit.M{}.Set("take", take).Set("skip", skip)) if err != nil { return helper.CreateResult(true, nil, err.Error()) } data := toolkit.M{} arrm := make([]toolkit.M, 0, 0) err = c.Fetch(&arrm, 0, false) c.Close() c, err = acl.Find(tUser, filter, nil) data.Set("Datas", arrm) data.Set("total", c.Count()) if err != nil { return helper.CreateResult(true, nil, err.Error()) } else { return helper.CreateResult(true, data, "") } }
func (a *GroupController) Search(r *knot.WebContext) interface{} { var filter *dbox.Filter r.Config.OutputType = knot.OutputJson _ = a.InitialSetDatabase() payload := map[string]interface{}{} err := r.GetForms(&payload) if err != nil { return helper.CreateResult(false, nil, err.Error()) } if strings.Contains(toolkit.TypeName(payload["search"]), "float") { payload["search"] = toolkit.ToInt(payload["search"], toolkit.RoundingAuto) } tGroup := new(acl.Group) if search := toolkit.ToString(payload["search"]); search != "" { filter = new(dbox.Filter) filter = dbox.Or(dbox.Contains("_id", search), dbox.Contains("title", search), dbox.Contains("owner", search)) } fmt.Println(filter) take := toolkit.ToInt(payload["take"], toolkit.RoundingAuto) skip := toolkit.ToInt(payload["skip"], toolkit.RoundingAuto) c, err := acl.Find(tGroup, filter, toolkit.M{}.Set("take", take).Set("skip", skip)) if err != nil { return helper.CreateResult(true, nil, err.Error()) } data := toolkit.M{} arrm := make([]toolkit.M, 0, 0) err = c.Fetch(&arrm, 0, false) data.Set("Datas", arrm) data.Set("total", c.Count()) if err != nil { return helper.CreateResult(true, nil, err.Error()) } return helper.CreateResult(true, data, "") }