|
|
@ -14,6 +14,7 @@ import ( |
|
|
|
"github.com/gogits/validation" |
|
|
|
"github.com/gogits/validation" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
|
|
|
|
"github.com/gogits/gogs/utils/auth" |
|
|
|
"github.com/gogits/gogs/utils/log" |
|
|
|
"github.com/gogits/gogs/utils/log" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -50,18 +51,19 @@ func SignIn(req *http.Request, r render.Render, session sessions.Session) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SignUp(req *http.Request, r render.Render) { |
|
|
|
func SignUp(req *http.Request, r render.Render) { |
|
|
|
|
|
|
|
data := map[string]interface{}{"Title": "Sign Up"} |
|
|
|
if req.Method == "GET" { |
|
|
|
if req.Method == "GET" { |
|
|
|
r.HTML(200, "user/signup", map[string]interface{}{ |
|
|
|
r.HTML(200, "user/signup", data) |
|
|
|
"Title": "Sign Up", |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Front-end should do double check of password.
|
|
|
|
u := &models.User{ |
|
|
|
u := &models.User{ |
|
|
|
Name: req.FormValue("username"), |
|
|
|
Name: req.FormValue("username"), |
|
|
|
Email: req.FormValue("email"), |
|
|
|
Email: req.FormValue("email"), |
|
|
|
Passwd: req.FormValue("passwd"), |
|
|
|
Passwd: req.FormValue("passwd"), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
valid := validation.Validation{} |
|
|
|
valid := validation.Validation{} |
|
|
|
ok, err := valid.Valid(u) |
|
|
|
ok, err := valid.Valid(u) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -69,23 +71,21 @@ func SignUp(req *http.Request, r render.Render) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
for _, err := range valid.Errors { |
|
|
|
data["HasError"] = true |
|
|
|
log.Warn("user.SignUp -> valid user: %v", err) |
|
|
|
data["ErrorMsg"] = auth.GenerateErrorMsg(valid.Errors[0]) |
|
|
|
} |
|
|
|
r.HTML(200, "user/signup", data) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err = models.RegisterUser(u) |
|
|
|
// err = models.RegisterUser(u)
|
|
|
|
if err != nil { |
|
|
|
// if err != nil {
|
|
|
|
if err != nil { |
|
|
|
// r.HTML(200, "base/error", map[string]interface{}{
|
|
|
|
r.HTML(200, "base/error", map[string]interface{}{ |
|
|
|
// "Error": fmt.Sprintf("%v", err),
|
|
|
|
"Error": fmt.Sprintf("%v", err), |
|
|
|
// })
|
|
|
|
}) |
|
|
|
// return
|
|
|
|
return |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r.Redirect("/") |
|
|
|
// r.Redirect("/")
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Delete(req *http.Request, r render.Render) { |
|
|
|
func Delete(req *http.Request, r render.Render) { |
|
|
|