Example #1
0
//POST /account/edit
func (c Account) PostEdit(user models.User) revel.Result {
	c.Validation.Required(user.Name).Message("用户名不能为空")
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Account.Edit())
	}
	if user.HasName() {
		return c.Redirect(routes.User.Profile())
	}
	if user.Password != "" {
		if user.Password == user.ConfirmPassword {
			user.HashedPassword, user.Salt = models.GenHashPasswordAndSalt(user.Password)
			username := c.Session[USERNAME]
			u := models.GetCurrentUser(username)
			_, err := engine.Id(u.Id).Update(user)
			if err != nil {
				fmt.Println(err)
			}
			c.Session[USERNAME] = user.Name
			return c.Redirect(routes.User.Profile())
		} else {
			c.Flash.Error("passwords not match")
			return c.Redirect(routes.Account.Notice())
		}
	} else {
		username := c.Session[USERNAME]
		u := models.GetCurrentUser(username)
		_, err := engine.Id(u.Id).Cols("name").Update(user)
		if err != nil {
			fmt.Println(err)
			c.Flash.Error(err.Error())
		} else {
			c.Session[USERNAME] = user.Name
			c.Flash.Success("modify sucess")
		}
		return c.Redirect(routes.User.Profile())
	}

}
Example #2
0
File: user.go Project: jango2015/OJ
//GET /user/solved
func (u *User) Solved() revel.Result {
	username := u.Session[USERNAME]
	user := models.GetCurrentUser(username)
	if user != nil {
		//user solve problems
		usps, err := models.FindSovledProblems(user.Id)
		if err != nil {
			u.Flash.Error(err.Error())
			return u.Render()
		} else {
			return u.Render(usps)
		}
	} else {
		return u.Render()
	}

}
Example #3
0
File: code.go Project: jango2015/OJ
func (c *Code) Submit(code string, problemId int64, lang string) revel.Result {
	source := &models.Source{}
	path := source.GenPath()
	source.CreatedAt = time.Now()
	source.Status = models.UnHandled
	source.ProblemId = problemId
	//get user id
	username := c.Session[USERNAME]
	u := models.GetCurrentUser(username)
	if u != nil {
		source.UserId = u.Id
	} else {
		c.Flash.Error("wrong user")
		return c.Redirect(routes.Code.Answer(problemId))
	}
	switch lang {
	case "c":
		_, err := util.WriteFile(path+"/tmp.c", []byte(code))
		if err != nil {
			log.Println(err)
		}
		source.Lang = models.C
	case "cpp":
		util.WriteFile(path+"/tmp.cpp", []byte(code))
		source.Lang = models.CPP
	case "go":
		util.WriteFile(path+"/tmp.go", []byte(code))
		source.Lang = models.Go
	default:
		c.Flash.Error("wrong lang %s\n", lang)
		return c.Redirect(routes.Code.Answer(problemId))
	}
	_, err := engine.Insert(source)
	if err != nil {
		c.Flash.Error(err.Error())
		return c.Redirect(routes.Code.Answer(problemId))
	}
	c.Flash.Success(username + " 提交成功")
	return c.Redirect("/code/status")
}
Example #4
0
//GET /account/resent-active-code
func (c Account) ResentActiveCode() revel.Result {
	username := c.Session[USERNAME]
	user := models.GetCurrentUser(username)
	subject := "activate password"
	content := fmt.Sprintf(`<h2><a href="http://%s:%s/account/activate/%s">`+
		`activate account</a></h2>`,
		appAddr, appPort, user.ActiveCode)
	err := SendMail(
		subject,
		content,
		smtpConfig.Username,
		[]string{user.Email},
		smtpConfig,
		true)

	if err != nil {
		fmt.Println(err)
	}
	c.Flash.Success("please check email " +
		user.Email +
		"to make your account active")
	return c.Redirect(routes.Account.Notice())
}