Exemplo n.º 1
0
// add user submit
func (this *UserController) PostAdd() {

	u := m.User{UserType: "系统管理员"}
	if err := this.ParseForm(&u); err != nil {
		this.Data[INFO] = FAILED
	}

	id, err := m.AddUser(&u)

	if err == nil && id > 0 {
		beego.Info("register success!!")
		this.Data[INFO] = SUCCESS
	} else {
		beego.Info("register failed!!", err.Error())
		this.Data[INFO] = FAILED
	}

	this.Layout = INDEX
	this.TplNames = "admin/userAdd.html"
}
Exemplo n.º 2
0
func (this *UserController) Register() {
	beego.Info("Register()")
	u := m.User{UserType: "普通用户"}

	if err := this.ParseForm(&u); err != nil {
		beego.Debug(err.Error())
		this.Data[INFO] = FAILED
	}

	//如果用户名存在
	username := strings.Trim(u.UserName, " ")
	exists := m.FindUserByUserName(username)
	if exists {
		this.Data[INFO] = "对不起,用户名已经存在"
		this.TplNames = "register.html"
		return
	}

	_, hd, err := this.GetFile("photo")
	if err != nil {
		beego.Error("no photo")
	}

	fileName := this.uploadFile(hd, "photo")
	if fileName != "" {
		u.PicUrl = fileName
	}

	id, err := m.AddUser(&u)
	if err == nil && id > 0 {
		beego.Info("register success!!")
		this.Data[INFO] = SUCCESS
	} else {
		beego.Info("register failed!!")
		this.Data[INFO] = FAILED
	}

	this.Data["User"] = m.FindUserById(id)
	this.Layout = INDEX
	this.TplNames = "admin/personalInfo.html"
}