Skip to content

Commit

Permalink
add login,check func
Browse files Browse the repository at this point in the history
  • Loading branch information
zzerroo committed Sep 3, 2020
1 parent 96e3887 commit 41e45f4
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 1,032 deletions.
10 changes: 6 additions & 4 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,25 @@ const (
<body style="background-color: #f0f0f0">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div style="position: relative;top: 20%%;margin:0 auto;width:360px;height:400px;">
<form style="height:100%%" action="%s" method="POST">
<form style="height:100%%" action="%s" method="POST" role="form" onsubmit="return true;">
<div id="divBorder" class="form-group divBorder">
<div>
<h1 style="text-align: center;">Name</h1>
</div><br>
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Name">
<input type="email" class="form-control" id="email" name="name" placeholder="邮箱">
<input type="hidden" class="form-control" id="flag" name="flag" value="2">
</div>
<div class="form-group">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
<input type="password" class="form-control" id="password" name="password" placeholder="密码">
</div>
<div class="form-group">
<label><input type="checkbox"> Remember me</label>
</div>
<div class="form-group">
<button width="100%" type="submit" class="btn btn-primary btn-block">Sign in</button>
<button width="100%" type="submit" class="btn btn-primary btn-block">登录</button>
</div>
</div>
</form>
</div>
Expand Down
131 changes: 0 additions & 131 deletions engine/mysql.go

This file was deleted.

11 changes: 0 additions & 11 deletions engine/mysql.sql

This file was deleted.

2 changes: 1 addition & 1 deletion engine/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (m *mysql) GetUsrInfo(info, flag string) (*zauth.UsrInfo, error) {
} else if flag == zauth.FlagPhone {
sql = fmt.Sprintf("select name,pswd,phone,email,other from users where phone=?")
} else if flag == zauth.FlagEamil {
sql = fmt.Sprintf("select name,pswd,phone,email,other from users where eamil=?")
sql = fmt.Sprintf("select name,pswd,phone,email,other from users where email=?")
}

row := m.db.QueryRow(sql, info)
Expand Down
52 changes: 52 additions & 0 deletions engine/mysql/mysql_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package mysql

import (
"testing"

"github.com/zzerroo/zauth"
)

func getMysqlConn() (*mysql, error) {
mysql := &mysql{}
erro := mysql.Open("root:xxx@tcp(127.0.0.1:3306)/auth?charset=utf8")
if erro != nil {
return nil, erro
}

return mysql, nil
}

func TestAll(t *testing.T) {
mysql, erro := getMysqlConn()
if erro != nil {
t.Errorf("error open mysql conn")
}

var u1 zauth.UsrInfo
u1.Name.String = "test1"
u1.Pswd.String = "123456"
u1.Email.String = "[email protected]"
u1.Phone.String = "11111111111"
u1.Other.String = ""
erro = mysql.Register(&u1)
if erro != nil {
t.Errorf("error register user")
}

_, erro = mysql.LogIn(u1.Name.String, u1.Pswd.String, "0")
if erro != nil {
t.Errorf("error login 0")
}

_, erro = mysql.LogIn(u1.Phone.String, u1.Pswd.String, "1")
if erro != nil {
t.Errorf("error login 1")
}

_, erro = mysql.LogIn(u1.Email.String, u1.Pswd.String, "2")
if erro != nil {
t.Errorf("error login 2")
}

t.Log("ok")
}
4 changes: 4 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ var (
ErrorCalPwd = errors.New("error cal pswd")
ErrorSign = errors.New("error sign")
ErrorTkAlgNotSupported = errors.New("error alg not supported")

//
ErrorNeedRedirect = errors.New("error need redirect")
ErrorNeedShowForm = errors.New("error need show form")
)
Loading

0 comments on commit 41e45f4

Please sign in to comment.