|
|
|
@ -26,6 +26,9 @@ import (
|
|
|
|
|
const (
|
|
|
|
|
minimumContentLen = 3
|
|
|
|
|
minimumTitleLen = 3
|
|
|
|
|
base10 = 10
|
|
|
|
|
size8Bit = 8
|
|
|
|
|
size64Bit = 64
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
@ -66,7 +69,7 @@ func (f *NewDecisionForm) Validate() (bool, *Decision) {
|
|
|
|
|
f.Errors["Content"] = fmt.Sprintf("Please enter at least %d words as Text.", minimumContentLen)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if voteType, err := strconv.ParseUint(f.VoteType, 10, 8); err != nil || (voteType != 0 && voteType != 1) {
|
|
|
|
|
if voteType, err := strconv.ParseUint(f.VoteType, base10, size8Bit); err != nil || (voteType != 0 && voteType != 1) {
|
|
|
|
|
f.Errors["VoteType"] = fmt.Sprint("Please choose a valid vote type.", err)
|
|
|
|
|
} else {
|
|
|
|
|
data.VoteType = VoteType(uint8(voteType))
|
|
|
|
@ -106,7 +109,7 @@ func (f *EditDecisionForm) Validate() (bool, *Decision) {
|
|
|
|
|
f.Errors["Content"] = fmt.Sprintf("Please enter at least %d words as Text.", minimumContentLen)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if voteType, err := strconv.ParseUint(f.VoteType, 10, 8); err != nil || (voteType != 0 && voteType != 1) {
|
|
|
|
|
if voteType, err := strconv.ParseUint(f.VoteType, base10, size8Bit); err != nil || (voteType != 0 && voteType != 1) {
|
|
|
|
|
f.Errors["VoteType"] = fmt.Sprint("Please choose a valid vote type.", err)
|
|
|
|
|
} else {
|
|
|
|
|
data.VoteType = VoteType(uint8(voteType))
|
|
|
|
@ -142,7 +145,7 @@ func (f *ProxyVoteForm) Validate() (bool, *Voter, *Vote, string) {
|
|
|
|
|
|
|
|
|
|
data := &Vote{}
|
|
|
|
|
|
|
|
|
|
if voterID, err = strconv.ParseInt(f.Voter, 10, 64); err != nil {
|
|
|
|
|
if voterID, err = strconv.ParseInt(f.Voter, base10, size64Bit); err != nil {
|
|
|
|
|
f.Errors["Voter"] = fmt.Sprintf("Please choose a valid voter: %v.", err)
|
|
|
|
|
} else if voter, err = GetVoterByID(voterID); err != nil {
|
|
|
|
|
f.Errors["Voter"] = fmt.Sprintf("Please choose a valid voter: %v.", err)
|
|
|
|
@ -150,7 +153,7 @@ func (f *ProxyVoteForm) Validate() (bool, *Voter, *Vote, string) {
|
|
|
|
|
data.VoterID = voter.ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if vote, err = strconv.ParseInt(f.Vote, 10, 8); err != nil {
|
|
|
|
|
if vote, err = strconv.ParseInt(f.Vote, base10, size8Bit); err != nil {
|
|
|
|
|
f.Errors["Vote"] = fmt.Sprintf("Please choose a valid vote: %v.", err)
|
|
|
|
|
} else if voteChoice, ok := VoteChoices[vote]; !ok {
|
|
|
|
|
f.Errors["Vote"] = "Please choose a valid vote."
|
|
|
|
|