mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +01:00
merge master
This commit is contained in:
commit
d66a8f913e
10
api/log.go
10
api/log.go
@ -61,14 +61,18 @@ func (l *LogAPI) Get() {
|
||||
|
||||
var linesNum int
|
||||
lines := l.GetString("lines")
|
||||
if len(lines) == 0 && len(startTime) == 0 && len(endTime) == 0 {
|
||||
linesNum = 10
|
||||
} else if len(lines) != 0 {
|
||||
if len(lines) != 0 {
|
||||
linesNum, err = strconv.Atoi(lines)
|
||||
if err != nil {
|
||||
log.Errorf("Get parameters error--lines, err: %v", err)
|
||||
l.CustomAbort(http.StatusBadRequest, "bad request of lines")
|
||||
}
|
||||
if linesNum <= 0 {
|
||||
log.Warning("lines must be a positive integer")
|
||||
l.CustomAbort(http.StatusBadRequest, "lines is 0 or negative")
|
||||
}
|
||||
} else if len(startTime) == 0 && len(endTime) == 0 {
|
||||
linesNum = 10
|
||||
}
|
||||
|
||||
var logList []models.AccessLog
|
||||
|
@ -289,8 +289,8 @@ func (ra *RepositoryAPI) getUsername() (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
//GetTopTenRepos handles request GET /api/repositories/toprepos
|
||||
func (ra *RepositoryAPI) GetTopTenRepos() {
|
||||
//GetTopRepos handles request GET /api/repositories/top
|
||||
func (ra *RepositoryAPI) GetTopRepos() {
|
||||
var err error
|
||||
var countNum int
|
||||
count := ra.GetString("count")
|
||||
@ -307,7 +307,7 @@ func (ra *RepositoryAPI) GetTopTenRepos() {
|
||||
ra.CustomAbort(http.StatusBadRequest, "count is 0 or negative")
|
||||
}
|
||||
}
|
||||
repos, err := dao.GetTop10Repos(countNum)
|
||||
repos, err := dao.GetTopRepos(countNum)
|
||||
if err != nil {
|
||||
log.Errorf("error occured in get top 10 repos: %v", err)
|
||||
ra.CustomAbort(http.StatusInternalServerError, "internal server error")
|
||||
|
12
api/user.go
12
api/user.go
@ -201,6 +201,16 @@ func (ua *UserAPI) Post() {
|
||||
ua.RenderError(http.StatusConflict, "username has already been used!")
|
||||
return
|
||||
}
|
||||
emailExist, err := dao.UserExists(user, "email")
|
||||
if err != nil {
|
||||
log.Errorf("Error occurred in change user profile: %v", err)
|
||||
ua.CustomAbort(http.StatusInternalServerError, "Internal error.")
|
||||
}
|
||||
if emailExist {
|
||||
log.Warning("email has already been used!")
|
||||
ua.RenderError(http.StatusConflict, "email has already been used!")
|
||||
return
|
||||
}
|
||||
userID, err := dao.Register(user)
|
||||
if err != nil {
|
||||
log.Errorf("Error occurred in Register: %v", err)
|
||||
@ -308,6 +318,8 @@ func commonValidate(user models.User) error {
|
||||
if m, _ := regexp.MatchString(`^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$`, user.Email); !m {
|
||||
return fmt.Errorf("Email with illegal format.")
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("Email can't be empty")
|
||||
}
|
||||
|
||||
if isIllegalLength(user.Realname, 0, 20) {
|
||||
|
@ -111,6 +111,9 @@ func (l *Auth) Authenticate(m models.AuthModel) (*models.User, error) {
|
||||
u.Realname = m.Principal
|
||||
u.Password = "12345678AbC"
|
||||
u.Comment = "registered from LDAP."
|
||||
if u.Email == "" {
|
||||
u.Email = u.Username + "@vmware.com"
|
||||
}
|
||||
userID, err := dao.Register(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -18,8 +18,6 @@ package dao
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
|
||||
"github.com/vmware/harbor/models"
|
||||
"github.com/vmware/harbor/utils/log"
|
||||
)
|
||||
@ -148,8 +146,8 @@ func GetRecentLogs(userID, linesNum int, startTime, endTime string) ([]models.Ac
|
||||
return recentLogList, nil
|
||||
}
|
||||
|
||||
//GetTop10Repos return top 10 accessed public repos
|
||||
func GetTop10Repos(countNum int) ([]orm.ParamsList, error) {
|
||||
//GetTopRepos return top accessed public repos
|
||||
func GetTopRepos(countNum int) ([]orm.ParamsList, error) {
|
||||
|
||||
o := GetOrmer()
|
||||
|
||||
|
@ -25,10 +25,6 @@ import (
|
||||
|
||||
// Register is used for user to register, the password is encrypted before the record is inserted into database.
|
||||
func Register(user models.User) (int64, error) {
|
||||
//when register from ldap, email may be empty
|
||||
if user.Email == "" {
|
||||
user.Email = user.Username + "@vmware.com"
|
||||
}
|
||||
o := GetOrmer()
|
||||
p, err := o.Raw("insert into user (username, password, realname, email, comment, salt, sysadmin_flag, creation_time, update_time) values (?, ?, ?, ?, ?, ?, ?, ?, ?)").Prepare()
|
||||
if err != nil {
|
||||
|
@ -232,10 +232,6 @@ func DeleteUser(userID int) error {
|
||||
|
||||
// ChangeUserProfile ...
|
||||
func ChangeUserProfile(user models.User) error {
|
||||
//email is null is permitted
|
||||
if user.Email == "" {
|
||||
user.Email = user.Username + "@vmware.com"
|
||||
}
|
||||
o := GetOrmer()
|
||||
if _, err := o.Update(&user, "Email", "Realname", "Comment"); err != nil {
|
||||
log.Errorf("update user failed, error: %v", err)
|
||||
|
@ -64,7 +64,7 @@ func initRouters() {
|
||||
beego.Router("/api/repositories", &api.RepositoryAPI{})
|
||||
beego.Router("/api/repositories/tags", &api.RepositoryAPI{}, "get:GetTags")
|
||||
beego.Router("/api/repositories/manifests", &api.RepositoryAPI{}, "get:GetManifests")
|
||||
beego.Router("/api/repositories/top", &api.RepositoryAPI{}, "get:GetTopTenRepos")
|
||||
beego.Router("/api/repositories/top", &api.RepositoryAPI{}, "get:GetTopRepos")
|
||||
beego.Router("api/logs", &api.LogAPI{})
|
||||
|
||||
//external service that hosted on harbor process:
|
||||
|
Loading…
Reference in New Issue
Block a user