From 3eb1ab9e8b12a80096d6b10a7f0a398aec8d8172 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 17 Feb 2014 18:38:50 -0500 Subject: [PATCH] Add UI for register user --- bee.json | 5 ++++- gogs.go | 7 ++++-- models/access.go | 17 +++++++++++---- models/user.go | 4 ++++ routers/user/user.go | 38 ++++++++++++++++++++++++++++++++ templates/base/base.tmpl | 15 ------------- templates/base/footer.tmpl | 2 ++ templates/base/head.tmpl | 32 ++++++++++++++++----------- templates/base/navbar.tmpl | 4 ++-- templates/dashboard.tmpl | 11 +++++----- templates/status/403.tmpl | 6 ++++++ templates/user/signup.tmpl | 44 ++++++++++++++++++++++++++++++++++++++ 12 files changed, 144 insertions(+), 41 deletions(-) create mode 100644 routers/user/user.go delete mode 100644 templates/base/base.tmpl create mode 100644 templates/status/403.tmpl create mode 100644 templates/user/signup.tmpl diff --git a/bee.json b/bee.json index 793069405..ce3967060 100644 --- a/bee.json +++ b/bee.json @@ -7,9 +7,12 @@ "go_install": true, "watch_ext": [], "dir_structure": { + "watch_all": true, "controllers": "routers", "models": "", - "others": [] + "others": [ + "utils" + ] }, "cmd_args": [], "envs": [] diff --git a/gogs.go b/gogs.go index c503a4af8..6cb3f37ed 100644 --- a/gogs.go +++ b/gogs.go @@ -12,18 +12,19 @@ import ( "github.com/martini-contrib/render" "github.com/gogits/gogs/routers" + "github.com/gogits/gogs/routers/user" "github.com/gogits/gogs/utils" "github.com/gogits/gogs/utils/log" ) -const APP_VER = "0.0.0.0212" +const APP_VER = "0.0.0.0217" func init() { } func main() { - log.Info("App Name: %s", utils.Cfg.MustValue("", "APP_NAME")) + log.Info("%s %s", utils.Cfg.MustValue("", "APP_NAME"), APP_VER) m := martini.Classic() @@ -32,6 +33,8 @@ func main() { // Routers. m.Get("/", routers.Dashboard) + m.Get("/user/signin", user.SignIn) + m.Any("/user/signup", user.SignUp) listenAddr := fmt.Sprintf("%s:%s", utils.Cfg.MustValue("server", "HTTP_ADDR"), diff --git a/models/access.go b/models/access.go index 11bb360af..ea5cbfaa5 100644 --- a/models/access.go +++ b/models/access.go @@ -1,3 +1,7 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + package models import ( @@ -6,8 +10,8 @@ import ( ) const ( - Readable = iota + 1 - Writable + AU_READABLE = iota + 1 + AU_WRITABLE ) type Access struct { @@ -24,6 +28,11 @@ func AddAccess(access *Access) error { } // if one user can read or write one repository -func HasAccess(userName, repoName, mode string) (bool, error) { - return orm.Get(&Access{0, strings.ToLower(userName), strings.ToLower(repoName), mode}) +func HasAccess(userName, repoName string, mode int) (bool, error) { + return orm.Get(&Access{ + Id: 0, + UserName: strings.ToLower(userName), + RepoName: strings.ToLower(repoName), + Mode: mode, + }) } diff --git a/models/user.go b/models/user.go index 6ea329c52..44dadb9a5 100644 --- a/models/user.go +++ b/models/user.go @@ -98,6 +98,10 @@ func RegisterUser(user *User) (err error) { if err = validateUser(user.Name); err != nil { return err } + user.LowerName = strings.ToLower(user.Name) + // TODO: generate Avatar address. + user.Created = time.Now() + user.Updated = time.Now() _, err = orm.Insert(user) return err } diff --git a/routers/user/user.go b/routers/user/user.go new file mode 100644 index 000000000..f9dc07f26 --- /dev/null +++ b/routers/user/user.go @@ -0,0 +1,38 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package user + +import ( + "fmt" + "net/http" + + "github.com/martini-contrib/render" + + //"github.com/gogits/gogs/utils/log" + "github.com/gogits/gogs/models" +) + +func SignIn(r render.Render) { + r.Redirect("/user/signup", 302) +} + +func SignUp(req *http.Request, r render.Render) { + if req.Method == "GET" { + r.HTML(200, "user/signup", map[string]interface{}{ + "Title": "Sign Up", + }) + return + } + + // TODO: validate form. + err := models.RegisterUser(&models.User{ + Name: req.FormValue("username"), + Email: req.FormValue("email"), + Passwd: req.FormValue("passwd"), + }) + r.HTML(403, "status/403", map[string]interface{}{ + "Title": fmt.Sprintf("%v", err), + }) +} diff --git a/templates/base/base.tmpl b/templates/base/base.tmpl deleted file mode 100644 index f75230d9a..000000000 --- a/templates/base/base.tmpl +++ /dev/null @@ -1,15 +0,0 @@ - - - - {{template "base/head" .}} - {{template "head" .}} - - - - {{template "base/navbar" .}} -
- {{template "body" .}} -
- {{template "base/footer" .}} - - \ No newline at end of file diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl index e69de29bb..4d4a7e528 100644 --- a/templates/base/footer.tmpl +++ b/templates/base/footer.tmpl @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 71c071396..9e48040f2 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -1,14 +1,22 @@ - - - - - + + + + + + + + - - - - - + + + + + - - \ No newline at end of file + + + + {{.Title}} | Gogs - Go Git Service + + + \ No newline at end of file diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index 79ba1ac53..16d76688d 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -4,7 +4,7 @@ - Gogs Logo + Gogs Logo diff --git a/templates/dashboard.tmpl b/templates/dashboard.tmpl index b91df21e2..25a63827b 100644 --- a/templates/dashboard.tmpl +++ b/templates/dashboard.tmpl @@ -1,5 +1,6 @@ -{{template "base/base" .}} -{{define "head"}} {{.Title}} | Gogs - Go Git Service{{end}} -{{define "body"}} -Website is still in the progress of building...please come back later! -{{end}} \ No newline at end of file +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ Website is still in the progress of building...please come back later! +
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/status/403.tmpl b/templates/status/403.tmpl new file mode 100644 index 000000000..03a88479d --- /dev/null +++ b/templates/status/403.tmpl @@ -0,0 +1,6 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ 403 Forbidden +
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/user/signup.tmpl b/templates/user/signup.tmpl new file mode 100644 index 000000000..8e1f1493c --- /dev/null +++ b/templates/user/signup.tmpl @@ -0,0 +1,44 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+ + +
+
+{{template "base/footer" .}} \ No newline at end of file