mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Various fixes in login sources (#10428)
This commit is contained in:
		@@ -18,6 +18,7 @@ import (
 | 
			
		||||
	"image/png"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"regexp"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
@@ -87,6 +88,9 @@ var (
 | 
			
		||||
 | 
			
		||||
	// ErrUnsupportedLoginType login source is unknown error
 | 
			
		||||
	ErrUnsupportedLoginType = errors.New("Login source is unknown")
 | 
			
		||||
 | 
			
		||||
	// Characters prohibited in a user name (anything except A-Za-z0-9_.-)
 | 
			
		||||
	alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// User represents the object of individual and member of organization.
 | 
			
		||||
@@ -906,6 +910,11 @@ func isUsableName(names, patterns []string, name string) error {
 | 
			
		||||
 | 
			
		||||
// IsUsableUsername returns an error when a username is reserved
 | 
			
		||||
func IsUsableUsername(name string) error {
 | 
			
		||||
	// Validate username make sure it satisfies requirement.
 | 
			
		||||
	if alphaDashDotPattern.MatchString(name) {
 | 
			
		||||
		// Note: usually this error is normally caught up earlier in the UI
 | 
			
		||||
		return ErrNameCharsNotAllowed{Name: name}
 | 
			
		||||
	}
 | 
			
		||||
	return isUsableName(reservedUsernames, reservedUserPatterns, name)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user