创建验证码
This commit is contained in:
		@@ -18,15 +18,30 @@ func init() {
 | 
			
		||||
	configs.ORMDB().AutoMigrate(&Code{})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CodeCreate(email, mobile string) string {
 | 
			
		||||
func CodeCreate(email, mobile string) (err error) {
 | 
			
		||||
	code := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
 | 
			
		||||
	// 如果是邮箱,发送邮件
 | 
			
		||||
	if email != "" {
 | 
			
		||||
		go func() {
 | 
			
		||||
			// 发送邮件
 | 
			
		||||
			// ...
 | 
			
		||||
		}()
 | 
			
		||||
	}
 | 
			
		||||
	// 如果是手机,发送短信
 | 
			
		||||
	if mobile != "" {
 | 
			
		||||
		go func() {
 | 
			
		||||
			// 发送短信
 | 
			
		||||
			// ...
 | 
			
		||||
		}()
 | 
			
		||||
	}
 | 
			
		||||
	// 保存验证码
 | 
			
		||||
	configs.ORMDB().Create(&Code{
 | 
			
		||||
		Email:  email,
 | 
			
		||||
		Mobile: mobile,
 | 
			
		||||
		Code:   code,
 | 
			
		||||
		Expire: time.Now().Add(time.Minute * 5),
 | 
			
		||||
	})
 | 
			
		||||
	return code
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func EmailCheck(email, code string) (err error) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user