Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/robfig/revel
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesward committed Oct 9, 2012
2 parents 8e1f07f + a833ded commit 10af918
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
4 changes: 2 additions & 2 deletions router.go
Expand Up @@ -282,8 +282,8 @@ func (router *Router) validate(route *Route) *Error {
// 5: action
var routePattern *regexp.Regexp = regexp.MustCompile(
"(?i)^(GET|POST|PUT|DELETE|OPTIONS|HEAD|WS|\\*)" +
"[(]?([^)]*)(\\))? +" +
"(.*/[^ ]*) +([^ (]+)(.+)?( *)$")
"[(]?([^)]*)(\\))?[ \t]+" +
"(.*/[^ \t]*)[ \t]+([^ \t(]+)(.+)?([ \t]*)$")

func parseRouteLine(line string) (method, path, action string, found bool) {
var matches []string = routePattern.FindStringSubmatch(line)
Expand Down
4 changes: 2 additions & 2 deletions router_test.go
Expand Up @@ -147,8 +147,8 @@ GET / Application.Index
GET /app/{id} Application.Show
POST /app/{id} Application.Save
GET /public/ staticDir:www
* /{controller}/{action} {controller}.{action}
GET /public/ staticDir:www
* /{controller}/{action} {controller}.{action}
GET /favicon.ico 404
`
Expand Down
19 changes: 12 additions & 7 deletions samples/booking/app/controllers/hotels.go
@@ -1,6 +1,7 @@
package controllers

import (
"code.google.com/p/go.crypto/bcrypt"
"database/sql"
"fmt"
"github.com/robfig/revel"
Expand Down Expand Up @@ -124,17 +125,21 @@ func (c Hotels) Settings() rev.Result {
}

func (c Hotels) SaveSettings(password, verifyPassword string) rev.Result {
user := connected(c.Controller)
user.Password = password
user.Validate(c.Validation)
c.Validation.Required(verifyPassword).Message("VerifyPassword is required")
c.Validation.Required(password == verifyPassword).Message("Your password doesn't match")
models.ValidatePassword(c.Validation, password).Key("password")
c.Validation.Required(verifyPassword).
Key("verifyPassword").
Message("Please verify your password")
c.Validation.Required(password == verifyPassword).
Key("verifyPassword").
Message("Your password doesn't match")
if c.Validation.HasErrors() {
c.Validation.Keep()
return c.Redirect(Hotels.Settings)
}
_, err := c.Txn.Exec("update User set Password = ? where UserId = ?",
password, user.UserId)

bcryptPassword, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
_, err := c.Txn.Exec("update User set HashedPassword = ? where UserId = ?",
bcryptPassword, connected(c.Controller).UserId)
if err != nil {
panic(err)
}
Expand Down
14 changes: 9 additions & 5 deletions samples/booking/app/models/user.go
Expand Up @@ -26,14 +26,18 @@ func (u *User) Validate(v *rev.Validation) {
rev.Match{userRegex},
).Key("user.Username")

v.Check(u.Password,
rev.Required{},
rev.MaxSize{15},
rev.MinSize{5},
).Key("user.Password")
ValidatePassword(v, u.Password).Key("user.Password")

v.Check(u.Name,
rev.Required{},
rev.MaxSize{100},
).Key("user.Name")
}

func ValidatePassword(v *rev.Validation, password string) *rev.ValidationResult {
return v.Check(password,
rev.Required{},
rev.MaxSize{15},
rev.MinSize{5},
)
}
6 changes: 3 additions & 3 deletions samples/booking/app/views/Hotels/Settings.html
Expand Up @@ -4,17 +4,17 @@
<h1>Change your password</h1>

<form method="POST" action="{{url "Hotels.SaveSettings"}}">
{{with $field := field "connected.Password" .}}
{{with $field := field "password" .}}
<p class="{{$field.ErrorClass}}">
<strong>Password:</strong>
<input type="password" name="Password" size="16" value="{{.connected.Password}}"> *
<input type="password" name="{{$field.Name}}" size="16"> *
<span class="error">{{$field.Error}}</span>
</p>
{{end}}
{{with $field := field "verifyPassword" .}}
<p class="{{$field.ErrorClass}}">
<strong>Verify password:</strong>
<input type="password" name="{{$field.Name}}" size="16" value="{{.verifyPassword}}"> *
<input type="password" name="{{$field.Name}}" size="16"> *
<span class="error">{{$field.Error}}</span>
</p>
{{end}}
Expand Down
Binary file modified skeleton/public/images/favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion watcher.go
@@ -1,7 +1,7 @@
package rev

import (
"github.com/howeyc/fsnotify"
"github.com/robfig/fsnotify"
"os"
"path"
"path/filepath"
Expand Down

0 comments on commit 10af918

Please sign in to comment.