HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
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.'));
  }
};