diff --git a/auth/auth.go b/auth/auth.go index d6409c72..8bc5cbe5 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -1,7 +1,6 @@ package auth import ( - "database/sql" "encoding/gob" "errors" "fmt" @@ -9,6 +8,7 @@ import ( "net/http" "crypto/rand" + "code.google.com/p/go.crypto/bcrypt" ctx "github.com/gorilla/context" "github.com/gorilla/securecookie" @@ -53,22 +53,22 @@ func Register(r *http.Request) (bool, error) { username, password := r.FormValue("username"), r.FormValue("password") u, err := models.GetUserByUsername(username) // If we have an error which is not simply indicating that no user was found, report it - if err != sql.ErrNoRows { + if err != nil { + fmt.Println(err) return false, err } + fmt.Println("Made it here!") + u = models.User{} //If we've made it here, we should have a valid username given //Let's create the password hash h, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) + if err != nil { + return false, err + } u.Username = username u.Hash = string(h) u.ApiKey = GenerateSecureKey() - if err != nil { - return false, err - } - err = models.Conn.Insert(&u) - if err != nil { - return false, err - } + err = models.PutUser(&u) return true, nil } diff --git a/controllers/api.go b/controllers/api.go index ccb5289d..1a51bbb0 100644 --- a/controllers/api.go +++ b/controllers/api.go @@ -17,6 +17,7 @@ import ( "github.com/jordan-wright/gophish/worker" ) +// Worker is the worker that processes phishing events and updates campaigns. var Worker *worker.Worker func init() { diff --git a/controllers/route.go b/controllers/route.go index 78de0fa0..46c73b97 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -116,7 +116,13 @@ func Register(w http.ResponseWriter, r *http.Request) { case r.Method == "GET": params.Flashes = session.Flashes() session.Save(r, w) - getTemplate(w, "register").ExecuteTemplate(w, "base", params) + templates := template.New("template") + templates.Delims(templateDelims[0], templateDelims[1]) + _, err := templates.ParseFiles("templates/register.html", "templates/flashes.html") + if err != nil { + Logger.Println(err) + } + template.Must(templates, err).ExecuteTemplate(w, "base", params) case r.Method == "POST": //Attempt to register succ, err := auth.Register(r) diff --git a/models/models.go b/models/models.go index 764798c8..f887741a 100644 --- a/models/models.go +++ b/models/models.go @@ -5,14 +5,11 @@ import ( "log" "os" - "github.com/coopernurse/gorp" "github.com/jinzhu/gorm" "github.com/jordan-wright/gophish/config" _ "github.com/mattn/go-sqlite3" // Blank import needed to import sqlite3 ) -// Conn is the connection to the SQLite database -var Conn *gorp.DbMap var db gorm.DB var err error diff --git a/models/user.go b/models/user.go index a3915c2c..c131786f 100644 --- a/models/user.go +++ b/models/user.go @@ -1,6 +1,6 @@ package models -import "database/sql" +import "github.com/jinzhu/gorm" // User represents the user model for gophish. type User struct { @@ -37,12 +37,13 @@ func GetUserByAPIKey(key string) (User, error) { func GetUserByUsername(username string) (User, error) { u := User{} err := db.Where("username = ?", username).First(&u).Error - if err != sql.ErrNoRows { + // No issue if we don't find a record + if err == gorm.RecordNotFound { + return u, nil + } else if err == nil { return u, ErrUsernameTaken - } else if err != nil { - return u, err } - return u, nil + return u, err } // PutUser updates the given user diff --git a/static/js/app/partials/landing_pages.html b/static/js/app/partials/landing_pages.html index 256289ec..099a09e6 100644 --- a/static/js/app/partials/landing_pages.html +++ b/static/js/app/partials/landing_pages.html @@ -44,21 +44,22 @@
{{page.name}} | +{{page.name}}
+
+
+
+
+ |
{{page.modified_date | date:'medium'}} | -