]> source.dussan.org Git - gitea.git/commitdiff
Update
authorUnknown <joe2010xtmf@163.com>
Tue, 4 Mar 2014 00:03:08 +0000 (19:03 -0500)
committerUnknown <joe2010xtmf@163.com>
Tue, 4 Mar 2014 00:03:08 +0000 (19:03 -0500)
conf/app.ini
gogs.go
models/user.go
routers/user/user.go
templates/base/head.tmpl
templates/base/navbar.tmpl
templates/user/signin.tmpl
templates/user/signup.tmpl
utils/auth/auth.go [new file with mode: 0644]
web.go

index 7a8970cb4aa369dad93aab734399b5a1b47a2955..dcc58c37f374f603bce4ffd782566bc58f2470c2 100644 (file)
@@ -1,4 +1,4 @@
-APP_NAME = Gogs - Go Git Service
+APP_NAME = Gogs: Go Git Service
 RUN_USER = lunny
 
 [repository]
diff --git a/gogs.go b/gogs.go
index 51ef3cf19d3b12f9775410520c74111268610e4e..72a967f01c5a9ee1eaaca0e48566cf0a1344f99c 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -19,7 +19,7 @@ import (
 // Test that go1.1 tag above is included in builds. main.go refers to this definition.
 const go11tag = true
 
-const APP_VER = "0.0.0.0301"
+const APP_VER = "0.0.0.0303"
 
 func init() {
        runtime.GOMAXPROCS(runtime.NumCPU())
index 086b02c82f41dd4115665e532dba9e3cabc8b5b1..820597380de3d3d23bfc4bc374da69e787106784 100644 (file)
@@ -34,7 +34,7 @@ const (
 type User struct {
        Id            int64
        LowerName     string `xorm:"unique not null"`
-       Name          string `xorm:"unique not null" valid:"Required"`
+       Name          string `xorm:"unique not null" valid:"AlphaDash;MinSize(5);MaxSize(30)"`
        Email         string `xorm:"unique not null" valid:"Email"`
        Passwd        string `xorm:"not null" valid:"MinSize(8)"`
        LoginType     int
index 5dc2c0b97d0d4de70d682bade7ef27574e6a44a0..a66a7b5f9436ed004f01bea9e12affb104abdc41 100644 (file)
@@ -14,6 +14,7 @@ import (
        "github.com/gogits/validation"
 
        "github.com/gogits/gogs/models"
+       "github.com/gogits/gogs/utils/auth"
        "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) {
+       data := map[string]interface{}{"Title": "Sign Up"}
        if req.Method == "GET" {
-               r.HTML(200, "user/signup", map[string]interface{}{
-                       "Title": "Sign Up",
-               })
+               r.HTML(200, "user/signup", data)
                return
        }
 
+       // Front-end should do double check of password.
        u := &models.User{
                Name:   req.FormValue("username"),
                Email:  req.FormValue("email"),
                Passwd: req.FormValue("passwd"),
        }
+
        valid := validation.Validation{}
        ok, err := valid.Valid(u)
        if err != nil {
@@ -69,23 +71,21 @@ func SignUp(req *http.Request, r render.Render) {
                return
        }
        if !ok {
-               for _, err := range valid.Errors {
-                       log.Warn("user.SignUp -> valid user: %v", err)
-               }
+               data["HasError"] = true
+               data["ErrorMsg"] = auth.GenerateErrorMsg(valid.Errors[0])
+               r.HTML(200, "user/signup", data)
                return
        }
 
-       err = models.RegisterUser(u)
-       if err != nil {
-               if err != nil {
-                       r.HTML(200, "base/error", map[string]interface{}{
-                               "Error": fmt.Sprintf("%v", err),
-                       })
-                       return
-               }
-       }
+       // err = models.RegisterUser(u)
+       // if err != nil {
+       //      r.HTML(200, "base/error", map[string]interface{}{
+       //              "Error": fmt.Sprintf("%v", err),
+       //      })
+       //      return
+       // }
 
-       r.Redirect("/")
+       // r.Redirect("/")
 }
 
 func Delete(req *http.Request, r render.Render) {
index 4358bf02bfaaa3673c490b406fcc592284be5e8c..0294ba49a58f530e6136ff2af07c2a806e19fd12 100644 (file)
@@ -16,7 +16,7 @@
                <script src="/js/jquery-1.10.1.min.js"></script>
                <script src="/js/bootstrap.min.js"></script>
         <script src="/js/app.js"></script>
-               <title>{{.Title}} | {{AppName}}</title>
+               <title>{{.Title}} - {{AppName}}</title>
        </head>
        <body>
                <noscript>Please enable JavaScript in your browser!</noscript>
\ No newline at end of file
index c4bd3a7a518fc1c49fd7b4d9dc4582c5bf02f8fc..00112c03d3be8dd8d167ae137f47426792af3b26 100644 (file)
@@ -7,7 +7,7 @@
             <a class="gogs-nav-item" href="#">Help</a>
 
             <!--<a class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/login/">Sign in</a>-->
-            <a id="gogs-nav-out" class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/login/"><i class="fa fa-power-off fa-lg"></i></a>
+            <a id="gogs-nav-out" class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/user/login/"><i class="fa fa-power-off fa-lg"></i></a>
             <a id="gogs-nav-avatar" class="gogs-nav-item navbar-right" href="/user/profile" data-toggle="tooltip" data-placement="bottom" title="Username">
                 <img src="http://1.gravatar.com/avatar/x?s=28" alt="user-avatar" title="username"/>
             </a>
index 6527ae53f20f7a37cf1a62702f9a981f4a6e01ee..f80b3199a216c291f2f51110ac0814385a16b844 100644 (file)
@@ -1,7 +1,7 @@
 {{template "base/head" .}}
 {{template "base/navbar" .}}
 <div class="container" id="gogs-body">
-    <form action="/user/signin" method="post" class="form-horizontal gogs-card" id="gogs-login-card">
+    <form action="/user/login" method="post" class="form-horizontal gogs-card" id="gogs-login-card">
         <h3>Log in</h3>{{if .Error}}
         <div class="form-group">
             <div class="col-md-6 col-md-offset-3 alert alert-danger text-center"><strong>{{.Error}}</strong></div>
@@ -26,7 +26,7 @@
         </div>
         <div class="form-group">
             <div class="col-md-offset-4 col-md-6">
-                <a href="/sign-up/">Need an account? Sign up free.</a>
+                <a href="/user/sign_up">Need an account? Sign up free.</a>
             </div>
         </div>
         <div class="form-group text-center" id="gogs-social-login">
index 48e50a0037c64a18375326b715e68dd0017905dc..e8854e4aca45af5dbc234e988dc1432d868b2e48 100644 (file)
@@ -1,8 +1,11 @@
 {{template "base/head" .}}
 {{template "base/navbar" .}}
 <div class="container" id="gogs-body">
-       <form action="/user/signup" method="post" class="form-horizontal gogs-card" id="gogs-login-card">
+       <form action="/user/sign_up" method="post" class="form-horizontal gogs-card" id="gogs-login-card">
         <h3>Sign Up</h3>
+       {{if .HasError}}
+       <div class="alert alert-danger">{{.ErrorMsg}}</div>
+       {{end}}
                <div class="form-group">
                        <label class="col-md-4 control-label">Username: </label>
                        <div class="col-md-6">
@@ -37,7 +40,7 @@
 
            <div class="form-group">
             <div class="col-md-offset-4 col-md-6">
-                <a href="/login/">Already have an account? Sign in now!</a>
+                <a href="/user/login">Already have an account? Sign in now!</a>
             </div>
            </div>
        </form>
diff --git a/utils/auth/auth.go b/utils/auth/auth.go
new file mode 100644 (file)
index 0000000..1099103
--- /dev/null
@@ -0,0 +1,15 @@
+// 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 auth
+
+import (
+       "fmt"
+
+       "github.com/gogits/validation"
+)
+
+func GenerateErrorMsg(e *validation.ValidationError) string {
+       return fmt.Sprintf("%v", e.LimitValue)
+}
diff --git a/web.go b/web.go
index 4fca90a2983add137a01a6ba52cd4dc8711e007c..ca3b4fcf1a316bec0639999d6113d3443586fe8b 100644 (file)
--- a/web.go
+++ b/web.go
@@ -53,11 +53,9 @@ func runWeb(*cli.Context) {
 
        // Routers.
        m.Get("/", routers.Dashboard)
-       m.Any("/login", user.SignIn)
-       m.Any("/user/signin", user.SignIn)
+       m.Any("/user/login", user.SignIn)
 
-       m.Any("/sign-up", user.SignUp)
-       m.Any("/user/signup", user.SignUp)
+       m.Any("/user/sign_up", user.SignUp)
 
        m.Get("/user/profile", user.Profile) // should be /username
        m.Any("/user/delete", user.Delete)