| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- import bodyParser from "body-parser";
- import express from "express";
- import dotenv from "dotenv";
- import cors from "cors";
- import {
- CoreComplexClient,
- setServerURL
- } from "core-complex-client";
- dotenv.config();
- const app = express();
- app.use(bodyParser.json({ limit: "30mb", extended: true }));
- app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
- app.use(cors());
- setServerURL(process.env.SERVER_URL);
- const coreClient = new CoreComplexClient({
- rsaPublicKey: process.env.PUBLIC_KEY,
- privateKeyID: process.env.PRIVATE_KEY_ID,
- privateKey: process.env.PRIVATE_KEY,
- appID: process.env.APP_ID
- });
- app.get("/healthCheck", (req, res) => {
- res.status(200).json("It works!");
- });
- //NAuth
- app.post("/nauth/changePassword", async (req, res) => {
- await coreClient.NAuth.changePassword({
- newPassword: req.body.newPassword,
- oldPassword: req.body.oldPassword
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/login", async (req, res) => {
- await coreClient.NAuth.login({
- mail: req.body.mail,
- password: req.body.password
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/mailVerify", async (req, res) => {
- await coreClient.NAuth.mailVerify({
- hash: req.body.hash,
- code: req.body.code
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.get("/nauth/me", async (req, res) => {
- await coreClient.NAuth.me()
- .then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/refreshToken", async (req, res) => {
- await coreClient.NAuth.refreshToken({
- token: req.body.token
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/register", async (req, res) => {
- await coreClient.NAuth.register({
- isApproveContracts: req.body.isApproveContracts,
- phoneAreaCode: req.body.phoneAreaCode,
- firstName: req.body.firstName,
- password: req.body.password,
- lastName: req.body.lastName,
- userName: req.body.userName,
- language: req.body.language,
- phone: req.body.phone,
- mail: req.body.mail
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/reSendCodeSMSOTP", async (req, res) => {
- await coreClient.NAuth.reSendCodeSMSOTP({
- mail: req.body.mail
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/startResetPassword", async (req, res) => {
- let params = {
- };
- if (req.body.mail) {
- params.mail = req.body.mail;
- }
- if (req.body.userName) {
- params.userName = req.body.userName;
- }
- if (req.body.phone) {
- const phone = {
- phoneAreaCode: req.body.phoneAreaCode,
- phone: req.body.phone
- }
- params.phone = phone;
- }
- await coreClient.NAuth.startResetPassword(params)
- .then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/confirmResetPasswordMethod", async (req, res) => {
- let params = {
- method: req.body.method
- };
- if (req.body.userName) {
- params.userName = req.body.userName;
- }
- if (req.body.mail) {
- params.mail = req.body.mail;
- }
- if (req.body.phone) {
- const phone = {
- phoneAreaCode: req.body.phoneAreaCode,
- phone: req.body.phone
- }
- params.phone = phone;
- }
- if (req.body.targetMail) {
- params.targetMail = req.body.targetMail;
- }
- if (req.body.targetPhone) {
- const target = {
- phoneAreaCode: req.body.targetPhoneAreaCode,
- phone: req.body.targetPhone
- }
- params.targetPhone = target
- }
- await coreClient.NAuth.confirmResetPasswordMethod(params)
- .then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/resetPasswordCheckCode", async (req, res) => {
- let params = {
- code: req.body.code
- };
- if (req.body.mail) {
- params.mail = req.body.mail;
- }
- if (req.body.userName) {
- params.userName = req.body.userName;
- }
- if (req.body.phone) {
- const phone = {
- phoneAreaCode: req.body.phoneAreaCode,
- phone: req.body.phone
- }
- params.phone = phone;
- }
- await coreClient.NAuth.resetPasswordCheckCode(params)
- .then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/resetNewPassword", async (req, res) => {
- let params = {
- newPassword: req.body.newPassword,
- code: req.body.code
- };
- if (req.body.mail) {
- params.mail = req.body.mail;
- }
- if (req.body.userName) {
- params.userName = req.body.userName;
- }
- if (req.body.phone) {
- const phone = {
- phoneAreaCode: req.body.phoneAreaCode,
- phone: req.body.phone
- }
- params.phone = phone;
- }
- await coreClient.NAuth.resetNewPassword(params)
- .then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/smsOTP", async (req, res) => {
- await coreClient.NAuth.smsOTP({
- mail: req.body.mail,
- code: req.body.code
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nauth/startMailVerify", async (req, res) => {
- await coreClient.NAuth.startMailVerify({
- mail: req.body.mail
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- //NChar
- app.get("/nchar/me", async (req, res) => {
- await coreClient.NChar.me()
- .then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- /* app.post("/nchar/startChangeMail", async (req, res) => {
- await coreClient.NChar.startChangeMail({
- mail: req.body.mail
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/checkChangeMailCode", async (req, res) => {
- await coreClient.NChar.checkChangeMailCode({
- mail: req.body.mail,
- code: req.body.code
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- }); */
- app.post("/nchar/addPhoneNumber", async (req, res) => {
- await coreClient.NChar.addPhoneNumber({
- phoneAreaCode: req.body.phoneAreaCode,
- phone: req.body.phone
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/deletePhoneNumber", async (req, res) => {
- await coreClient.NChar.deletePhoneNumber({
- phoneAreaCode: req.body.phoneAreaCode,
- phone: req.body.phone
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/setPrimaryPhoneNumber", async (req, res) => {
- await coreClient.NChar.setPrimaryPhoneNumber({
- phoneAreaCode: req.body.phoneAreaCode,
- phone: req.body.phone
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/setPrimaryPhoneNumberCheckCode", async (req, res) => {
- await coreClient.NChar.setPrimaryPhoneNumberCheckCode({
- phoneAreaCode: req.body.phoneAreaCode,
- phone: req.body.phone,
- code: req.body.code
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/changeUserName", async (req, res) => {
- await coreClient.NChar.changeUserName({
- userName: req.body.userName
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.get("/nchar/getPastUserNameChanges", async (req, res) => {
- await coreClient.NChar.getPastUserNameChanges()
- .then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/editUserProfile", async (req, res) => {
- let params = {};
- if (req.body.firstName) params.firstName = req.body.firstName;
- if (req.body.lastName) params.lastName = req.body.lastName;
- await coreClient.NChar.editUserProfile(params).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/addMail", async (req, res) => {
- await coreClient.NChar.addMail({
- mail: req.body.mail
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/deleteMail", async (req, res) => {
- await coreClient.NChar.deleteMail({
- mail: req.body.mail
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/setPrimaryMail", async (req, res) => {
- await coreClient.NChar.setPrimaryMail({
- mail: req.body.mail
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- app.post("/nchar/setPrimaryMailCheckCode", async (req, res) => {
- await coreClient.NChar.setPrimaryMailCheckCode({
- mail: req.body.mail,
- code: req.body.code
- }).then((resp) => {
- res.status(200).json(resp);
- }).catch((err) => {
- console.log("err:", err)
- res.status(400).json("something-went-wrong");
- });
- });
- const PORT = process.env.PORT || 5000;
- app.listen(PORT, () => {
- console.log("Server is running on port " + PORT);
- });
|