コード例 #1
0
ファイル: userinfo.go プロジェクト: hngchiming/BTCsport
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
}
コード例 #2
0
ファイル: game.go プロジェクト: hngchiming/BTCsport
func (this *GameRouter) postData(Type string, id, uid int) {
	// Validate Bet amount
	amount_str := this.Input().Get("amount")
	if !models.ValidBetamount(amount_str) {
		this.SetSession("Error", ERROR_INVALIDINPUT)
		this.fail(id)
		return
	}

	// Validate if balance is enough
	amount, _ := strconv.ParseFloat(amount_str, 64)
	if !models.UserBalanceEnough(uid, amount) {
		this.SetSession("Error", ERROR_BALANCENOTENOUGH)
		this.fail(id)
		return
	}

	// Submit Post
	switch Type {
	case "AorB":
		// Validate radio input
		sliceAorB := []interface{}{"A_Win", "B_Win"}
		AorB := this.Input().Get("AorB")
		if !In_slice(AorB, sliceAorB) {
			this.SetSession("Error", ERROR_INVALIDINPUT)
			this.fail(id)
			return
		}

		// Send BTC to betaddress
		Type := " 主队赢"
		if AorB != "A_Win" {
			Type = " 客队赢"
		}
		user := models.UserByUid(uid)
		note := time.Now().Format(layout) + " 赛事ID:" + strconv.Itoa(id) + Type
		txhash, err := models.SendBTC(user.Btcaddress, BetAddr, note, amount)
		if err != nil {
			this.SetSession("Error", ERROR_CANTSENDBTC)
			this.fail(id)
			return
		}

		// Change database
		if !models.PlaceBet(id, uid, AorB, txhash, amount) {
			this.SetSession("Error", ERROR_DB)
			this.fail(id)
			return
		}

	case "OddEven":
		sliceOddEven := []interface{}{"Odd", "Even"}
		OddEven := this.Input().Get("OddEven")

		if !In_slice(OddEven, sliceOddEven) {
			this.SetSession("Error", ERROR_INVALIDINPUT)
			this.fail(id)
			return
		}

		// Send BTC to betaddress
		Type := " 单数总比分"
		if OddEven != "Odd" {
			Type = " 双数总比分"
		}
		user := models.UserByUid(uid)
		note := time.Now().Format(layout) + " 赛事ID:" + strconv.Itoa(id) + Type
		txhash, err := models.SendBTC(user.Btcaddress, BetAddr, note, amount)
		if err != nil {
			this.SetSession("Error", ERROR_CANTSENDBTC)
			this.fail(id)
			return
		}

		// Change database
		if !models.PlaceBet(id, uid, OddEven, txhash, amount) {
			this.SetSession("Error", ERROR_DB)
			this.fail(id)
			return
		}

	case "LargeSmall":
		sliceLargeSmall := []interface{}{"Large", "Small"}
		LargeSmall := this.Input().Get("LargeSmall")

		if !In_slice(LargeSmall, sliceLargeSmall) {
			this.SetSession("Error", ERROR_INVALIDINPUT)
			this.fail(id)
			return
		}

		// Send BTC to betaddress
		Type := " 大分"
		if LargeSmall != "Large" {
			Type = " 小分"
		}
		user := models.UserByUid(uid)
		note := time.Now().Format(layout) + " 赛事ID:" + strconv.Itoa(id) + Type
		txhash, err := models.SendBTC(user.Btcaddress, BetAddr, note, amount)
		if err != nil {
			this.SetSession("Error", ERROR_CANTSENDBTC)
			this.fail(id)
			return
		}

		// Change database
		if !models.PlaceBet(id, uid, LargeSmall, txhash, amount) {
			this.SetSession("Error", ERROR_DB)
			this.fail(id)
			return
		}

	}

	this.succ(id)
}