mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
Insert and Update Users instead of generic Save function. Check ID != 0
This commit is contained in:
parent
881dcb153e
commit
d0b722cc8b
3 changed files with 27 additions and 8 deletions
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue