Browse Source

Check email to one function

Vova Tkach 6 years ago
parent
commit
93c3a6fdb1
3 changed files with 26 additions and 5 deletions
  1. 1 4
      engine/actions/action_first_user.go
  2. 19 1
      engine/actions/action_signin.go
  3. 6 0
      engine/actions/actions.go

+ 1 - 4
engine/actions/action_first_user.go

@@ -2,11 +2,8 @@ package actions
 
 import (
 	"fmt"
-	"regexp"
 )
 
-var regexpe = regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)
-
 func (this *Action) Action_first_user() {
 	if dbe := this.use_database(); dbe != nil {
 		this.msg_error(dbe.Error())
@@ -25,7 +22,7 @@ func (this *Action) Action_first_user() {
 		return
 	}
 
-	if !regexpe.MatchString(pf_email) {
+	if !this.is_valid_email(pf_email) {
 		this.msg_error(`Please specify correct user email`)
 		return
 	}

+ 19 - 1
engine/actions/action_signin.go

@@ -8,5 +8,23 @@ func (this *Action) Action_signin() {
 		defer this.db.Close()
 	}
 
-	this.msg_success(`Hello from web server`)
+	pf_email := this.wrapper.R.FormValue("email")
+	pf_password := this.wrapper.R.FormValue("password")
+
+	if pf_email == "" {
+		this.msg_error(`Please specify user email`)
+		return
+	}
+
+	if !this.is_valid_email(pf_email) {
+		this.msg_error(`Please specify correct user email`)
+		return
+	}
+
+	if pf_password == "" {
+		this.msg_error(`Please specify user password`)
+		return
+	}
+
+	//this.msg_success(`Hello from web server`)
 }

+ 6 - 0
engine/actions/actions.go

@@ -7,6 +7,7 @@ import (
 	"errors"
 	"fmt"
 	"reflect"
+	"regexp"
 	"strings"
 
 	"golang-fave/engine/wrapper"
@@ -61,6 +62,11 @@ 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}
 }