Revert "fix: hardcode credentials"
This commit is contained in:
+2
-6
@@ -175,8 +175,6 @@ FINAL_PORT=$(get_random_port)
|
|||||||
# --- 4. Генерация паролей ---
|
# --- 4. Генерация паролей ---
|
||||||
DB_PASS=$(openssl rand -base64 12)
|
DB_PASS=$(openssl rand -base64 12)
|
||||||
JWT_SECRET=$(openssl rand -base64 32)
|
JWT_SECRET=$(openssl rand -base64 32)
|
||||||
ADMIN_USER=$(openssl rand -base64 12)
|
|
||||||
ADMIN_PASS=$(openssl rand -base64 12)
|
|
||||||
log "Сгенерированы секретные ключи для БД и JWT."
|
log "Сгенерированы секретные ключи для БД и JWT."
|
||||||
|
|
||||||
#################################
|
#################################
|
||||||
@@ -188,8 +186,6 @@ DB_PORT=5432
|
|||||||
DB_USERNAME=admin
|
DB_USERNAME=admin
|
||||||
DB_PASSWORD=${DB_PASS}
|
DB_PASSWORD=${DB_PASS}
|
||||||
DB_NAME=3dp_manager
|
DB_NAME=3dp_manager
|
||||||
ADMIN_LOGIN=${ADMIN_USER}
|
|
||||||
ADMIN_PASSWORD=${ADMIN_PASS}
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [[ "$USE_SSL" == "true" ]]; then
|
if [[ "$USE_SSL" == "true" ]]; then
|
||||||
@@ -416,8 +412,8 @@ if [[ "$USE_SSL" == "true" ]]; then
|
|||||||
else
|
else
|
||||||
echo -e "${GREEN}✔ Установка завершена! Доступно по адресу: http://${UI_HOST}:${FINAL_PORT}${NC}"
|
echo -e "${GREEN}✔ Установка завершена! Доступно по адресу: http://${UI_HOST}:${FINAL_PORT}${NC}"
|
||||||
fi
|
fi
|
||||||
echo "${GREEN}Логин: $ADMIN_USER"
|
echo "Логин: admin"
|
||||||
echo "${GREEN}Пароль: $ADMIN_PASS"
|
echo "Пароль: admin"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Немедленно измените пароль в Настройках утилиты!"
|
echo "Немедленно измените пароль в Настройках утилиты!"
|
||||||
echo "==================================================="
|
echo "==================================================="
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
DB_HOST=localhost
|
|
||||||
DB_PORT=5432
|
|
||||||
DB_USERNAME=admin
|
|
||||||
DB_PASSWORD=
|
|
||||||
DB_NAME=3dp_manager
|
|
||||||
ADMIN_LOGIN=admin
|
|
||||||
ADMIN_PASSWORD=
|
|
||||||
@@ -4,7 +4,6 @@ import { InjectRepository } from '@nestjs/typeorm';
|
|||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
import { Setting } from '../settings/entities/setting.entity';
|
import { Setting } from '../settings/entities/setting.entity';
|
||||||
import { ConfigService } from '@nestjs/config';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
@@ -14,7 +13,6 @@ export class AuthService {
|
|||||||
@InjectRepository(Setting)
|
@InjectRepository(Setting)
|
||||||
private settingsRepo: Repository<Setting>,
|
private settingsRepo: Repository<Setting>,
|
||||||
private jwtService: JwtService,
|
private jwtService: JwtService,
|
||||||
private configService: ConfigService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async validateUser(login: string, pass: string): Promise<any> {
|
async validateUser(login: string, pass: string): Promise<any> {
|
||||||
@@ -87,14 +85,12 @@ export class AuthService {
|
|||||||
const login = await this.settingsRepo.findOne({ where: { key: 'admin_login' } });
|
const login = await this.settingsRepo.findOne({ where: { key: 'admin_login' } });
|
||||||
|
|
||||||
if (!login) {
|
if (!login) {
|
||||||
this.logger.log('Инициализация администратора...');
|
this.logger.log('Инициализация администратора (admin / admin)...');
|
||||||
const envLogin = this.configService.get<string>('ADMIN_LOGIN') || 'admin';
|
|
||||||
const envPass = this.configService.get<string>('ADMIN_PASSWORD') || 'admin';
|
|
||||||
|
|
||||||
const loginSetting = this.settingsRepo.create({ key: 'admin_login', value: envLogin });
|
const loginSetting = this.settingsRepo.create({ key: 'admin_login', value: 'admin' });
|
||||||
await this.settingsRepo.save(loginSetting);
|
await this.settingsRepo.save(loginSetting);
|
||||||
|
|
||||||
const hash = await bcrypt.hash(envPass, 10);
|
const hash = await bcrypt.hash('admin', 10);
|
||||||
const passSetting = this.settingsRepo.create({ key: 'admin_password', value: hash });
|
const passSetting = this.settingsRepo.create({ key: 'admin_password', value: hash });
|
||||||
await this.settingsRepo.save(passSetting);
|
await this.settingsRepo.save(passSetting);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user