Exemplo n.º 1
0
func (self *RegHandler) Post() {
	self.TplNames = "reg.html"
	self.Ctx.Request.ParseForm()
	username := self.Ctx.Request.Form.Get("username")
	password := self.Ctx.Request.Form.Get("password")
	usererr := helper.CheckUsername(username)

	if usererr == false {
		self.Data["UsernameErr"] = "Username error, Please to again"
		return
	}

	passerr := helper.CheckPassword(password)
	if passerr == false {
		self.Data["PasswordErr"] = "Password error, Please to again"
		return
	}

	pwd := helper.Encrypt_password(password, nil)

	//now := torgo.Date(time.Now(), "Y-m-d H:i:s")

	userInfo := models.CheckUserByNickname(username)
	fmt.Println("=============================")
	fmt.Println(userInfo.Nickname)

	//  检查该用户是否已经被注册
	if userInfo.Nickname == "" {

		//注册用户
		regErr := models.AddUser(username+"@insion.co", username, "", pwd, 1)
		fmt.Println("reg:s")
		fmt.Println(regErr)
		fmt.Println("reg:e ")
		//注册成功设置session
		//	self.SetSession("userid", userInfo.Id)
		//	self.SetSession("username", userInfo.Nickname)
		//	self.SetSession("userrole", userInfo.Role)
		//	self.SetSession("useremail", userInfo.Email)
		self.Ctx.Redirect(302, "/login")

	} else {
		self.Data["UsernameErr"] = "User already exists"
	}
	self.Render()
}
Exemplo n.º 2
0
func (self *RSettingHandler) Post() {
	switch {
	case self.Ctx.Request.RequestURI == "/root-setting-setroot":
		//设置管理员
		newroot := self.GetString("newroot")
		realname := self.GetString("realname")
		curpassword := self.GetString("curpassword")
		newpassword := self.GetString("newpassword")
		repassword := self.GetString("repassword")
		if newroot != "" && realname != "" && curpassword != "" && repassword != "" && newpassword == repassword {
			sess_username, _ := self.GetSession("username").(string)
			usr := models.GetUserByNickname(sess_username)

			if helper.Validate_password(usr.Password, curpassword) {

				if e := models.AddUser("", newroot, realname, helper.Encrypt_password(newpassword, nil), -1000); e != nil {
					self.Data["MsgErr"] = "添加新管理员“" + newroot + "”失败!"

				} else {
					self.Data["MsgErr"] = "添加新管理员“" + newroot + "”成功!"
				}

			} else {

				self.Data["MsgErr"] = "当前密码不正确!"
			}
		} else {
			msg := ""
			if curpassword == "" {
				msg = msg + "当前管理员密码不能为空!"
			}

			if newpassword == "" {
				msg = msg + "新增管理员密码不能为空!"
			}

			if repassword == "" {
				msg = msg + "新增管理员确认密码不能为空!"
			}

			if newpassword != repassword {
				msg = msg + "两次输入的新增管理员密码不一致!"
			}

			self.Data["MsgErr"] = msg
		}

	case self.Ctx.Request.RequestURI == "/root-setting-password":
		//密码修改
		oldpassword := self.GetString("oldpassword")
		newpassword := self.GetString("newpassword")
		repassword := self.GetString("repassword")

		if oldpassword != "" && repassword != "" && newpassword == repassword {
			sess_username, _ := self.GetSession("username").(string)
			usr := models.GetUserByNickname(sess_username)

			if helper.Validate_password(usr.Password, oldpassword) {
				usr.Password = helper.Encrypt_password(newpassword, nil)
				if e := models.SaveUser(usr); e != nil {
					self.Data["MsgErr"] = "更新密码失败!"

				} else {
					self.Data["MsgErr"] = "更新密码成功!"
				}

			}
		} else {
			msg := ""
			if oldpassword == "" {
				msg = msg + "原密码不能为空!"
			}

			if newpassword == "" {
				msg = msg + "新密码不能为空!"
			}

			if repassword == "" {
				msg = msg + "请输入确认密码!"
			}

			if newpassword != repassword {
				msg = msg + "两次输入的新密码不一致!"
			}

			self.Data["MsgErr"] = msg
		}

	case self.Ctx.Request.RequestURI == "/root-setting":
		//常规设置 POST
		title := self.GetString("title")
		title_en := self.GetString("title_en")
		keywords := self.GetString("keywords")
		description := self.GetString("description")
		company := self.GetString("company")
		copyright := self.GetString("copyright")
		site_email := self.GetString("site_email")
		tweibo := self.GetString("tweibo")
		sweibo := self.GetString("sweibo")
		statistics := self.GetString("statistics")

		models.SetKV("title", title)
		models.SetKV("title_en", title_en)
		models.SetKV("keywords", keywords)
		models.SetKV("description", description)

		models.SetKV("company", company)
		models.SetKV("copyright", copyright)
		models.SetKV("site_email", site_email)

		models.SetKV("tweibo", tweibo)
		models.SetKV("sweibo", sweibo)

		models.SetKV("statistics", statistics)

	}

	self.SetSession("MsgErr", self.Data["MsgErr"])
	self.Redirect(self.Ctx.Request.RequestURI, 302)
}