2026-09-25 19:04:48 +03:30
|
|
|
import { Body, Controller, Get, Headers, HttpCode, Ip, Post } from '@nestjs/common';
|
2026-09-13 21:02:25 +03:30
|
|
|
import { AuthService } from './auth.service';
|
|
|
|
|
import { LoginDto } from './dto/login.dto';
|
|
|
|
|
import { CurrentAdmin, Public } from './guards';
|
|
|
|
|
import type { AuthenticatedAdmin } from './jwt.strategy';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Legacy endpoints (henza_server routes/admin.php):
|
|
|
|
|
* POST admin-login -> AdminController::login
|
|
|
|
|
* GET users/show -> UserController::showData
|
|
|
|
|
*
|
|
|
|
|
* Exposed here under the clean /api/admin/auth prefix; the admin panel's mapping
|
|
|
|
|
* layer translates the legacy paths onto these.
|
|
|
|
|
*/
|
|
|
|
|
@Controller('admin/auth')
|
|
|
|
|
export class AuthController {
|
|
|
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
|
|
|
|
|
|
@Public()
|
|
|
|
|
@Post('login')
|
|
|
|
|
@HttpCode(200)
|
2026-09-25 19:04:48 +03:30
|
|
|
login(@Body() dto: LoginDto, @Ip() ip: string, @Headers('user-agent') userAgent?: string) {
|
|
|
|
|
// The IP is forwarded to the identity service (when delegation is on) so its
|
|
|
|
|
// per-IP rate limit applies to the real admin, not to this API server; both
|
|
|
|
|
// are also recorded on the session row when session tracking is on.
|
|
|
|
|
return this.authService.login(dto, ip, userAgent);
|
2026-09-13 21:02:25 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Legacy `users/show` — the router guard's permission refresh. */
|
|
|
|
|
@Get('me')
|
|
|
|
|
me(@CurrentAdmin() admin: AuthenticatedAdmin) {
|
|
|
|
|
return this.authService.showData(admin.id);
|
|
|
|
|
}
|
|
|
|
|
}
|