diff --git a/.next/build-manifest.json b/.next/build-manifest.json
index 1aaa22a..a59a444 100644
--- a/.next/build-manifest.json
+++ b/.next/build-manifest.json
@@ -28,21 +28,9 @@
"static/runtime/webpack.js",
"static/runtime/main.js"
],
- "/suzuki/latest_news/latestnews_details": [
- "static/runtime/webpack.js",
- "static/runtime/main.js"
- ],
- "/suzuki/product/product": [
- "static/runtime/webpack.js",
- "static/runtime/main.js"
- ],
"/suzuki/product/product_detail": [
"static/runtime/webpack.js",
"static/runtime/main.js"
- ],
- "/yamaha/latest_news/latestnews": [
- "static/runtime/webpack.js",
- "static/runtime/main.js"
]
}
}
\ No newline at end of file
diff --git a/.next/server/pages-manifest.json b/.next/server/pages-manifest.json
index 90f81a8..212df0c 100644
--- a/.next/server/pages-manifest.json
+++ b/.next/server/pages-manifest.json
@@ -1 +1 @@
-{"/_app":"static/development/pages/_app.js","/_document":"static/development/pages/_document.js","/_error":"static/development/pages/_error.js","/suzuki/home":"static/development/pages/suzuki/home.js","/suzuki/latest_news/latestnews_details":"static/development/pages/suzuki/latest_news/latestnews_details.js","/suzuki/product/product":"static/development/pages/suzuki/product/product.js","/suzuki/product/product_detail":"static/development/pages/suzuki/product/product_detail.js","/yamaha/latest_news/latestnews":"static/development/pages/yamaha/latest_news/latestnews.js"}
\ No newline at end of file
+{"/_app":"static/development/pages/_app.js","/_document":"static/development/pages/_document.js","/_error":"static/development/pages/_error.js","/suzuki/home":"static/development/pages/suzuki/home.js","/suzuki/product/product_detail":"static/development/pages/suzuki/product/product_detail.js"}
\ No newline at end of file
diff --git a/api/auth/auth.js b/api/auth/auth.js
new file mode 100644
index 0000000..6da9ba2
--- /dev/null
+++ b/api/auth/auth.js
@@ -0,0 +1,147 @@
+import apollo from "../../lib/apollo.js";
+import partners from "../partner/partner";
+
+async function register(username, email, password, token = "") {
+ var res = await apollo.mutation(
+ `
+ mutation($username: String! $email: String! $password: String!) {
+ register(input: { username: $username, email: $email, password: $password }) {
+ jwt
+ user {
+ username
+ email
+ }
+ }
+ }`,
+ token,
+ {
+ username: username,
+ email: email,
+ password: password,
+ }
+ );
+ return res;
+}
+
+async function login(partner, email, password, token = "") {
+ var cookiesData = {};
+ var res = await apollo.mutation(
+ `
+ mutation($email: String! $password: String!) {
+ login(input: { identifier: $email, password: $password }) {
+ user{
+ id
+ username
+ }
+ jwt
+ }
+ }`,
+ token,
+ {
+ email: email,
+ password: password,
+ }
+ );
+
+ if (res["STATUS"] == 1) {
+ token = res["DATA"]["login"]["jwt"];
+ res = await apollo.mutation(
+ `
+ query{
+ self{
+ id
+ username
+ email
+ role{
+ name
+ description
+ }
+ partners_login_states{
+ id
+ business_partner{
+ id
+ name
+ }
+ }
+ }
+ }
+ `,
+ token
+ );
+ }
+
+ if (res["STATUS"] == 1) {
+ var user = res["DATA"]["self"];
+ var sessions = [];
+ for (const i of user["partners_login_states"]) {
+ sessions.push(i.business_partner);
+ }
+ sessions = sessions.filter(
+ (i) =>
+ i.business_partner &&
+ i.business_partner.name.toUpperCase() == partner.toUpperCase()
+ );
+ if (sessions.length == 0) {
+ res = await partners.getID(partner, token);
+ if (res["STATUS"] == 1) {
+ res = await apollo.mutation(
+ `
+ mutation($input: PartnersLoginStateInput!) {
+ createPartnersLoginState(input:{data:$input}){
+ partnersLoginState{
+ id
+ business_partner{
+ id
+ name
+ }
+ }
+ }
+ }
+ `,
+ token,
+ {
+ input: {
+ user: user["id"],
+ business_partner:
+ res["DATA"]["businessPartners"][0]["id"],
+ },
+ }
+ );
+ if (res["STATUS"] == 1) {
+ user["partners_login_states"].push(
+ res["DATA"]["createPartnersLoginState"][
+ "partnersLoginState"
+ ]
+ );
+ }
+ }
+ }
+ cookiesData["user"] = user;
+ cookiesData["token"] = token;
+ }
+ return { res: res, cookies: cookiesData };
+}
+
+async function logout(id, token = "") {
+ var res = await apollo.mutation(
+ `
+ mutation($input: ID!) {
+ deletePartnersLoginState(input:{where:{id:$input}}){
+ partnersLoginState{
+ id
+ }
+ }
+ }`,
+ token,
+ {
+ input: id,
+ }
+ );
+ return res;
+}
+
+module.exports = {
+ register: register,
+ login: login,
+ logout: logout,
+};
diff --git a/api/partner/partner.js b/api/partner/partner.js
new file mode 100644
index 0000000..02ff1e5
--- /dev/null
+++ b/api/partner/partner.js
@@ -0,0 +1,21 @@
+import apollo from "../../lib/apollo.js";
+
+async function getID(partner, token = "") {
+ var res = await apollo.query(
+ `
+ query($input : String!){
+ businessPartners(where:{name_contains:$input}){
+ id
+ }
+ }`,
+ token,
+ {
+ input: partner,
+ }
+ );
+ return res;
+}
+
+module.exports = {
+ getID: getID,
+};
diff --git a/assets/jss/nextjs-material-kit/pages/loginPage.js b/assets/jss/nextjs-material-kit/pages/loginPage.js
index 4142c53..1aa7cac 100644
--- a/assets/jss/nextjs-material-kit/pages/loginPage.js
+++ b/assets/jss/nextjs-material-kit/pages/loginPage.js
@@ -7,11 +7,11 @@ const signupPageStyle = {
position: "relative",
paddingTop: "20vh",
color: "#FFFFFF",
- paddingBottom: "200px"
+ paddingBottom: "200px",
},
cardHidden: {
opacity: "0",
- transform: "translate3d(0, -60px, 0)"
+ transform: "translate3d(0, -60px, 0)",
},
pageHeader: {
minHeight: "100vh",
@@ -23,7 +23,7 @@ const signupPageStyle = {
border: "0",
alignItems: "center",
"&:before": {
- background: "rgba(0, 0, 0, 0.5)"
+ background: "rgba(0, 0, 0, 0.5)",
},
"&:before,&:after": {
position: "absolute",
@@ -33,19 +33,26 @@ const signupPageStyle = {
display: "block",
left: "0",
top: "0",
- content: '""'
+ content: '""',
},
"& footer li a,& footer li a:hover,& footer li a:active": {
- color: "#FFFFFF"
+ color: "#FFFFFF",
},
"& footer": {
position: "absolute",
bottom: "0",
- width: "100%"
- }
+ width: "100%",
+ },
+ },
+ collapsible: {
+ position: "fixed",
+ bottom: "5px",
+ left: "2%",
+ width: "96%",
+ zIndex: "9999",
},
form: {
- margin: "0"
+ margin: "0",
},
cardHeader: {
width: "auto",
@@ -54,7 +61,7 @@ const signupPageStyle = {
marginRight: "20px",
marginTop: "-40px",
padding: "20px 0",
- marginBottom: "15px"
+ marginBottom: "15px",
},
socialIcons: {
maxWidth: "24px",
@@ -65,27 +72,27 @@ const signupPageStyle = {
top: "0",
height: "100%",
lineHeight: "41px",
- fontSize: "20px"
+ fontSize: "20px",
},
divider: {
marginTop: "30px",
marginBottom: "0px",
- textAlign: "center"
+ textAlign: "center",
},
cardFooter: {
paddingTop: "0rem",
border: "0",
borderRadius: "6px",
- justifyContent: "center !important"
+ justifyContent: "center !important",
},
socialLine: {
marginTop: "1rem",
textAlign: "center",
- padding: "0"
+ padding: "0",
},
inputIconsColor: {
- color: "info"
- }
+ color: "info",
+ },
};
export default signupPageStyle;
diff --git a/lib/apollo.js b/lib/apollo.js
index 4e0bd8c..6f15f3e 100644
--- a/lib/apollo.js
+++ b/lib/apollo.js
@@ -8,6 +8,16 @@ import {
import ApolloConfig from "../config/apollo-config";
import fetch from "cross-fetch";
+function errorHandler(object) {
+ return object.graphQLErrors.length != 0
+ ? object.graphQLErrors[0].message
+ : object.networkError && object.networkError.result
+ ? object.networkError.result.errors.join(" ; ")
+ : object.networkError
+ ? object.networkError[Object.keys(object.networkError)[0]].toString()
+ : "Fetch failed";
+}
+
function initApollo(token) {
const httpLink = createHttpLink({
uri: ApolloConfig.graphql_uri,
@@ -41,7 +51,7 @@ async function query(query, token = "", variables = {}, cache = false) {
});
res = { STATUS: 1, DATA: sql.data };
} catch (e) {
- res = { STATUS: 0, DATA: e };
+ res = { STATUS: 0, DATA: errorHandler(e) };
}
return res;
}
@@ -58,7 +68,7 @@ async function mutation(mutation, token = "", variables = {}) {
});
res = { STATUS: 1, DATA: sql.data };
} catch (e) {
- res = { STATUS: 0, DATA: e };
+ res = { STATUS: 0, DATA: errorHandler(e) };
}
return res;
}
diff --git a/package.json b/package.json
index 0836b16..683b0fe 100644
--- a/package.json
+++ b/package.json
@@ -37,10 +37,12 @@
"@material-ui/core": "^4.11.3",
"@material-ui/data-grid": "^4.0.0-alpha.23",
"@material-ui/icons": "4.9.1",
+ "@material-ui/lab": "^4.0.0-alpha.57",
"@zeit/next-css": "^1.0.1",
"@zeit/next-less": "^1.0.1",
"@zeit/next-sass": "1.0.1",
"classnames": "2.2.6",
+ "cookies": "^0.8.0",
"cross-fetch": "^3.0.6",
"graphql": "^15.3.0",
"less": "^4.1.1",
@@ -68,4 +70,4 @@
"styled-components": "5.1.0",
"webpack": "4.43.0"
}
-}
+}
\ No newline at end of file
diff --git a/pages/api/auth/login.js b/pages/api/auth/login.js
new file mode 100644
index 0000000..78164f4
--- /dev/null
+++ b/pages/api/auth/login.js
@@ -0,0 +1,41 @@
+import auth from "../../../api/auth/auth";
+import Cookies from "cookies";
+
+export default async function handler(req, res) {
+ if (req.method == "POST") {
+ const cookies = new Cookies(req, res);
+ var email = req.body.email;
+ var pass = req.body.pass;
+ var partner = req.body.partner;
+ var resp = await auth.login(partner, email, pass);
+ var login = resp["res"];
+ // console.log(login["DATA"]);
+ if (login["STATUS"] == 0) {
+ return res
+ .status(400)
+ .send(login["DATA"] + ". Check user and password again.");
+ }
+ var userObj = resp["cookies"]["user"];
+ await cookies.set("myToken", resp["cookies"]["token"], {
+ httpOnly: true, // true by default
+ });
+ await cookies.set("user", JSON.stringify(userObj), {
+ httpOnly: true, // true by default
+ });
+ let sessionId = userObj["partners_login_states"].filter(
+ (i) =>
+ i.business_partner &&
+ i.business_partner.name.toUpperCase() == partner.toUpperCase()
+ );
+ if (sessionId.length == 0) return res.status(400).send("Login Failed");
+ return res.status(200).send("Success Login");
+ // res.status(200).json(login);
+ // res.writeHead(200, {
+ // Location: "../home",
+ // //add other headers here...
+ // });
+ // res.end();
+ } else {
+ return res.status(400).send("NOT FOUND");
+ }
+}
diff --git a/pages/api/auth/logout.js b/pages/api/auth/logout.js
new file mode 100644
index 0000000..f77f97d
--- /dev/null
+++ b/pages/api/auth/logout.js
@@ -0,0 +1,37 @@
+import auth from "../../../api/auth/auth";
+import Cookies from "cookies";
+
+export default async function handler(req, res) {
+ if (req.method == "POST") {
+ const cookies = new Cookies(req, res);
+ const partner = req.body.p;
+ var user = await cookies.get("user");
+ var token = await cookies.get("myToken");
+ var userObj = user ? JSON.parse(user) : null;
+ // console.log("user", userObj);
+ let sessionId = userObj["partners_login_states"].filter(
+ (i) =>
+ i.business_partner &&
+ i.business_partner.name.toUpperCase() == partner.toUpperCase()
+ );
+ sessionId.forEach(async (i) => {
+ var resp = await auth.logout(i.id, token);
+ if (resp["STATUS"] == 0) {
+ return res.status(400).send(resp["DATA"]);
+ }
+ });
+ userObj["partners_login_states"] = userObj[
+ "partners_login_states"
+ ].filter(
+ (i) =>
+ i.business_partner &&
+ i.business_partner.name.toUpperCase() != partner.toUpperCase()
+ );
+ await cookies.set("user", JSON.stringify(userObj), {
+ httpOnly: true, // true by default
+ });
+ return res.status(200).send("Success Logout");
+ } else {
+ return res.status(400).send("NOT FOUND");
+ }
+}
diff --git a/pages/api/product/get.js b/pages/api/product/get.js
deleted file mode 100644
index 26306a7..0000000
--- a/pages/api/product/get.js
+++ /dev/null
@@ -1,27 +0,0 @@
-import DetailProduct from "../../../api/product/product";
-
-export default async function handler(req, res) {
- console.log("masuk");
- if (req.method == "POST") {
- var id = req.body.id;
- var detailproduct = await DetailProduct.GetDetailProduct(id);
- if (detailproduct["STATUS"] == 0) {
- res.status(200).json(detailproduct);
- } else if (detailproduct["DATA"]["products"] == null) {
- res
- .status(200)
- .json({
- STATUS: 0,
- DATA: "Product Tidak Ditemukan"
- });
- } else {
- res.status(200).json({
- STATUS: 1,
- DATA: detailproduct["DATA"]["products"],
- });
- }
- } else {
- console.log("masukas");
- res.status(200).send("NOT FOUND");
- }
-}
\ No newline at end of file
diff --git a/pages/suzuki/home.js b/pages/suzuki/home.js
index 811f925..3069f7d 100644
--- a/pages/suzuki/home.js
+++ b/pages/suzuki/home.js
@@ -8,9 +8,9 @@ import Parallax from "components/Parallax/Parallax.js";
import styles from "assets/jss/nextjs-material-kit/pages/components.js";
import FooterSuzuki from "components/Footer/FooterSuzuki.js";
-import Getservices from "../../api/home/service.js";
-import Getcarousels from "../../api/home/carousel.js";
-
+import GetbusinessPartners from "../../api/suzuki/home/businessPartner.js";
+import Getservices from "../../api/suzuki/home/service.js";
+import Getcarousels from "../../api/suzuki/home/carousel.js";
import DataSnackbarContent from "../../pages-sections/suzuki/snackbar.js";
import DataCarousel from "../../pages-sections/suzuki/home/carousel.js";
import DataService from "../../pages-sections/suzuki/home/service.js";
@@ -18,10 +18,12 @@ import DataBusinessPartner from "../../pages-sections/suzuki/home/business_partn
import DataSosmed from "../../pages-sections/suzuki/home/sosmed.js";
import CoreValue from "../../pages-sections/suzuki/home/core_value.js";
import DataFeature from "../../pages-sections/suzuki/home/feature.js";
+import Cookies from "cookies";
const useStyles = makeStyles(styles);
const Home = function ({
backend,
+ businessPartners,
service,
carousels,
...props
@@ -29,11 +31,10 @@ const Home = function ({
const classes = useStyles();
const { ...rest } = props;