Example #1
0
// 个人信息
func (this *MainController) Profile() {
	beego.ReadFromRequest(&this.Controller)
	user, _ := models.UserGetById(this.userId)

	if this.isPost() {
		flash := beego.NewFlash()
		user.Email = this.GetString("email")
		user.Update()
		password1 := this.GetString("password1")
		password2 := this.GetString("password2")
		if password1 != "" {
			if len(password1) < 6 {
				flash.Error("密码长度必须大于6位")
				flash.Store(&this.Controller)
				this.redirect(beego.UrlFor(".Profile"))
			} else if password2 != password1 {
				flash.Error("两次输入的密码不一致")
				flash.Store(&this.Controller)
				this.redirect(beego.UrlFor(".Profile"))
			} else {
				user.Salt = string(utils.RandomCreateBytes(10))
				user.Password = libs.Md5([]byte(password1 + user.Salt))
				user.Update()
			}
		}
		flash.Success("修改成功!")
		flash.Store(&this.Controller)
		this.redirect(beego.UrlFor(".Profile"))
	}

	this.Data["pageTitle"] = "个人信息"
	this.Data["user"] = user
	this.display()
}
Example #2
0
func (this *AuthController) DoRegister() {
	this.CheckRequestFrequency(3, 15, 30)
	this.Layout = "layout.html"
	this.TplNames = "register.html"
	valid := validation.Validation{}
	form := RegisterForm{}
	if err := this.ParseForm(&form); err != nil {
		beego.Error(err)
	}
	b, err := valid.Valid(form)
	if err != nil {
		beego.Error(err)
	}
	if !b {
		this.registerPageWithErrors(form, valid.Errors)
		return
	}
	//验证用户名
	user := models.User{Username: form.Username}
	if err := user.ValidUsername(); err != nil {
		valid.SetError("username", err.Error())
		this.registerPageWithErrors(form, valid.Errors)
		return
	} else {
		if user.Read("Username") == nil {
			valid.SetError("username", fmt.Sprintf("%s已被使用,请使用其他用户名!", form.Username))
			this.registerPageWithErrors(form, valid.Errors)
			return
		}
	}
	//验证email未被注册
	user.Email = form.Email
	if user.Read("Email") == nil {
		valid.SetError("email", "已被使用,请直接使用此电邮登录")
		this.registerPageWithErrors(form, valid.Errors)
		return
	}
	//通过所有验证
	actCode, _ := user.GenerateActivateCode()
	user.SetPassword(form.Password)
	if err := user.Insert(); err != nil {
		beego.Error(err)
		this.Abort("500")
		return
	}
	sub := sendcloud.NewSubstitution()
	sub.AddTo(user.Email)
	sub.AddSub("%appname%", setting.AppName)
	sub.AddSub("%name%", user.Username)
	sub.AddSub("%url%", setting.AppUrl+beego.UrlFor("AuthController.Activate", ":code", actCode))
	if err := setting.Sendcloud.SendTemplate("gotalk_register", setting.AppName+"欢迎你", setting.From, setting.FromName, sub); err != nil {
		beego.Error(err)
	}
	this.FlashWrite("notice", fmt.Sprintf("注册成功!欢迎你, %s。建议你再花点时间上传头像、验证电子邮件!", user.Username))
	this.LogUserIn(&user, false)
	userEditUrl := beego.UrlFor("UserController.Edit", ":username", user.Username)
	this.Redirect(userEditUrl, 302)
	return
}
Example #3
0
File: user.go Project: grr89/hrkb
//add new user
func (c *User) Post() {

	var v M.ValidMap
	var err error
	var msg string

	c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
	c.TplNames = "user/form.tpl"

	d := M.User{}

	flash := beego.NewFlash()

	err = c.ParseForm(&d)

	if err != nil {
		beego.Error(err)
		flash.Notice(T("internal"))
		flash.Store(&c.Controller)
		c.Redirect(beego.UrlFor("User.Index"), 302)
		return
	}

	d.GToken = sql.NullString{c.Ctx.Request.Form["gtoken"][0], true}

	d.Active = true

	if d.Id == 0 {
		v, err = DM.Insert(&d)
		msg = T("user_created")
	} else {
		v, err = DM.Update(&d)
		msg = T("user_updated", map[string]interface{}{"Login": d.Login})
		c.Data["isEdit"] = true
	}

	if err != nil {
		beego.Error(err)
	}

	if !v.HasErrors() {
		flash.Notice(msg)
		flash.Store(&c.Controller)
		c.Redirect(beego.UrlFor("User.Index"), 302)
		return
	}

	M.ExpandFormErrors(&v, c.Data)
	c.Data["user"] = d
	c.Data["roles"] = c.rolesList()
}
Example #4
0
File: crit.go Project: grr89/hrkb
// update criteria
func (c *Crit) Get() {
	c.Data["isEdit"] = true
	c.TplNames = "crit/form.tpl"
	c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
	id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))

	if err != nil {
		beego.Error(err)
		id = 0
	}
	var crit M.Crit
	if DM.FindByPk(&crit, id) != nil {
		flash := beego.NewFlash()
		flash.Notice(T("crit_not_found"))
		flash.Store(&c.Controller)
		c.Redirect(beego.UrlFor("Crit.Index"), 302)
		return
	}
	var deps []M.Dep
	err = DM.FindAll(&M.Dep{}, &deps, M.Sf{"Id", "Title"}, M.Where{})
	if err != nil {
		beego.Error(err)
	}

	c.Data["deps"] = deps
	c.Data["crit"] = crit
}
Example #5
0
File: crit.go Project: grr89/hrkb
//remove criteria
func (c *Crit) Remove() {
	s := T("crit_not_found")
	crit := M.Crit{}

	id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))

	if err == nil {
		err = DM.DeleteByPk(&crit, id)
	}

	if err != nil {
		beego.Error(err)
	} else {
		s = T("crit_removed", map[string]interface{}{"Title": crit.Title})
	}

	if c.IsAjax() {
		c.Data["json"] = RJson{s, err == nil}
		return
	}

	flash := beego.NewFlash()
	flash.Notice(s)
	flash.Store(&c.Controller)

	c.Redirect(beego.UrlFor("Crit.Index"), 302)

}
Example #6
0
// 任务执行日志列表
func (this *TaskController) Logs() {
	taskId, _ := this.GetInt("id")
	page, _ := this.GetInt("page")
	if page < 1 {
		page = 1
	}

	task, err := models.TaskGetById(taskId)
	if err != nil {
		this.showMsg(err.Error())
	}

	result, count := models.TaskLogGetList(page, this.pageSize, "task_id", task.Id)

	list := make([]map[string]interface{}, len(result))
	for k, v := range result {
		row := make(map[string]interface{})
		row["id"] = v.Id
		row["start_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
		row["process_time"] = float64(v.ProcessTime) / 1000
		row["ouput_size"] = libs.SizeFormat(float64(len(v.Output)))
		row["status"] = v.Status
		list[k] = row
	}

	this.Data["pageTitle"] = "任务执行日志"
	this.Data["list"] = list
	this.Data["task"] = task
	this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.UrlFor("TaskController.Logs", "id", taskId), true).ToString()
	this.display()
}
Example #7
0
File: user.go Project: grr89/hrkb
//view concrete user
func (c *User) Get() {

	var u M.User
	var err error

	c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
	c.Data["isEdit"] = true
	c.TplNames = "user/form.tpl"

	id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))

	if err == nil {
		err = DM.FindByPk(&u, id)
	}

	if err != nil {
		flash := beego.NewFlash()
		flash.Notice(T("user_not_found"))
		flash.Store(&c.Controller)
		c.Redirect(beego.UrlFor("User.Index"), 302)
		return
	}

	c.Data["user"] = u
	c.Data["roles"] = c.rolesList()
}
Example #8
0
File: lang.go Project: grr89/hrkb
func (c *Lang) Remove() {

	s := T("lang_not_found")
	d := M.Lang{}

	id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))

	if err == nil {
		err = DM.DeleteByPkWithFetch(&d, id)
	}

	if err == nil {
		s = T("lang_removed")
		err = c.cleanLang(d.Code)
	}

	if err != nil {
		beego.Error(err)
	}

	if c.IsAjax() {
		c.Data["json"] = RJson{s, err == nil}
		return
	}

	flash := beego.NewFlash()
	flash.Notice(s)
	flash.Store(&c.Controller)

	c.Redirect(beego.UrlFor("Lang.Index"), 302)

}
Example #9
0
File: user.go Project: grr89/hrkb
//remove user
func (c *User) Remove() {

	s := T("user_not_found")
	d := M.User{}

	id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))

	if err == nil {
		err = DM.DeleteByPk(&d, id)
	}

	if err != nil {
		beego.Error(err)
	} else {
		s = T("user_removed", map[string]interface{}{"Login": d.Login})
	}

	if c.IsAjax() {
		c.Data["json"] = RJson{s, err == nil}
		return
	}

	flash := beego.NewFlash()
	flash.Notice(s)
	flash.Store(&c.Controller)

	c.Redirect(beego.UrlFor("User.Index"), 302)
}
Example #10
0
File: cand.go Project: grr89/hrkb
//edit candidate
func (c *Cand) Edit() {

	flash := beego.NewFlash()
	var deps []M.Dep
	var err error

	if err := DM.FindAll(&M.Dep{}, &deps, M.Sf{}, M.Where{}); err != nil {
		beego.Error("Department find error: ", err)

		flash.Error(T("internal"))
		flash.Store(&c.Controller)

		return
	}
	var id int

	if id, err = strconv.Atoi(c.Ctx.Input.Param(":id")); err != nil {
		beego.Error(err)
	}

	var cand M.Cand

	if DM.FindByPk(&cand, id) != nil {
		flash.Notice(T("nocand"))
		flash.Store(&c.Controller)

		c.Redirect(beego.UrlFor("Cand.Index"), 302)
		return
	}

	c.Data["cand"] = cand
	c.Data["deps"] = deps
	c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
}
Example #11
0
File: dep.go Project: grr89/hrkb
//save concrete or new department
func (c *Dep) Post() {

	var v M.ValidMap
	var err error
	var msg string

	c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
	c.TplNames = "dep/form.tpl"

	d := M.Dep{}
	flash := beego.NewFlash()
	err = c.ParseForm(&d)

	if err != nil {
		beego.Error(err)
		flash.Notice(T("internal"))
		flash.Store(&c.Controller)
		c.Redirect(beego.UrlFor("Dep.Index"), 302)
		return
	}

	if d.Id == 0 {
		v, err = DM.Insert(&d, "Title")
		msg = T("dep_created")
	} else {
		v, err = DM.Update(&d, "Title")
		msg = T("dep_updated", map[string]interface{}{"Title": d.Title})
		c.Data["isEdit"] = true
	}

	if err != nil {
		beego.Error(err)
	}

	if !v.HasErrors() {

		flash.Notice(msg)
		flash.Store(&c.Controller)

		c.Redirect(beego.UrlFor("Dep.Index"), 302)
		return
	}

	M.ExpandFormErrors(&v, c.Data)
	c.Data["dep"] = d

}
Example #12
0
File: main.go Project: grr89/hrkb
//show auth form
func (c *Main) Get() {
	if c.GetSession("uid") != nil {
		c.Redirect(beego.UrlFor("User.Index"), 302)
	}
	c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
	c.TplNames = "loginform.tpl"
	c.Data["title"] = "HRKB"
}
Example #13
0
func (this *CompanyController) Del() {
	id, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
	beego.Debug("id=", id)
	o := orm.NewOrm()
	if num, err := o.Delete(&models.Company{Id: int64(id)}); err == nil {
		beego.Debug(num)
		this.Redirect(beego.UrlFor("CompanyController.Index"), 302)
	} else {
		beego.Error(err)
	}
}
Example #14
0
func (this *CategoryController) Store() {
	pid, _ := strconv.Atoi(this.GetString("Pid"))
	name := this.GetString("Name")
	o := orm.NewOrm()
	category := new(models.Category)
	category.Pid = int64(pid)
	category.Name = name
	//category := &models.Category{Pid:int64(pid),Name:name}
	o.Insert(category)
	this.Redirect(beego.UrlFor("CategoryController.Index"), 302)

}
Example #15
0
// 任务列表
func (this *TaskController) List() {
	page, _ := this.GetInt("page")
	if page < 1 {
		page = 1
	}
	groupId, _ := this.GetInt("groupid")
	filters := make([]interface{}, 0)
	if groupId > 0 {
		filters = append(filters, "group_id", groupId)
	}
	result, count := models.TaskGetList(page, this.pageSize, filters...)

	list := make([]map[string]interface{}, len(result))
	for k, v := range result {
		row := make(map[string]interface{})
		row["id"] = v.Id
		row["name"] = v.TaskName
		row["cron_spec"] = v.CronSpec
		row["status"] = v.Status
		row["description"] = v.Description

		e := jobs.GetEntryById(v.Id)
		if e != nil {
			row["next_time"] = beego.Date(e.Next, "Y-m-d H:i:s")
			row["prev_time"] = "-"
			if e.Prev.Unix() > 0 {
				row["prev_time"] = beego.Date(e.Prev, "Y-m-d H:i:s")
			} else if v.PrevTime > 0 {
				row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s")
			}
			row["running"] = 1
		} else {
			row["next_time"] = "-"
			if v.PrevTime > 0 {
				row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s")
			} else {
				row["prev_time"] = "-"
			}
			row["running"] = 0
		}
		list[k] = row
	}

	// 分组列表
	groups, _ := models.TaskGroupGetList(1, 100)

	this.Data["pageTitle"] = "任务列表"
	this.Data["list"] = list
	this.Data["groups"] = groups
	this.Data["groupid"] = groupId
	this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.UrlFor("TaskController.List", "groupid", groupId), true).ToString()
	this.display()
}
Example #16
0
// 登录
func (this *MainController) Login() {
	if this.userId > 0 {
		this.redirect("/")
	}
	beego.ReadFromRequest(&this.Controller)
	if this.isPost() {
		flash := beego.NewFlash()

		username := strings.TrimSpace(this.GetString("username"))
		password := strings.TrimSpace(this.GetString("password"))
		remember := this.GetString("remember")
		if username != "" && password != "" {
			user, err := models.UserGetByName(username)
			errorMsg := ""
			if err != nil || user.Password != libs.Md5([]byte(password+user.Salt)) {
				errorMsg = "帐号或密码错误"
			} else if user.Status == -1 {
				errorMsg = "该帐号已禁用"
			} else {
				user.LastIp = this.getClientIp()
				user.LastLogin = time.Now().Unix()
				models.UserUpdate(user)

				authkey := libs.Md5([]byte(this.getClientIp() + "|" + user.Password + user.Salt))
				if remember == "yes" {
					this.Ctx.SetCookie("auth", strconv.Itoa(user.Id)+"|"+authkey, 7*86400)
				} else {
					this.Ctx.SetCookie("auth", strconv.Itoa(user.Id)+"|"+authkey)
				}

				this.redirect(beego.UrlFor("TaskController.List"))
			}
			flash.Error(errorMsg)
			flash.Store(&this.Controller)
			this.redirect(beego.UrlFor("MainController.Login"))
		}
	}

	this.TplNames = "main/login.html"
}
Example #17
0
func (this *GroupController) List() {
	page, _ := this.GetInt("page")
	if page < 1 {
		page = 1
	}

	list, count := models.TaskGroupGetList(page, this.pageSize)

	this.Data["pageTitle"] = "分组列表"
	this.Data["list"] = list
	this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.UrlFor("GroupController.List"), true).ToString()
	this.display()
}
Example #18
0
File: lang.go Project: grr89/hrkb
func (c *Lang) Default() {
	id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))

	if err == nil {
		err = M.Lang{}.SetDefault(id)
	}

	if err != nil {
		beego.Error(err)
	}

	c.Redirect(beego.UrlFor("Lang.Index"), 302)
}
Example #19
0
func (this *UserController) ResendValidation() {
	//获取用户,并且判断是否有权限执行此操作
	user, err := this.getUserFromRequest()
	if err != nil {
		this.Abort("404")
	}
	if !this.canEdit(user) {
		this.Abort("403")
	}
	this.resendValidation(&user)
	this.FlashWrite("notice", fmt.Sprintf("验证邮件已经发送,请登录%s进行验证。", user.Email))
	redirectUrl := beego.UrlFor("UserController.Edit", ":username", user.Username)
	this.Redirect(redirectUrl, 302)
}
Example #20
0
File: lang.go Project: grr89/hrkb
func (c *Lang) Download() {
	var l M.Lang
	id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
	if err == nil {
		err = DM.FindByPk(&l, id)
	}

	if err != nil {
		beego.Error(err)
		c.Redirect(beego.UrlFor("Lang.Index"), 302)
	}

	c.Ctx.Output.Download(c.langFileName("lang::folder", l.Code))
}
Example #21
0
func (this *CompanyController) Update() {

	o := orm.NewOrm()
	id, _ := strconv.Atoi(this.GetString("Id"))
	company := models.Company{Id: int64(id)}
	error := o.Read(&company)
	beego.Debug(error)
	if error == nil {
		beego.Debug("start")
		//company.Sname = this.GetString("Sname")
		//company.Symbol = this.GetString("Symbol")
		this.ParseForm(&company)
		_, error_u := o.Update(&company, "sname", "symbol")
		if error_u != nil {
			beego.Error(error_u)
		} else {
			this.Redirect(beego.UrlFor("CompanyController.Index"), 302)
		}
	} else {
		beego.Error(error)
		this.Redirect(beego.UrlFor("CompanyController.Edit", "id", strconv.Itoa(id)), 302)
	}

}
Example #22
0
func (this *CategoryController) Update() {
	id, _ := strconv.Atoi(this.GetString("Id"))
	name := this.GetString("Name")
	o := orm.NewOrm()
	category := models.Category{Id: int64(id)}
	error := o.Read(&category)
	if error != nil {
		beego.Error("error=", error)
	}
	beego.Debug("category=", category)
	category.Name = name
	beego.Debug("category=", category)
	o.Update(&category, "name")
	this.Redirect(beego.UrlFor("CategoryController.Index"), 302)
}
Example #23
0
File: crit.go Project: grr89/hrkb
// save criteria
func (c *Crit) Post() {
	var v M.ValidMap
	var err error
	msg := T("crit_created")

	c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
	c.TplNames = "crit/form.tpl"

	flash := beego.NewFlash()
	crit := M.Crit{}

	err = c.ParseForm(&crit)

	if crit.Id != 0 {
		msg = T("crit_updated", map[string]interface{}{"Title": crit.Title})
		c.Data["isEdit"] = true
	}

	if err == nil {
		if crit.Id == 0 {
			v, err = DM.Insert(&crit, "Title", "Dep")
		} else {
			v, err = DM.Update(&crit, "Title", "Dep")
		}
	}

	if err != nil {
		beego.Error(err)
	}

	if !v.HasErrors() && err == nil {
		flash.Notice(msg)
		flash.Store(&c.Controller)
		c.Redirect(beego.UrlFor("Crit.Index"), 302)
		return
	}

	var deps []M.Dep
	err = DM.FindAll(&M.Dep{}, &deps, M.Sf{"Id", "Title"}, M.Where{})
	if err != nil {
		beego.Error(err)
	}

	c.Data["deps"] = deps
	c.Data["crit"] = crit
	M.ExpandFormErrors(&v, c.Data)

}
Example #24
0
func (this *UserController) resendValidation(user *models.User) {
	//发验证邮件
	sub := sendcloud.NewSubstitution()
	sub.AddTo(user.Email)
	sub.AddSub("%name%", user.Username)
	sub.AddSub("%appname%", setting.AppName)
	code, err := user.GenerateActivateCode()
	if err != nil {
		beego.Trace(err)
		this.Abort("500")
	}
	sub.AddSub("%url%", setting.AppUrl+beego.UrlFor("AuthController.Activate", ":code", code))
	if err := setting.Sendcloud.SendTemplate("gotalk_revalidate", setting.AppName+"邮件验证", setting.From, setting.FromName, sub); err != nil {
		beego.Error(err)
	}
}
Example #25
0
func (this *ContentController) Store() {
	o := orm.NewOrm()

	f, h, _ := this.GetFile("Filepath")
	defer f.Close()

	newdir := "./static/upload/" + time.Now().Format("20151121")
	beego.Debug(newdir)
	os.MkdirAll(newdir, 0777)
	newfile := newdir + "/" + h.Filename

	this.SaveToFile("Filepath", newfile)

	company_id, _ := this.GetInt64("company_id")
	company := models.Company{Id: company_id}
	o.Read(&company)
	beego.Debug(company)
	category_id, _ := this.GetInt64("category_id")
	category := models.Category{Id: category_id}
	o.Read(&category)
	beego.Debug(category)

	user_id := int64(1)
	user := models.User{Id: user_id}
	o.Read(&user)
	beego.Debug(user)

	title := this.GetString("Title")
	Content := this.GetString("Content")

	content := &models.Content{}
	content.Title = title
	content.Content = Content
	content.Category = &category
	content.Company = &company
	content.Filepath = newfile
	content.User = &user

	beego.Debug(content)

	_, e := o.Insert(content)
	if e != nil {
		beego.Error(e)
	}
	this.Redirect(beego.UrlFor("ContentController.Index"), 302)

}
Example #26
0
File: issue.go Project: grr89/hrkb
func (c *Issue) ReportIssue() {
	if !c.IsAjax() {
		c.Redirect(beego.UrlFor("Cand.Index"), 302)
		return
	}

	var fLabels string

	form := IssueForm{}
	if c.CheckErr(c.ParseForm(&form), internalErr) {
		return
	}
	labels := c.GetStrings("labels[]")
	fLabels = strings.Join(labels, ",")

	authToken := c.GetSession("gitlabToken")

	if authToken == nil {
		c.CheckErr(notNilErr, gitlabTokenReq, "Auth token for gitlab required")
		return
	}

	issueReq := IssueReq{}
	issueReq.PID = gitlabProject
	issueReq.Title = form.Title
	issueReq.Desc = form.Desc
	issueReq.Labels = fLabels

	data, err := json.Marshal(&issueReq)
	if c.CheckErr(err, marshalErr) {
		return
	}

	res, err := http.Post(gitlabUrl+"projects/"+gitlabProject+"/issues?private_token="+authToken.(string), "application/json", bytes.NewBuffer(data))
	if c.CheckErr(err, gitlabAuthFailed) {
		return
	}

	if res.Status != "201 Created" {
		c.CheckErr(notNilErr, gitlabAuthFailed, res.Status)
		return
	}

	c.Data["json"] = RJson{T("issue_create_success"), true}
}
Example #27
0
// 暂停任务
func (this *TaskController) Pause() {
	id, _ := this.GetInt("id")

	task, err := models.TaskGetById(id)
	if err != nil {
		this.showMsg(err.Error())
	}

	jobs.RemoveJob(id)
	task.Status = 0
	task.Update()

	refer := this.Ctx.Request.Referer()
	if refer == "" {
		refer = beego.UrlFor("TaskController.List")
	}
	this.redirect(refer)
}
Example #28
0
//输入email,发送重设密码邮件
func (this *AuthController) ForgetPassword() {
	this.Data["PageTitle"] = fmt.Sprintf("忘记密码 | %s", setting.AppName)
	this.Layout = "layout.html"
	this.TplNames = "forget-password.html"
	valid := validation.Validation{}
	form := ForgetPasswordForm{}
	if this.Ctx.Request.Method == "POST" {
		if err := this.ParseForm(&form); err != nil {
			beego.Error(err)
		}
		_, err := valid.Valid(form)
		if err != nil {
			beego.Error(err)
		}
		user := models.User{Email: form.Email}
		if err := user.Read("Email"); err != nil {
			beego.Trace(user)
			beego.Trace(form)
			valid.SetError("Email", "此电子邮件并未注册")
		}
		beego.Trace(valid.Errors)
		if len(valid.Errors) == 0 {
			//发送忘记密码邮件
			code, err := user.GenerateActivateCode()
			if err != nil {
				this.Abort("500")
			}
			sub := sendcloud.NewSubstitution()
			sub.AddTo(user.Email)
			sub.AddSub("%appname%", setting.AppName)
			sub.AddSub("%name%", user.Username)
			sub.AddSub("%url%", setting.AppUrl+beego.UrlFor("AuthController.ResetPassword", ":code", code))
			if err := setting.Sendcloud.SendTemplate("gotalk_password", setting.AppName+"忘记密码", setting.From, setting.FromName, sub); err != nil {
				beego.Error(err)
			}
			this.FlashWrite("notice", fmt.Sprintf("重设密码的方法已经发到%s。请查收!", user.Email))
			this.Redirect("/", 302)
		} else {
			this.Data["HasError"] = true
			this.Data["errors"] = valid.Errors
		}
	}
}
Example #29
0
//save account settings
func (c *Prof) Post() {
	var v M.ValidMap
	var err error
	var msg string
	s := []string{"Name", "Email", "NotifyByMail", "NotifyByTelegram"}

	c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
	c.TplNames = "prof/get.tpl"

	d := M.Profile{}
	err = c.ParseForm(&d)
	d.Id = c.GetSession("uid").(int)

	if err == nil && d.Password != "" {
		s = append(s, "Password")
	}

	if err == nil {
		v, err = DM.Update(&d, s...)
	}

	if err == nil && !v.HasErrors() {
		c.SetSession("name", d.Name)
		msg = T("account_saved")
	}

	if err != nil {
		msg = T("internal")
		beego.Error(err)
	}

	if msg != "" {
		flash := beego.NewFlash()
		flash.Notice(msg)
		flash.Store(&c.Controller)
		c.Redirect(beego.UrlFor("Prof.Get"), 302)
		return
	}

	M.ExpandFormErrors(&v, c.Data)
	c.Data["Name"] = d.Name
}
Example #30
0
func (node *tagURLForNode) Execute(ctx *p2.ExecutionContext, buffer *bytes.Buffer) *p2.Error {
	args := make([]string, len(node.objectEvaluators))
	for i, ev := range node.objectEvaluators {
		obj, err := ev.Evaluate(ctx)
		if err != nil {
			return err
		}
		args[i] = obj.String()
	}

	params := make([]interface{}, len(args)-1)
	for i := range params {
		params[i] = args[i+1]
	}

	url := beego.UrlFor(args[0], params...)

	buffer.WriteString(url)
	return nil
}