aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-02-17 18:38:50 -0500
committerUnknown <joe2010xtmf@163.com>2014-02-17 18:38:50 -0500
commit3eb1ab9e8b12a80096d6b10a7f0a398aec8d8172 (patch)
treef37d6bc5c6d006d97e4fd4f3a3a9891eb98c5156
parent5da2ad743567297b965b06a8e75ab37d308b215c (diff)
Add UI for register user
-rw-r--r--bee.json5
-rw-r--r--gogs.go7
-rw-r--r--models/access.go17
-rw-r--r--models/user.go4
-rw-r--r--routers/user/user.go38
-rw-r--r--templates/base/base.tmpl15
-rw-r--r--templates/base/footer.tmpl2
-rw-r--r--templates/base/head.tmpl32
-rw-r--r--templates/base/navbar.tmpl4
-rw-r--r--templates/dashboard.tmpl11
-rw-r--r--templates/status/403.tmpl6
-rw-r--r--templates/user/signup.tmpl44
12 files changed, 144 insertions, 41 deletions
diff --git a/bee.json b/bee.json
index 79306940..ce396706 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 c503a4af..6cb3f37e 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 11bb360a..ea5cbfaa 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 6ea329c5..44dadb9a 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 00000000..f9dc07f2
--- /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 f75230d9..00000000
--- a/templates/base/base.tmpl
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- {{template "base/head" .}}
- {{template "head" .}}
- </head>
- <body>
- <noscript>Please enable JavaScript in your browser!</noscript>
- {{template "base/navbar" .}}
- <div class="container">
- {{template "body" .}}
- </div>
- {{template "base/footer" .}}
- </body>
-</html> \ No newline at end of file
diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl
index e69de29b..4d4a7e52 100644
--- a/templates/base/footer.tmpl
+++ b/templates/base/footer.tmpl
@@ -0,0 +1,2 @@
+ </body>
+</html> \ No newline at end of file
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl
index 71c07139..9e48040f 100644
--- a/templates/base/head.tmpl
+++ b/templates/base/head.tmpl
@@ -1,14 +1,22 @@
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<link rel="shortcut icon" href="img/favicon.png" />
-<meta name="author" content="Gogs - Go Git Service" />
-<meta name="description" content="Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language" />
-<meta name="keywords" content="go, git">
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <link rel="shortcut icon" href="/img/favicon.png" />
+ <meta name="author" content="Gogs - Go Git Service" />
+ <meta name="description" content="Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language" />
+ <meta name="keywords" content="go, git">
- <!-- Stylesheets -->
-<link href="css/bootstrap.min.css" rel="stylesheet" />
-<link href="css/todc-bootstrap.min.css" rel="stylesheet" />
-<link href="css/font-awesome.min.css" rel="stylesheet" />
-<link href="css/gogs.css" rel="stylesheet" />
+ <!-- Stylesheets -->
+ <link href="/css/bootstrap.min.css" rel="stylesheet" />
+ <link href="/css/todc-bootstrap.min.css" rel="stylesheet" />
+ <link href="/css/font-awesome.min.css" rel="stylesheet" />
+ <link href="/css/gogs.css" rel="stylesheet" />
-<script src="js/jquery-1.10.1.min.js"></script>
-<script src="js/bootstrap.min.js"></script> \ No newline at end of file
+ <script src="/js/jquery-1.10.1.min.js"></script>
+ <script src="/js/bootstrap.min.js"></script>
+
+ <title>{{.Title}} | Gogs - Go Git Service</title>
+ </head>
+ <body>
+ <noscript>Please enable JavaScript in your browser!</noscript> \ No newline at end of file
diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl
index 79ba1ac5..16d76688 100644
--- a/templates/base/navbar.tmpl
+++ b/templates/base/navbar.tmpl
@@ -4,7 +4,7 @@
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#gogs-navbar-collapse">
<i class="fa fa-bars"></i>
</button>
- <a class="navbar-brand" href="/"><img src="img/favicon.png" alt="Gogs Logo"></a>
+ <a class="navbar-brand" href="/"><img src="/img/favicon.png" alt="Gogs Logo"></a>
</div>
<div class="collapse navbar-collapse" id="gopmweb-navbar-collapse">
@@ -12,7 +12,7 @@
<li><a>{{.Title}}</a></li>
</ul>
- <a href="/login" class="navbar-right btn btn-success navbar-btn">Log In</a>
+ <a href="/user/signin" class="navbar-right btn btn-success navbar-btn">Sign In</a>
</div>
</div>
</nav>
diff --git a/templates/dashboard.tmpl b/templates/dashboard.tmpl
index b91df21e..25a63827 100644
--- a/templates/dashboard.tmpl
+++ b/templates/dashboard.tmpl
@@ -1,5 +1,6 @@
-{{template "base/base" .}}
-{{define "head"}} <title>{{.Title}} | Gogs - Go Git Service</title>{{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" .}}
+<div class="container">
+ Website is still in the progress of building...please come back later!
+</div>
+{{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 00000000..03a88479
--- /dev/null
+++ b/templates/status/403.tmpl
@@ -0,0 +1,6 @@
+{{template "base/head" .}}
+{{template "base/navbar" .}}
+<div class="container">
+ 403 Forbidden
+</div>
+{{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 00000000..8e1f1493
--- /dev/null
+++ b/templates/user/signup.tmpl
@@ -0,0 +1,44 @@
+{{template "base/head" .}}
+{{template "base/navbar" .}}
+<div class="container">
+ <form action="/user/signup" method="post" class="form-horizontal">
+ <div class="form-group">
+ <label class="col-md-4 control-label">Username: </label>
+ <div class="col-md-3">
+ <input name="username" class="form-control" placeholder="Type your username">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-md-4 control-label">Email: </label>
+ <div class="col-md-3">
+ <input name="email" class="form-control" placeholder="Type your e-mail address">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-md-4 control-label">Password: </label>
+ <div class="col-md-3">
+ <input name="passwd" type="password" class="form-control" placeholder="Type your password">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="col-md-4 control-label">Re-type: </label>
+ <div class="col-md-3">
+ <input type="password" class="form-control" placeholder="Re-type your password">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <div class="col-md-offset-4 col-md-3">
+ <button type="submit" class="btn btn-info">Sign Up</button>
+ </div>
+ </div>
+
+ <div class="col-md-offset-4 col-md-3">
+ <a href="/user/signin">Already have an account? Sign in now!</a>
+ </div>
+ </form>
+</div>
+{{template "base/footer" .}} \ No newline at end of file