summaryrefslogtreecommitdiff
path: root/src/pages/api/activation-request.js
blob: 42ad536445f9478a645984e64c2cad28507d107f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import apiOdoo from "../../helpers/apiOdoo";
import mailer from "../../helpers/mailer";

export default async function handler(req, res) {
  try {
    const { email } = req.body;
    let result = await apiOdoo(
      'POST', 
      '/api/v1/user/activation-request', 
      {email}
    );
    if (result.activation_request) {
      mailer.sendMail({
        from: 'sales@indoteknik.com',
        to: result.user.email,
        subject: 'Permintaan Aktivasi Akun Indoteknik',
        html: `
          <h1>Permintaan Aktivasi Akun Indoteknik</h1>
          <br>
          <p>Aktivasi akun anda melalui link berikut: <a href="${process.env.SELF_HOST}/activate?token=${result.token}">Aktivasi Akun</a></p>
        `
      });
    }
    delete result.user;
    delete result.token;
    res.status(200).json(result);
  } catch (error) {
    console.log(error);
    res.status(400).json({ error: error.message });
  }
}