当前位置: 首页>>代码示例>>Golang>>正文


Golang Admin.Save方法代码示例

本文整理汇总了Golang中admin/app/models.Admin.Save方法的典型用法代码示例。如果您正苦于以下问题:Golang Admin.Save方法的具体用法?Golang Admin.Save怎么用?Golang Admin.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在admin/app/models.Admin的用法示例。


在下文中一共展示了Admin.Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Add


//.........这里部分代码省略.........
		if admin.HasName() {
			c.Flash.Error("用户名“" + username + "”已存在!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var password string = c.Params.Get("password")
		if len(password) > 0 {
			admin.Password = password
		} else {
			c.Flash.Error("请输入密码!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var pwdconfirm string = c.Params.Get("pwdconfirm")
		if len(pwdconfirm) > 0 {
			if password != pwdconfirm {
				c.Flash.Error("两次输入密码不一致!")
				c.Flash.Out["url"] = "/Admin/Add/"
				return c.Redirect("/Message/")
			}
		} else {
			c.Flash.Error("请输入确认密码!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var email string = c.Params.Get("email")
		if len(email) > 0 {
			admin.Email = email
		} else {
			c.Flash.Error("请输入E-mail!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		if admin.HasEmail() {
			c.Flash.Error("E-mail已存在!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var realname string = c.Params.Get("realname")
		if len(realname) > 0 {
			admin.Realname = realname
		} else {
			c.Flash.Error("请输入真实姓名!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var lang string = c.Params.Get("lang")
		if len(lang) > 0 {
			admin.Lang = lang
		} else {
			c.Flash.Error("请选择语言!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var roleid string = c.Params.Get("roleid")
		if len(roleid) > 0 {

			Roleid, err := strconv.ParseInt(roleid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			admin.Roleid = Roleid
		} else {
			c.Flash.Error("请选择所属角色!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var status string = c.Params.Get("status")
		if len(status) > 0 {
			Status, err := strconv.ParseInt(status, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			admin.Status = Status
		} else {
			c.Flash.Error("请选择状态!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		if admin.Save() {
			c.Flash.Success("添加管理员成功!")
			c.Flash.Out["url"] = "/Admin/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加管理员失败!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}
	}
}
开发者ID:qmdx,项目名称:GoCMS,代码行数:101,代码来源:admin.go

示例2: Add


//.........这里部分代码省略.........
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		if admin.HasEmail() {
			c.Flash.Error("E-mail已存在!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var realname string = c.Params.Get("realname")
		if len(realname) > 0 {
			admin.Realname = realname
		} else {
			c.Flash.Error("请输入真实姓名!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var lang string = c.Params.Get("lang")
		if len(lang) > 0 {
			admin.Lang = lang
		} else {
			c.Flash.Error("请选择语言!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var roleid string = c.Params.Get("roleid")
		if len(roleid) > 0 {

			Roleid, err := strconv.ParseInt(roleid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			admin.Roleid = Roleid
		} else {
			c.Flash.Error("请选择所属角色!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		var status string = c.Params.Get("status")
		if len(status) > 0 {
			Status, err := strconv.ParseInt(status, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			admin.Status = Status
		} else {
			c.Flash.Error("请选择状态!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}

		if ip := c.Request.Header.Get("X-Forwarded-For"); ip != "" {
			ips := strings.Split(ip, ",")
			if len(ips) > 0 && ips[0] != "" {
				rip := strings.Split(ips[0], ":")
				admin.Lastloginip = rip[0]
			}
		} else {
			ip := strings.Split(c.Request.RemoteAddr, ":")
			if len(ip) > 0 {
				if ip[0] != "[" {
					admin.Lastloginip = ip[0]
				}
			}
		}

		if admin.Save() {

			//******************************************
			//管理员日志
			if UserID, ok := c.Session["UserID"]; ok {
				UserID, err := strconv.ParseInt(UserID, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				admin_info := admin.GetById(UserID)

				logs := new(models.Logs)
				desc := "添加管理员:" + username + "|^|管理员管理"
				logs.Save(admin_info, c.Controller, desc)
			}

			//*****************************************

			c.Flash.Success("添加管理员成功!")
			c.Flash.Out["url"] = "/Admin/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("添加管理员失败!")
			c.Flash.Out["url"] = "/Admin/Add/"
			return c.Redirect("/Message/")
		}
	}
}
开发者ID:zacklin923,项目名称:GoCMS,代码行数:101,代码来源:admin.go


注:本文中的admin/app/models.Admin.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。