release/v1.15
Unknown 2014-03-03 19:03:08 -05:00
parent fea660f1d7
commit e59f90b8fe
10 changed files with 45 additions and 29 deletions

View File

@ -1,4 +1,4 @@
APP_NAME = Gogs - Go Git Service APP_NAME = Gogs: Go Git Service
RUN_USER = lunny RUN_USER = lunny
[repository] [repository]

View File

@ -19,7 +19,7 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition. // Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true const go11tag = true
const APP_VER = "0.0.0.0301" const APP_VER = "0.0.0.0303"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View File

@ -34,7 +34,7 @@ const (
type User struct { type User struct {
Id int64 Id int64
LowerName string `xorm:"unique not null"` 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"` Email string `xorm:"unique not null" valid:"Email"`
Passwd string `xorm:"not null" valid:"MinSize(8)"` Passwd string `xorm:"not null" valid:"MinSize(8)"`
LoginType int LoginType int

View File

@ -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) {

View File

@ -16,7 +16,7 @@
<script src="/js/jquery-1.10.1.min.js"></script> <script src="/js/jquery-1.10.1.min.js"></script>
<script src="/js/bootstrap.min.js"></script> <script src="/js/bootstrap.min.js"></script>
<script src="/js/app.js"></script> <script src="/js/app.js"></script>
<title>{{.Title}} | {{AppName}}</title> <title>{{.Title}} - {{AppName}}</title>
</head> </head>
<body> <body>
<noscript>Please enable JavaScript in your browser!</noscript> <noscript>Please enable JavaScript in your browser!</noscript>

View File

@ -7,7 +7,7 @@
<a class="gogs-nav-item" href="#">Help</a> <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 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"> <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"/> <img src="http://1.gravatar.com/avatar/x?s=28" alt="user-avatar" title="username"/>
</a> </a>

View File

@ -1,7 +1,7 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{template "base/navbar" .}}
<div class="container" id="gogs-body"> <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}} <h3>Log in</h3>{{if .Error}}
<div class="form-group"> <div class="form-group">
<div class="col-md-6 col-md-offset-3 alert alert-danger text-center"><strong>{{.Error}}</strong></div> <div class="col-md-6 col-md-offset-3 alert alert-danger text-center"><strong>{{.Error}}</strong></div>
@ -26,7 +26,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-offset-4 col-md-6"> <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> </div>
<div class="form-group text-center" id="gogs-social-login"> <div class="form-group text-center" id="gogs-social-login">

View File

@ -1,8 +1,11 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{template "base/navbar" .}}
<div class="container" id="gogs-body"> <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> <h3>Sign Up</h3>
{{if .HasError}}
<div class="alert alert-danger">{{.ErrorMsg}}</div>
{{end}}
<div class="form-group"> <div class="form-group">
<label class="col-md-4 control-label">Username: </label> <label class="col-md-4 control-label">Username: </label>
<div class="col-md-6"> <div class="col-md-6">
@ -37,7 +40,7 @@
<div class="form-group"> <div class="form-group">
<div class="col-md-offset-4 col-md-6"> <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>
</div> </div>
</form> </form>

15
utils/auth/auth.go Normal file
View File

@ -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)
}

6
web.go
View File

@ -53,11 +53,9 @@ func runWeb(*cli.Context) {
// Routers. // Routers.
m.Get("/", routers.Dashboard) m.Get("/", routers.Dashboard)
m.Any("/login", user.SignIn) m.Any("/user/login", user.SignIn)
m.Any("/user/signin", user.SignIn)
m.Any("/sign-up", user.SignUp) m.Any("/user/sign_up", user.SignUp)
m.Any("/user/signup", user.SignUp)
m.Get("/user/profile", user.Profile) // should be /username m.Get("/user/profile", user.Profile) // should be /username
m.Any("/user/delete", user.Delete) m.Any("/user/delete", user.Delete)