From 5a5d0fd250c28c3560ff00b9a367938e915eed7f Mon Sep 17 00:00:00 2001 From: Horus3 Date: Tue, 10 Feb 2015 14:01:31 +0100 Subject: Restructuring and bug fixes. --- app/controllers/utilities.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'app/controllers/utilities.go') diff --git a/app/controllers/utilities.go b/app/controllers/utilities.go index 2eae775..1aa5d6d 100644 --- a/app/controllers/utilities.go +++ b/app/controllers/utilities.go @@ -4,7 +4,7 @@ import ( "crypto/md5" "fmt" "github.com/garyburd/redigo/redis" - "github.com/tanema/revel_mailer" + "github.com/revel/revel" "golang.org/x/crypto/bcrypt" "io" "io/ioutil" @@ -22,7 +22,7 @@ func Get(url string) (string, error) { defer response.Body.Close() contents, err := ioutil.ReadAll(response.Body) - if er != nil { + if err != nil { return "Reading body failed.", err } @@ -58,13 +58,7 @@ func newPool() *redis.Pool { IdleTimeout: 240 * time.Second, Dial: func() (redis.Conn, error) { //c, err := redis.Dial("tcp", ":6379") - if revel.Config.Bool("cache.redis") { - // If we use redis as cache we reuse the config part - c, err := redis.Dial("tcp", revel.Config.String("cache.hosts")) - } else { - // Otherwise we use our own configuration - c, err := redis.Dial("tcp", revel.Config.String("redis.server")+":"+revel.Config.String("redis.port")) - } + c, err := redis.Dial("tcp", revel.Config.StringDefault("redis.server", "127.0.0.1")+":"+revel.Config.StringDefault("redis.port", "6379")) if err != nil { return nil, err } @@ -80,19 +74,19 @@ func newPool() *redis.Pool { // Hashs password with bcrypt and returns the string func HashPassword(password string) (string, error) { if password == "" { - return nil, nil + return "", nil } p := []byte(password) hash, err := bcrypt.GenerateFromPassword(p, 10) if err != nil { - return nil, err + return "", err } - return string(hash) + return string(hash), nil } // Verify password and hash func VerifyPassword(password, hash string) (bool, error) { - err := bcrypt.CompareHashAndPassword(hash, password) + err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) if err != nil { return false, err } -- cgit v1.2.3