Compare commits
2 Commits
test/node_
...
feat3580-u
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c52f1b22b6 | ||
|
|
b4e38b6b38 |
@@ -1,6 +1,10 @@
|
||||
package migrator
|
||||
|
||||
import "github.com/portainer/portainer/api"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/portainer/portainer/api"
|
||||
)
|
||||
|
||||
func (m *Migrator) updateEndointsAndEndpointsGroupsToDBVersion23() error {
|
||||
tags, err := m.tagService.Tags()
|
||||
@@ -55,3 +59,21 @@ func (m *Migrator) updateEndointsAndEndpointsGroupsToDBVersion23() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Migrator) updateUsersToDBVersion23() error {
|
||||
legacyUsers, err := m.userService.Users()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, user := range legacyUsers {
|
||||
user.Username = strings.ToLower(user.Username)
|
||||
|
||||
err = m.userService.UpdateUser(user.ID, &user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -311,6 +311,11 @@ func (m *Migrator) Migrate() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.updateUsersToDBVersion23()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return m.versionService.StoreDBVersion(portainer.DBVersion)
|
||||
|
||||
@@ -47,7 +47,9 @@ func (handler *Handler) authenticate(w http.ResponseWriter, r *http.Request) *ht
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve settings from the database", err}
|
||||
}
|
||||
|
||||
u, err := handler.UserService.UserByUsername(payload.Username)
|
||||
userName := strings.ToLower(payload.Username)
|
||||
|
||||
u, err := handler.UserService.UserByUsername(userName)
|
||||
if err != nil && err != portainer.ErrObjectNotFound {
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve a user with the specified username from the database", err}
|
||||
}
|
||||
@@ -58,7 +60,7 @@ func (handler *Handler) authenticate(w http.ResponseWriter, r *http.Request) *ht
|
||||
|
||||
if settings.AuthenticationMethod == portainer.AuthenticationLDAP {
|
||||
if u == nil && settings.LDAPSettings.AutoCreateUsers {
|
||||
return handler.authenticateLDAPAndCreateUser(w, payload.Username, payload.Password, &settings.LDAPSettings)
|
||||
return handler.authenticateLDAPAndCreateUser(w, userName, payload.Password, &settings.LDAPSettings)
|
||||
} else if u == nil && !settings.LDAPSettings.AutoCreateUsers {
|
||||
return &httperror.HandlerError{http.StatusUnprocessableEntity, "Invalid credentials", portainer.ErrUnauthorized}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package users
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
@@ -43,7 +44,7 @@ func (handler *Handler) adminInit(w http.ResponseWriter, r *http.Request) *httpe
|
||||
}
|
||||
|
||||
user := &portainer.User{
|
||||
Username: payload.Username,
|
||||
Username: strings.ToLower(payload.Username),
|
||||
Role: portainer.AdministratorRole,
|
||||
PortainerAuthorizations: portainer.DefaultPortainerAuthorizations(),
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package users
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
httperror "github.com/portainer/libhttp/error"
|
||||
@@ -49,7 +50,9 @@ func (handler *Handler) userCreate(w http.ResponseWriter, r *http.Request) *http
|
||||
return &httperror.HandlerError{http.StatusForbidden, "Permission denied to create administrator user", portainer.ErrResourceAccessDenied}
|
||||
}
|
||||
|
||||
user, err := handler.UserService.UserByUsername(payload.Username)
|
||||
userName := strings.ToLower(payload.Username)
|
||||
|
||||
user, err := handler.UserService.UserByUsername(userName)
|
||||
if err != nil && err != portainer.ErrObjectNotFound {
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve users from the database", err}
|
||||
}
|
||||
@@ -58,7 +61,7 @@ func (handler *Handler) userCreate(w http.ResponseWriter, r *http.Request) *http
|
||||
}
|
||||
|
||||
user = &portainer.User{
|
||||
Username: payload.Username,
|
||||
Username: strings.ToLower(userName),
|
||||
Role: portainer.UserRole(payload.Role),
|
||||
PortainerAuthorizations: portainer.DefaultPortainerAuthorizations(),
|
||||
}
|
||||
|
||||
@@ -27,21 +27,24 @@ angular.module('portainer.app').controller('UsersController', [
|
||||
};
|
||||
|
||||
$scope.checkUsernameValidity = function () {
|
||||
var valid = true;
|
||||
for (var i = 0; i < $scope.users.length; i++) {
|
||||
if ($scope.formValues.Username === $scope.users[i].Username) {
|
||||
valid = false;
|
||||
break;
|
||||
const currentUsername = _.toLower($scope.formValues.Username);
|
||||
let validUsername = true;
|
||||
|
||||
_.forEach($scope.users, (user) => {
|
||||
if (user.Username === currentUsername) {
|
||||
validUsername = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
$scope.state.validUsername = valid;
|
||||
$scope.state.userCreationError = valid ? '' : 'Username already taken';
|
||||
});
|
||||
|
||||
$scope.state.validUsername = validUsername;
|
||||
$scope.state.userCreationError = validUsername ? '' : 'Username already taken';
|
||||
};
|
||||
|
||||
$scope.addUser = function () {
|
||||
$scope.state.actionInProgress = true;
|
||||
$scope.state.userCreationError = '';
|
||||
var username = $scope.formValues.Username;
|
||||
var username = _.toLower($scope.formValues.Username);
|
||||
var password = $scope.formValues.Password;
|
||||
var role = $scope.formValues.Administrator ? 1 : 2;
|
||||
var teamIds = [];
|
||||
|
||||
Reference in New Issue
Block a user