Files
kavehhn 192c595c68 feat: add password change, class unenroll, and optional notify flags
Let admins skip SMS on user, class, and invoice actions, and let users change their own password with the current one.
2026-08-15 23:48:18 +03:30

35 lines
1.2 KiB
JavaScript

// /components/auth/authController.js
const catchAsync = require('../../utils/catchAsync');
const authService = require('./authService');
const { successResponse } = require('../../utils/apiResponse');
exports.login = catchAsync(async (req, res, next) => {
const { username, password } = req.body;
const result = await authService.login(username, password);
return successResponse(res, 200, 'Login successful', result);
});
exports.refresh = catchAsync(async (req, res, next) => {
const { refreshToken } = req.body;
const result = await authService.refreshToken(refreshToken);
return successResponse(res, 200, 'Tokens refreshed successfully', result);
});
exports.logout = catchAsync(async (req, res, next) => {
const { refreshToken } = req.body;
const userId = req.user?._id;
await authService.logout(userId, refreshToken);
return successResponse(res, 200, 'Logout successful');
});
exports.changePassword = catchAsync(async (req, res) => {
const { currentPassword, newPassword, refreshToken } = req.body;
await authService.changePassword(req.user._id, {
currentPassword,
newPassword,
refreshToken
});
return successResponse(res, 200, 'Password changed successfully');
});