Esempio n. 1
0
//添加会员
func (u *User) Edit(Id int64) bool {
	user := new(User)

	user.Email = u.Email
	if len(u.Password) > 0 {
		user.Password = utils.Md5(u.Password)
	}
	user.Nickname = u.Nickname
	user.Mobile = u.Mobile
	user.Birthday = u.Birthday
	user.Groupid = u.Groupid
	user.Point = u.Point
	user.Islock = u.Islock
	user.Vip = u.Vip
	user.Overduedate = u.Overduedate

	if len(u.Password) > 0 {
		has, err := DB_Write.Table("user").Id(Id).Cols("email", "password", "nickname", "mobile", "birthday", "groupid", "point", "islock", "vip", "overduedate").Update(user)
		if err != nil {
			revel.WARN.Println(has)
			revel.WARN.Printf("错误: %v", err)
			return false
		}
	} else {
		has, err := DB_Write.Table("user").Id(Id).Cols("email", "nickname", "mobile", "birthday", "groupid", "point", "islock", "vip", "overduedate").Update(user)
		if err != nil {
			revel.WARN.Println(has)
			revel.WARN.Printf("错误: %v", err)
			return false
		}
	}

	return true
}
Esempio n. 2
0
//添加会员
func (u *User) Save() bool {
	user := new(User)

	user.Email = u.Email
	user.Username = u.Username
	user.Password = utils.Md5(u.Password)
	user.Encrypt = utils.RandomString(6)
	user.Nickname = u.Nickname
	user.Mobile = u.Mobile
	user.Birthday = u.Birthday
	user.Regip = u.Regip
	user.Regdate = time.Now().Format("2006-01-02 15:04:04")
	user.Lastdate = time.Now().Format("2006-01-02 15:04:04")
	user.Lastip = u.Lastip
	user.Loginnum = 0
	user.Groupid = u.Groupid
	user.Areaid = u.Areaid
	user.Amount = 0
	user.Point = u.Point
	user.Ismessage = u.Ismessage
	user.Islock = u.Islock
	user.Vip = u.Vip
	user.Overduedate = u.Overduedate
	user.Status = u.Status
	user.Createtime = time.Now().Format("2006-01-02 15:04:04")

	has, err := DB_Write.Table("user").Insert(user)
	if err != nil {
		revel.WARN.Println(has)
		revel.WARN.Printf("错误: %v", err)
		return false
	}
	return true
}
Esempio n. 3
0
//解锁
func (c *Ajax) ScreenUnlock(admin *models.Admin) revel.Result {
	var lock_password string = c.Params.Get("lock_password")

	if lock_password == "" || len(lock_password) <= 0 {
		return c.RenderText("2")
	}

	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)

		if admin_info.Password != utils.Md5(lock_password) {
			return c.RenderText("3")
		} else {
			c.Session["lock_screen"] = "0"
			return c.RenderText("1")
		}
	} else {
		return c.RenderText("4")
	}
}
Esempio n. 4
0
//编辑管理员
func (a *Admin) Edit(Id int64) bool {

	admin := new(Admin)

	if len(a.Username) > 0 {
		admin.Username = a.Username
	}

	if len(a.Password) > 0 {
		admin.Password = utils.Md5(a.Password)
	}

	if a.Roleid > 0 {
		admin.Roleid = a.Roleid
	}

	if len(a.Email) > 0 {
		admin.Email = a.Email
	}

	if len(a.Realname) > 0 {
		admin.Realname = a.Realname
	}

	if len(a.Lang) > 0 {
		admin.Lang = a.Lang
	}

	admin.Status = a.Status

	if len(a.Password) > 0 {
		has, err := DB_Write.Id(Id).Cols("username", "password", "email", "realname", "roleid", "lang", "status").Update(admin)
		if err != nil {
			revel.WARN.Println(has)
			revel.WARN.Printf("错误: %v", err)
			return false
		}
	} else {
		has, err := DB_Write.Id(Id).Cols("username", "email", "realname", "roleid", "lang", "status").Update(admin)
		if err != nil {
			revel.WARN.Println(has)
			revel.WARN.Printf("错误: %v", err)
			return false
		}
	}

	return true
}
Esempio n. 5
0
//修改密码
func (a *Admin) EditPwd(Id int64) bool {
	admin := new(Admin)

	if len(a.Password) > 0 {
		admin.Password = utils.Md5(a.Password)
	}

	has, err := DB_Write.Id(Id).Cols("password").Update(admin)
	if err != nil {
		revel.WARN.Println(has)
		revel.WARN.Printf("错误: %v", err)
		return false
	}

	return true
}
Esempio n. 6
0
//添加管理员
func (a *Admin) Save() bool {

	admin := new(Admin)
	admin.Username = a.Username
	admin.Password = utils.Md5(a.Password)
	admin.Roleid = a.Roleid
	admin.Lastloginip = a.Lastloginip
	admin.Email = a.Email
	admin.Realname = a.Realname
	admin.Lang = a.Lang
	admin.Lastlogintime = "0000-00-00 00:00:00"
	admin.Status = a.Status
	admin.Createtime = time.Now().Format("2006-01-02 15:04:04")

	has, err := DB_Write.Insert(admin)
	if err != nil {
		revel.WARN.Println(has)
		revel.WARN.Printf("错误: %v", err)
		return false
	}
	return true
}
Esempio n. 7
0
//修改密码
func (c *User) EditPwd(admin *models.Admin) revel.Result {
	if c.Request.Method == "GET" {
		title := "修改密码--GoCMS管理系统"

		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)

			c.Render(title, admin_info)
		} else {
			c.Render(title)
		}

		return c.RenderTemplate("User/EditPwd.html")
	} else {

		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)

			var old_password string = c.Params.Get("old_password")
			if len(old_password) > 0 {
				if admin_info.Password != utils.Md5(old_password) {
					c.Flash.Error("旧密码不正确!")
					c.Flash.Out["url"] = "/EditPwd/"
					return c.Redirect("/Message/")
				}
			} else {
				return c.Redirect("/User/EditPwd/")
			}

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

			} else {
				c.Flash.Error("新密码不能为空!")
				c.Flash.Out["url"] = "/EditPwd/"
				return c.Redirect("/Message/")
			}

			var new_pwdconfirm string = c.Params.Get("new_pwdconfirm")
			if len(new_pwdconfirm) > 0 {
				if new_pwdconfirm != new_password {
					c.Flash.Error("两次输入密码入不一致!")
					c.Flash.Out["url"] = "/EditPwd/"
					return c.Redirect("/Message/")
				} else {
					admin.Password = new_pwdconfirm
				}
			} else {
				c.Flash.Error("请输入重复新密码!")
				c.Flash.Out["url"] = "/EditPwd/"
				return c.Redirect("/Message/")
			}

			if admin.EditPwd(UserID) {

				//******************************************
				//管理员日志
				logs := new(models.Logs)
				desc := "个人设置|^|修改密码"
				logs.Save(admin_info, c.Controller, desc)
				//*****************************************

				c.Flash.Success("修改成功!")
				c.Flash.Out["url"] = "/EditPwd/"
				return c.Redirect("/Message/")
			} else {
				c.Flash.Error("修改失败!")
				c.Flash.Out["url"] = "/EditPwd/"
				return c.Redirect("/Message/")
			}
		} else {
			c.Flash.Error("未登陆,请先登陆!")
			c.Flash.Out["url"] = "/"
			return c.Redirect("/Message/")
		}
	}
}
Esempio n. 8
0
//登陆
func (c *User) Login(admin *models.Admin) revel.Result {

	if c.Request.Method == "GET" {
		title := "登陆--GoCMS管理系统"

		CaptchaId := captcha.NewLen(6)

		return c.Render(title, CaptchaId)
	} else {
		var username string = c.Params.Get("username")
		var password string = c.Params.Get("password")

		var captchaId string = c.Params.Get("captchaId")
		var verify string = c.Params.Get("verify")

		data := make(map[string]string)

		if LANG, ok := c.Session["Lang"]; ok {
			//设置语言
			c.Request.Locale = LANG
		} else {
			//设置默认语言
			c.Request.Locale = "zh"
		}

		if !captcha.VerifyString(captchaId, verify) {
			data["status"] = "0"
			data["url"] = "/"
			data["message"] = c.Message("verification_code")
			return c.RenderJson(data)
		}

		if len(username) <= 0 {
			data["status"] = "0"
			data["url"] = "/"
			data["message"] = c.Message("login_user_name")
			return c.RenderJson(data)
		}

		if len(password) <= 0 {
			data["status"] = "0"
			data["url"] = "/"
			data["message"] = c.Message("login_password")
			return c.RenderJson(data)
		}

		if len(verify) <= 0 {
			data["status"] = "0"
			data["url"] = "/"
			data["message"] = c.Message("login_verification_code")
			return c.RenderJson(data)
		}

		admin_info := admin.GetByName(username)

		if admin_info.Id <= 0 {
			data["status"] = "0"
			data["url"] = "/"
			data["message"] = c.Message("admin_username_error")
		} else if admin_info.Status == 0 && admin_info.Id != 1 {
			data["status"] = "0"
			data["url"] = "/"
			data["message"] = c.Message("admin_forbid_login")
		} else if admin_info.Role.Status == 0 && admin_info.Id != 1 {
			data["status"] = "0"
			data["url"] = "/"
			data["message"] = c.Message("admin_forbid_role_login")
		} else if username == admin_info.Username && utils.Md5(password) == admin_info.Password {

			/*
			* %% 印出百分比符号,不转换。
			* %c 整数转成对应的 ASCII 字元。
			* %d 整数转成十进位。
			* %f 倍精确度数字转成浮点数。
			* %o 整数转成八进位。
			* %s 整数转成字符串。
			* %x 整数转成小写十六进位。
			* %X 整数转成大写十六进位
			 */
			c.Session["UserID"] = fmt.Sprintf("%d", admin_info.Id)
			c.Session["Lang"] = admin_info.Lang

			c.Flash.Success(c.Message("login_success"))
			c.Flash.Out["url"] = "/"

			//更新登陆时间
			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]
					}
				}
			}
			admin.UpdateLoginTime(admin_info.Id)

			//******************************************
			//管理员日志
			logs := new(models.Logs)
			desc := "登陆用户名:" + admin_info.Username + "|^|登陆系统!|^|登陆ID:" + fmt.Sprintf("%d", admin_info.Id)
			logs.Save(admin_info, c.Controller, desc)
			//*****************************************

			data["status"] = "1"
			data["url"] = "/Message/"
			data["message"] = c.Message("login_success")
		} else {
			data["status"] = "0"
			data["url"] = "/"
			data["message"] = c.Message("login_password_error")
		}

		return c.RenderJson(data)
	}
}