/
login.go
59 lines (43 loc) · 1.17 KB
/
login.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package controllers
import (
"fmt"
"net/http"
)
func (app *Application) LoginHandler(w http.ResponseWriter, r *http.Request) {
data := &struct {
TransactionId string
ErrorMsg string
Error bool
Success bool
Response bool
Username string
}{
TransactionId: "",
ErrorMsg: "",
Error: false,
Success: false,
Response: false,
Username: "",
}
if r.FormValue("signinSubmitted") == "true" {
emailValue := r.FormValue("email")
passwordValue := hash(r.FormValue("password"))
fmt.Println("Sign In ---> emailValue = " + emailValue)
fabricUser, err := app.Fabric.LoginUser(emailValue, passwordValue)
if err != nil {
fmt.Errorf("Web ----- unable to login user : %v", err)
//http.Error(w, err.Error(), 500)
data.Error = true
data.ErrorMsg = err.Error()
} else {
fmt.Println("Logged In User : " + fabricUser.Username)
fmt.Println("Login : Redirect Index")
app.processAuthentication(w, emailValue)
http.Redirect(w, r, "/index.html", 302)
data.Username = fabricUser.Username
data.Success = true
}
data.Response = true
}
renderTemplate(w, r, "login.html", data)
}