diff --git a/server/datastore/database/user.go b/server/datastore/database/user.go index 25de0802..f6b25040 100644 --- a/server/datastore/database/user.go +++ b/server/datastore/database/user.go @@ -49,20 +49,15 @@ func (db *Userstore) GetUserList() ([]*model.User, error) { // PostUser saves a User in the datastore. func (db *Userstore) PostUser(user *model.User) error { - if user.Created == 0 { - user.Created = time.Now().UTC().Unix() - } + user.Created = time.Now().UTC().Unix() user.Updated = time.Now().UTC().Unix() - return meddler.Save(db, userTable, user) + return meddler.Insert(db, userTable, user) } // PutUser saves a user in the datastore. func (db *Userstore) PutUser(user *model.User) error { - if user.Created == 0 { - user.Created = time.Now().UTC().Unix() - } user.Updated = time.Now().UTC().Unix() - return meddler.Save(db, userTable, user) + return meddler.Update(db, userTable, user) } // DelUser removes the user from the datastore. diff --git a/server/handler/login.go b/server/handler/login.go index 285702d0..2f08debe 100644 --- a/server/handler/login.go +++ b/server/handler/login.go @@ -70,6 +70,13 @@ func GetLogin(c web.C, w http.ResponseWriter, r *http.Request) { return } + // the user id should NEVER equal zero + if u.ID == 0 { + log.Println("Unable to create account. User ID is zero") + w.WriteHeader(http.StatusInternalServerError) + return + } + // if this is the first user, they // should be an admin. if u.ID == 1 { diff --git a/shared/model/request.go b/shared/model/request.go index 594cbeb2..94075a88 100644 --- a/shared/model/request.go +++ b/shared/model/request.go @@ -1,5 +1,9 @@ package model +import ( + "fmt" +) + type Request struct { Host string `json:"-"` User *User `json:"-"` @@ -7,3 +11,16 @@ type Request struct { Commit *Commit `json:"commit"` Prior *Commit `json:"prior_commit"` } + +// URL returns the link to the commit in +// string format. +func (r *Request) URL() string { + return fmt.Sprintf("%s/%s/%s/%s", + r.Host, + r.Repo.Host, + r.Repo.Owner, + r.Repo.Name, + r.Commit.Branch, + r.Commit.Sha, + ) +}