File: //proc/thread-self/root/home/arjun/projects/good-life-be/api/Auth/controller.js
import { failedResponse, goodResponse } from '../../helper/response.js';
import {
forgotPassword,
loginSevice,
resetPasswordService,
signUpService,
verifyEmail,
} from './service.js';
export const signIn = async (req, res) => {
const data = await loginSevice(req.body);
return res.json(goodResponse({ data }, 'You have logged in successfully.'));
};
export const signUp = async (req, res) => {
await signUpService(req.body);
return res.json(
goodResponse(
{},
'You have successfully signed up. Please check your email.'
)
);
};
export const emailVerification = async (req, res) => {
await verifyEmail(req.query);
return res.json(
goodResponse({}, 'Email verified successfully. You can now log in.')
);
};
export const sendForgotPasswordEmail = async (req, res) => {
const { email } = req.body;
if (!email || email.trim() === '') {
return res.json(failedResponse('Invalid email id', 400, 'Invalid email'));
}
const token = await forgotPassword(email);
if (!token) {
return res.json(
failedResponse('Something went wrong', 400, 'Something went wrong')
);
}
return res.json(
goodResponse({ data: {} }, 'Reset link has been sent successfully')
);
};
export const resetPassword = async (req, res) => {
const { token, password } = req.body;
await resetPasswordService(token, password);
if (password) {
return res.json(goodResponse({}, 'Password updated successfully.'));
}
};