func (this *UserRouter) Post() { // Get _User session --> uid user_sess := this.GetSession("_User") if user_sess == nil { this.Ctx.Redirect(302, "/login") return } user := user_sess.(Session_User) // Get username username := user.Username // Get user inputs inputs := this.Input() email := inputs.Get("email") addr := inputs.Get("address") amount := inputs.Get("amount") fdps := inputs.Get("fundpassword") authen := models.RandString(15) // Validate inputs if models.ValidString(fdps) && models.ValidEmail(email) && models.ValidBetamount(amount) { // Validate fundpass if !models.FundPassMatch(username, fdps) { this.SetSession("Error", ERROR_PASSINCORRECT) this.fail() return } // Validate Email if !models.EmailMatch(username, email) { this.SetSession("Error", ERROR_EMAILNOTMATCH) this.fail() return } // Check if balance enough amount_float64, _ := strconv.ParseFloat(amount, 64) if !models.UserBalanceEnough(user.Uid, amount_float64) { this.SetSession("Error", ERROR_BALANCENOTENOUGH) this.fail() return } // Send Email Code to User if !models.SendEmail(email, "提现申请", "申请提现"+amount+"BTC到以下地址"+addr+"\n请复制右边的Code,以完成提现操作", authen) { this.SetSession("Error", ERROR_EMAILNOTSENT) this.fail() return } this.SetSession("Data", []string{addr, authen, amount}) this.succ() return } this.SetSession("Error", ERROR_INVALIDINPUT) this.fail() return }
func (this *ForgetRouter) Post() { // Get inputs and validate inputs := this.Input() // Check token in case twice submit var token string token_sess := this.GetSession("Token") if token_sess != nil { this.DelSession("Token") token = fmt.Sprintf("%d", token_sess.(int64)) } if token != inputs.Get("token") { this.SetSession("Error", ERROR_TWICESUBMIT) models.Log(models.Log_Struct{"error", "Forget:", errors.New("Submit twice")}) this.fail() return } // Check cookie in case bots cookie_sess := this.GetSession("Cookie") if cookie_sess != nil { this.DelSession("Cookie") cookie := cookie_sess.(string) if cookie != this.Ctx.GetCookie("nobot") { this.SetSession("Error", ERROR_CAPTCHA) models.Log(models.Log_Struct{"error", "Forget:", errors.New("No bot is allowed")}) this.fail() return } } // Validate inputs username := strings.TrimSpace(inputs.Get("username")) dateofbirth := strings.TrimSpace(inputs.Get("birth")) email := strings.TrimSpace(inputs.Get("email")) if models.ValidString(username) && models.ValidEmail(email) && models.ValidBirth(dateofbirth) { // Check if user exist if !models.UserExist(username) { models.Log(models.Log_Struct{"info", "Forget:", errors.New("User not exist.")}) this.SetSession("Error", ERROR_USERNOTEXIST) this.fail() return } // Check if birth matches if !models.BirthMatch(username, dateofbirth) { models.Log(models.Log_Struct{"info", "Forget:", errors.New("Birth not match.")}) this.SetSession("Error", ERROR_BIRTHNOTMATCH) this.fail() return } // Check if email mathces if !models.EmailMatch(username, email) { models.Log(models.Log_Struct{"info", "Forget:", errors.New("Email not match.")}) this.SetSession("Error", ERROR_EMAILNOTMATCH) this.fail() return } // Send Email to authenticate authen := models.RandString(8) if !models.SendEmail(email, "重设密码", username+": 请复制验证码,以完成重设密码操作---->", authen) { models.Log(models.Log_Struct{"warn", "Forget:", errors.New("Cant send email to authen password reset.")}) this.SetSession("Error", ERROR_EMAILNOTSENT) this.fail() return } this.SetSession("Username", username) this.SetSession("Authen", authen) this.succ() return } models.Log(models.Log_Struct{"info", "Forget:", errors.New("Failed, invalid data.")}) this.SetSession("Error", ERROR_INVALIDINPUT) this.fail() }