Browse Source

Check email to utils

Vova Tkach 6 years ago
parent
commit
b91e538295

+ 5 - 1
engine/actions/action_first_user.go

@@ -1,5 +1,9 @@
 package actions
 
+import (
+	utils "golang-fave/engine/wrapper/utils"
+)
+
 func (this *Action) Action_first_user() {
 	if dbe := this.use_database(); dbe != nil {
 		this.msg_error(dbe.Error())
@@ -18,7 +22,7 @@ func (this *Action) Action_first_user() {
 		return
 	}
 
-	if !this.is_valid_email(pf_email) {
+	if !utils.EmailIsValid(pf_email) {
 		this.msg_error(`Please specify correct user email`)
 		return
 	}

+ 3 - 1
engine/actions/action_signin.go

@@ -3,6 +3,8 @@ package actions
 import (
 	"database/sql"
 	_ "github.com/go-sql-driver/mysql"
+
+	utils "golang-fave/engine/wrapper/utils"
 )
 
 func (this *Action) Action_signin() {
@@ -21,7 +23,7 @@ func (this *Action) Action_signin() {
 		return
 	}
 
-	if !this.is_valid_email(pf_email) {
+	if !utils.EmailIsValid(pf_email) {
 		this.msg_error(`Please specify correct user email`)
 		return
 	}

+ 0 - 6
engine/actions/actions.go

@@ -7,7 +7,6 @@ import (
 	"errors"
 	"fmt"
 	"reflect"
-	"regexp"
 	"strings"
 
 	"golang-fave/engine/wrapper"
@@ -62,11 +61,6 @@ func (this *Action) use_database() error {
 	return nil
 }
 
-func (this *Action) is_valid_email(email string) bool {
-	regexpe := regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)
-	return regexpe.MatchString(email)
-}
-
 func New(wrapper *wrapper.Wrapper) *Action {
 	return &Action{wrapper, nil}
 }

+ 9 - 0
engine/wrapper/utils/utils.go

@@ -1 +1,10 @@
 package utils
+
+import (
+	"regexp"
+)
+
+func EmailIsValid(email string) bool {
+	regexpe := regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)
+	return regexpe.MatchString(email)
+}