Example #1
0
//@Mapper("/admin/user/save")
func (u *User) Save(user *model.User, opType string, flash *peony.Flash) peony.Renderer {
	var back interface{} = (*User).Add
	if opType == "edit" {
		back = (*User).Edit
	}
	if len(user.LoginId) == 0 {
		flash.Error("登录ID不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": user.Id})
	}
	if len(user.Name) == 0 {
		flash.Error("名字不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": user.Id})
	}
	if len(user.Password) < 6 {
		flash.Error("密码长度不够")
		return peony.Redirect(back, map[string]interface{}{"id": user.Id})
	}
	if opType == "edit" {
		flash.Success(user.LoginId + "修改成功")
		engine.Id(user.Id).AllCols().Update(user)
	} else {
		flash.Success(user.LoginId + "添加成功")
		engine.Insert(user)
	}
	return peony.Redirect((*User).Users)
}
Example #2
0
func (c Application) EnterDemo(user, demo string) peony.Renderer {

	// if c.Validation.HasErrors() {
	// 	c.Flash.Error("Please choose a nick name and the demonstration type.")
	// 	return NewRedirectRender(Application.Index)
	// }

	switch demo {
	case "refresh":
		return peony.Redirect("/refresh?user=%s", user)
	case "longpolling":
		return peony.Redirect("/longpolling/room?user=%s", user)
	case "websocket":
		return peony.Redirect("/websocket/room?user=%s", user)
	}
	return peony.Redirect(Application.Index)
}
Example #3
0
func loginCheck(c *peony.Controller) peony.Renderer {
	session := c.Session
	id, ok := session.Get("operatorId")
	if !ok || id == nil {
		return peony.Redirect(Admin)
	}
	return nil
}
Example #4
0
//@Mapper("/login", method="POST")
func Login(name, password string, c *peony.Controller) peony.Renderer {
	if len(name) == 0 || len(password) == 0 {
		c.Flash.Error("用户名或密码错误~!")
		return peony.Redirect(Admin)
	}
	oper := getOperatorById(name)
	if oper == nil ||
		oper.LoginId != name ||
		oper.Password != password {
		c.Flash.Error("用户名或密码错误~!")
		return peony.Redirect(Admin)
	}
	session := c.Session
	session.Set("operatorId", session.GetId())
	session.Set("operator", oper)
	if oper.IsMaster {
		session.Set("menus", loadAllMenus())
	}
	return peony.Redirect("/admin/home")

}
Example #5
0
//@Mapper("/admin/vendor/save")
func (v *Vendor) Save(vendor *model.Vendor, opType string, flash *peony.Flash) peony.Renderer {
	var back interface{} = (*Vendor).Add
	if opType == "edit" {
		back = (*Vendor).Edit
	}
	if len(vendor.Name) == 0 {
		flash.Error("名字不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": vendor.Id})
	}
	if vendor.VendorId == 0 {
		flash.Error("VendorId不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": vendor.Id})
	}

	if opType == "edit" {
		flash.Success(vendor.Name + "修改成功")
		engine.Id(vendor.Id).AllCols().Update(vendor)
	} else {
		flash.Success(vendor.Name + "添加成功")
		engine.Insert(vendor)
	}
	return peony.Redirect((*Vendor).Vendors)
}
Example #6
0
//@Mapper("/admin/nas/save")
func (v *Nas) Save(nas *model.Nas, opType string, flash *peony.Flash) peony.Renderer {
	var back interface{} = (*Nas).Add
	if opType == "edit" {
		back = (*Nas).Edit
	}
	if len(nas.Name) == 0 {
		flash.Error("名字不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": nas.Id})
	}
	if len(nas.Ip) == 0 {
		flash.Error("IP不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": nas.Id})
	}

	if opType == "edit" {
		flash.Success(nas.Ip + "修改成功")
		engine.Id(nas.Id).AllCols().Update(nas)
	} else {
		flash.Success(nas.Ip + "添加成功")
		engine.Insert(nas)
	}
	return peony.Redirect((*Nas).Nass)
}
Example #7
0
//@Mapper("/admin/attr/save")
func (v *Attr) Save(attr *model.Attr, opType string, flash *peony.Flash) peony.Renderer {
	var back interface{} = (*Attr).Add
	if opType == "edit" {
		back = (*Attr).Edit
	}
	if len(attr.Name) == 0 {
		flash.Error("名字不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": attr.Id})
	}
	if attr.Type == 0 {
		flash.Error("类型不能为空")
		return peony.Redirect(back, map[string]interface{}{"id": attr.Id})
	}

	if opType == "edit" {
		flash.Success(attr.Name + "修改成功")
		engine.Id(attr.Id).AllCols().Update(attr)
	} else {
		flash.Success(attr.Name + "添加成功")
		engine.Insert(attr)
	}
	return peony.Redirect((*Attr).Attrs)
}
Example #8
0
//@Mapper("/admin/vendor/<id>/del")
func (u *Vendor) Del(id int64, flash *peony.Flash) peony.Renderer {
	var vendor = &model.Vendor{}
	engine.Id(id).Delete(vendor)
	flash.Success(fmt.Sprintf("厂商:%s 删除成功~!", vendor.Name))
	return peony.Redirect((*Vendor).Vendors)
}
Example #9
0
//@Mapper("/admin/nas/<id>/del")
func (u *Nas) Del(id int64, flash *peony.Flash) peony.Renderer {
	var nas = &model.Nas{}
	engine.Id(id).Delete(nas)
	flash.Success(fmt.Sprintf("Nas:%s 删除成功~!", nas.Name))
	return peony.Redirect((*Nas).Nass)
}
Example #10
0
//@Mapper("/admin/attr/<id>/del")
func (u *Attr) Del(id int64, flash *peony.Flash) peony.Renderer {
	var attr = &model.Attr{}
	engine.Id(id).Delete(attr)
	flash.Success(fmt.Sprintf("属性:%s 删除成功~!", attr.Name))
	return peony.Redirect((*Attr).Attrs)
}
Example #11
0
//@Mapper("/")
func Index() peony.Renderer {
	return peony.Redirect(Admin)
}
Example #12
0
//@Mapper("/admin/user/<id>/del")
func (u *User) Del(id int64, flash *peony.Flash) peony.Renderer {
	var user = &model.User{}
	engine.Id(id).Delete(user)
	flash.Success(fmt.Sprintf("帐号:%s 删除成功~!", user.LoginId))
	return peony.Redirect((*User).Users)
}
Example #13
0
//@Mapper("/admin/logout")
func (oc *Operator) Logout(session *peony.Session) peony.Renderer {
	session.Del("operatorId")
	session.Del("operator")
	return peony.Redirect("/admin")
}