/
uzer_007
/
Rixea
Обзор
Документация
Войти
/
uzer_007
/
Rixea
Код
Запросы
0
Задачи
Вики
Пакеты
5
Релизы
2
CI/CD
Аналитика
Безопасность
master
services/user/admin_create.go
51 строка
1 KB
uzer_007
feat: первая версия Rixea
02 авг 2026, 22:16
02 авг 2026, 22:16
d4f7504
Код
Авторство
О чём код?
// Copyright 2026 Uzer_007. All rights reserved. // SPDX-License-Identifier: MIT package user import ( "context" "strings" user_model "gitverse.ru/uzer_007/Rixea/models/user" password_module "gitverse.ru/uzer_007/Rixea/modules/auth/password" "gitverse.ru/uzer_007/Rixea/modules/setting" "gitverse.ru/uzer_007/Rixea/modules/util" ) // PrepareUserForAdminCreate validates authentication fields and removes // passwords unsupported by the selected source before the user is persisted. func PrepareUserForAdminCreate(ctx context.Context, user *user_model.User, mustChangePassword bool) error { if user == nil { return util.NewInvalidArgumentErrorf("user is required") } if !user.IsLocal() && strings.TrimSpace(user.LoginName) == "" { return ErrAdminAuthLoginNameRequired } if !user.IsLocal() && !user.IsOAuth2() { user.Passwd = "" user.MustChangePassword = false return nil } if user.Passwd == "" { user.MustChangePassword = false if user.IsLocal() { return password_module.ErrMinLength } return nil } if len(user.Passwd) < setting.MinPasswordLength { return password_module.ErrMinLength } if !password_module.IsComplexEnough(user.Passwd) { return password_module.ErrComplexity } if err := password_module.IsPwned(ctx, user.Passwd); err != nil { return err } user.MustChangePassword = mustChangePassword return nil }