All checks were successful
Deploy to production / deploy (push) Successful in 1m55s
- Added user blocking checks in authentication and reporting processes, returning appropriate error responses. - Expanded moderation report functionality to include new target types and optional fields for reports. - Implemented a new API endpoint to retrieve the count of open moderation reports. - Enhanced frontend components to allow users to report profiles, images, and guestbook entries, with corresponding UI updates. - Updated internationalization files to include new strings for reporting features in both German and English.
68 lines
2.2 KiB
JavaScript
68 lines
2.2 KiB
JavaScript
import * as userService from '../services/authService.js';
|
|
|
|
class AuthController {
|
|
constructor() {
|
|
this.register = this.register.bind(this);
|
|
this.login = this.login.bind(this);
|
|
this.forgotPassword = this.forgotPassword.bind(this);
|
|
this.activateAccount = this.activateAccount.bind(this);
|
|
this.logout = this.logout.bind(this);
|
|
}
|
|
|
|
async register(req, res) {
|
|
const { email, username, password, language } = req.body;
|
|
try {
|
|
const result = await userService.registerUser({ email, username, password, language });
|
|
res.status(201).json(result);
|
|
} catch (error) {
|
|
console.log(error);
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async login(req, res) {
|
|
const { username, password } = req.body;
|
|
try {
|
|
const result = await userService.loginUser({ username, password });
|
|
console.log('User logged in successfully', result);
|
|
res.status(200).json(result);
|
|
} catch (error) {
|
|
if (error.message === 'credentialsinvalid') {
|
|
res.status(404).json({ error: error.message });
|
|
} else if (error.message === 'userblocked') {
|
|
res.status(403).json({ error: error.message });
|
|
} else {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
}
|
|
|
|
async logout(req, res) {
|
|
const { userid: hashedUserId } = req.headers;
|
|
await userService.logoutUser(hashedUserId);
|
|
res.status(200).json({ result: 'loggedout' });
|
|
}
|
|
|
|
async forgotPassword(req, res) {
|
|
const { email } = req.body;
|
|
try {
|
|
const result = await userService.handleForgotPassword({ email });
|
|
res.status(200).json(result);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
|
|
async activateAccount(req, res) {
|
|
const { token } = req.body;
|
|
try {
|
|
const result = await userService.activateUserAccount({ token });
|
|
res.status(200).json(result);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
}
|
|
}
|
|
|
|
export default AuthController;
|