Пример #1
0
func (this *LoginRouter) Get() {
	// Set const
	this.Data["App_Name"] = App_Name
	// xsrf
	this.Data["xsrf"] = template.HTML(this.XsrfFormHtml())
	// set token in case twice submit
	Token := models.Token()
	this.SetSession("Token", Token)
	// set cookie not bot in case bots
	Cookies := models.RandString(20)
	this.SetSession("Cookie", Cookies)

	this.Data["Token"] = Token
	this.Data["Cookie"] = Cookies

	// Get referral
	Refer := this.Input().Get("username")
	if models.UserExist(Refer) {
		this.Data["Refer"] = Refer
	} else {
		models.Log(models.Log_Struct{"error", "Login:"******"No such referer")})
	}

	// Get User Session
	var user Session_User
	u := this.GetSession("_User")
	if u != nil {
		user = u.(Session_User)
		this.Data["User"] = user
	} else {
		this.Data["User"] = false
	}

	// Show the login page or Error page
	var showLogin bool
	v := this.GetSession("ShowLogin")
	if v != nil {
		showLogin = v.(bool)
		this.DelSession("ShowLogin")
	} else {
		showLogin = true
	}
	this.Data["ShowLogin"] = showLogin

	// Errors
	if !showLogin {
		e := this.GetSession("Error")
		if e != nil {
			this.Data["Error"] = GetError(e)
			this.DelSession("Error")
		}
	}

	this.TplNames = "login.html"
}
Пример #2
0
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
}
Пример #3
0
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()
}