Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e625ed9633 | ||
![]() |
a042c202a0 | ||
![]() |
7a76b783b1 | ||
![]() |
e5400bc7bd | ||
![]() |
a8503666e3 | ||
![]() |
b028be3cbc | ||
![]() |
9a8d20b698 | ||
![]() |
fab3c2f87e | ||
![]() |
3fefcfcd9a | ||
![]() |
c2defdbaac | ||
![]() |
15a4be5431 | ||
![]() |
146561bacb | ||
![]() |
0c334856bc | ||
![]() |
ba0cf189de | ||
![]() |
9f52c08883 | ||
![]() |
80f3698f06 | ||
![]() |
2a2b7abc08 | ||
![]() |
27e3ed82e4 | ||
![]() |
6077702626 | ||
![]() |
cf54fcef03 | ||
![]() |
2f849b8f0c | ||
![]() |
85ca0f09bf | ||
![]() |
2fc438d810 | ||
![]() |
1796cace15 | ||
![]() |
43fdc826c4 | ||
![]() |
e7652db89c | ||
![]() |
5018462559 |
58
app/package-lock.json
generated
58
app/package-lock.json
generated
@@ -9,7 +9,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@authorizerdev/authorizer-react": "^1.1.11",
|
"@authorizerdev/authorizer-react": "^1.1.13",
|
||||||
"@types/react": "^17.0.15",
|
"@types/react": "^17.0.15",
|
||||||
"@types/react-dom": "^17.0.9",
|
"@types/react-dom": "^17.0.9",
|
||||||
"esbuild": "^0.12.17",
|
"esbuild": "^0.12.17",
|
||||||
@@ -27,9 +27,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@authorizerdev/authorizer-js": {
|
"node_modules/@authorizerdev/authorizer-js": {
|
||||||
"version": "1.2.3",
|
"version": "1.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-js/-/authorizer-js-1.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-js/-/authorizer-js-1.2.6.tgz",
|
||||||
"integrity": "sha512-rk/fMRIsqbp+fsy2y09etVjf7CY9/4mG6hf0RKgXgRRfxtAQa1jdkt/De23hBTNeEwAWu6hP/9BQZjcrln6KtA==",
|
"integrity": "sha512-9+9phHUMF+AeDM0y+XQvIRDoerOXnQ1vfTfYN6KxWN1apdrkAd9nzS1zUsA2uJSnX3fFZOErn83GjbYYCYF1BA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cross-fetch": "^3.1.5"
|
"cross-fetch": "^3.1.5"
|
||||||
},
|
},
|
||||||
@@ -41,11 +41,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@authorizerdev/authorizer-react": {
|
"node_modules/@authorizerdev/authorizer-react": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.13",
|
||||||
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-1.1.13.tgz",
|
||||||
"integrity": "sha512-tSI/yjsoeK/RvCOMiHSf1QGOeSpaLYQZEM864LFLndKoJwk7UWCJ86qg1w6ge7B00PmZSNWqST/w5JTcQaVNpw==",
|
"integrity": "sha512-LmpzyfR0+nEn+bjUrb/QU9b3kiVoYzMBIvcQ1nV4TNvrvVSqbLPKk+GmoIPkiBEtfy/QSM6XFLkiGNGD9BRP+g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@authorizerdev/authorizer-js": "^1.2.3"
|
"@authorizerdev/authorizer-js": "^1.2.6"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
@@ -406,11 +406,11 @@
|
|||||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
||||||
},
|
},
|
||||||
"node_modules/cross-fetch": {
|
"node_modules/cross-fetch": {
|
||||||
"version": "3.1.5",
|
"version": "3.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz",
|
||||||
"integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==",
|
"integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-fetch": "2.6.7"
|
"node-fetch": "^2.6.12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/css-color-keywords": {
|
"node_modules/css-color-keywords": {
|
||||||
@@ -567,9 +567,9 @@
|
|||||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
},
|
},
|
||||||
"node_modules/node-fetch": {
|
"node_modules/node-fetch": {
|
||||||
"version": "2.6.7",
|
"version": "2.6.12",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
||||||
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
|
"integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"whatwg-url": "^5.0.0"
|
"whatwg-url": "^5.0.0"
|
||||||
},
|
},
|
||||||
@@ -837,19 +837,19 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@authorizerdev/authorizer-js": {
|
"@authorizerdev/authorizer-js": {
|
||||||
"version": "1.2.3",
|
"version": "1.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-js/-/authorizer-js-1.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-js/-/authorizer-js-1.2.6.tgz",
|
||||||
"integrity": "sha512-rk/fMRIsqbp+fsy2y09etVjf7CY9/4mG6hf0RKgXgRRfxtAQa1jdkt/De23hBTNeEwAWu6hP/9BQZjcrln6KtA==",
|
"integrity": "sha512-9+9phHUMF+AeDM0y+XQvIRDoerOXnQ1vfTfYN6KxWN1apdrkAd9nzS1zUsA2uJSnX3fFZOErn83GjbYYCYF1BA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"cross-fetch": "^3.1.5"
|
"cross-fetch": "^3.1.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@authorizerdev/authorizer-react": {
|
"@authorizerdev/authorizer-react": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.13",
|
||||||
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-1.1.13.tgz",
|
||||||
"integrity": "sha512-tSI/yjsoeK/RvCOMiHSf1QGOeSpaLYQZEM864LFLndKoJwk7UWCJ86qg1w6ge7B00PmZSNWqST/w5JTcQaVNpw==",
|
"integrity": "sha512-LmpzyfR0+nEn+bjUrb/QU9b3kiVoYzMBIvcQ1nV4TNvrvVSqbLPKk+GmoIPkiBEtfy/QSM6XFLkiGNGD9BRP+g==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@authorizerdev/authorizer-js": "^1.2.3"
|
"@authorizerdev/authorizer-js": "^1.2.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@babel/code-frame": {
|
"@babel/code-frame": {
|
||||||
@@ -1144,11 +1144,11 @@
|
|||||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
||||||
},
|
},
|
||||||
"cross-fetch": {
|
"cross-fetch": {
|
||||||
"version": "3.1.5",
|
"version": "3.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz",
|
||||||
"integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==",
|
"integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"node-fetch": "2.6.7"
|
"node-fetch": "^2.6.12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"css-color-keywords": {
|
"css-color-keywords": {
|
||||||
@@ -1270,9 +1270,9 @@
|
|||||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||||
},
|
},
|
||||||
"node-fetch": {
|
"node-fetch": {
|
||||||
"version": "2.6.7",
|
"version": "2.6.12",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
||||||
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
|
"integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"whatwg-url": "^5.0.0"
|
"whatwg-url": "^5.0.0"
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
"author": "Lakhan Samani",
|
"author": "Lakhan Samani",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@authorizerdev/authorizer-react": "^1.1.11",
|
"@authorizerdev/authorizer-react": "^1.1.13",
|
||||||
"@types/react": "^17.0.15",
|
"@types/react": "^17.0.15",
|
||||||
"@types/react-dom": "^17.0.9",
|
"@types/react-dom": "^17.0.9",
|
||||||
"esbuild": "^0.12.17",
|
"esbuild": "^0.12.17",
|
||||||
|
@@ -2,19 +2,19 @@
|
|||||||
# yarn lockfile v1
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
"@authorizerdev/authorizer-js@^1.2.3":
|
"@authorizerdev/authorizer-js@^1.2.6":
|
||||||
"integrity" "sha512-rk/fMRIsqbp+fsy2y09etVjf7CY9/4mG6hf0RKgXgRRfxtAQa1jdkt/De23hBTNeEwAWu6hP/9BQZjcrln6KtA=="
|
"integrity" "sha512-9+9phHUMF+AeDM0y+XQvIRDoerOXnQ1vfTfYN6KxWN1apdrkAd9nzS1zUsA2uJSnX3fFZOErn83GjbYYCYF1BA=="
|
||||||
"resolved" "https://registry.npmjs.org/@authorizerdev/authorizer-js/-/authorizer-js-1.2.3.tgz"
|
"resolved" "https://registry.npmjs.org/@authorizerdev/authorizer-js/-/authorizer-js-1.2.6.tgz"
|
||||||
"version" "1.2.3"
|
"version" "1.2.6"
|
||||||
dependencies:
|
dependencies:
|
||||||
"cross-fetch" "^3.1.5"
|
"cross-fetch" "^3.1.5"
|
||||||
|
|
||||||
"@authorizerdev/authorizer-react@^1.1.11":
|
"@authorizerdev/authorizer-react@^1.1.13":
|
||||||
"integrity" "sha512-tSI/yjsoeK/RvCOMiHSf1QGOeSpaLYQZEM864LFLndKoJwk7UWCJ86qg1w6ge7B00PmZSNWqST/w5JTcQaVNpw=="
|
"integrity" "sha512-LmpzyfR0+nEn+bjUrb/QU9b3kiVoYzMBIvcQ1nV4TNvrvVSqbLPKk+GmoIPkiBEtfy/QSM6XFLkiGNGD9BRP+g=="
|
||||||
"resolved" "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-1.1.11.tgz"
|
"resolved" "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-1.1.13.tgz"
|
||||||
"version" "1.1.11"
|
"version" "1.1.13"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@authorizerdev/authorizer-js" "^1.2.3"
|
"@authorizerdev/authorizer-js" "^1.2.6"
|
||||||
|
|
||||||
"@babel/code-frame@^7.16.7":
|
"@babel/code-frame@^7.16.7":
|
||||||
"integrity" "sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg=="
|
"integrity" "sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg=="
|
||||||
@@ -278,11 +278,11 @@
|
|||||||
"version" "1.1.3"
|
"version" "1.1.3"
|
||||||
|
|
||||||
"cross-fetch@^3.1.5":
|
"cross-fetch@^3.1.5":
|
||||||
"integrity" "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw=="
|
"integrity" "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg=="
|
||||||
"resolved" "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz"
|
"resolved" "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz"
|
||||||
"version" "3.1.5"
|
"version" "3.1.8"
|
||||||
dependencies:
|
dependencies:
|
||||||
"node-fetch" "2.6.7"
|
"node-fetch" "^2.6.12"
|
||||||
|
|
||||||
"css-color-keywords@^1.0.0":
|
"css-color-keywords@^1.0.0":
|
||||||
"integrity" "sha1-/qJhbcZ2spYmhrOvjb2+GAskTgU="
|
"integrity" "sha1-/qJhbcZ2spYmhrOvjb2+GAskTgU="
|
||||||
@@ -389,10 +389,10 @@
|
|||||||
"resolved" "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz"
|
"resolved" "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz"
|
||||||
"version" "2.1.2"
|
"version" "2.1.2"
|
||||||
|
|
||||||
"node-fetch@2.6.7":
|
"node-fetch@^2.6.12":
|
||||||
"integrity" "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ=="
|
"integrity" "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g=="
|
||||||
"resolved" "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz"
|
"resolved" "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz"
|
||||||
"version" "2.6.7"
|
"version" "2.6.12"
|
||||||
dependencies:
|
dependencies:
|
||||||
"whatwg-url" "^5.0.0"
|
"whatwg-url" "^5.0.0"
|
||||||
|
|
||||||
|
@@ -118,7 +118,6 @@ const Webhooks = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchWebookData();
|
fetchWebookData();
|
||||||
}, [paginationProps.page, paginationProps.limit]);
|
}, [paginationProps.page, paginationProps.limit]);
|
||||||
console.log({ webhookData });
|
|
||||||
return (
|
return (
|
||||||
<Box m="5" py="5" px="10" bg="white" rounded="md">
|
<Box m="5" py="5" px="10" bg="white" rounded="md">
|
||||||
<Flex margin="2% 0" justifyContent="space-between" alignItems="center">
|
<Flex margin="2% 0" justifyContent="space-between" alignItems="center">
|
||||||
|
@@ -1222,9 +1222,9 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"is-arrayish" "^0.2.1"
|
"is-arrayish" "^0.2.1"
|
||||||
|
|
||||||
"esbuild-linux-64@0.14.9":
|
"esbuild-darwin-arm64@0.14.9":
|
||||||
"integrity" "sha512-WoEI+R6/PLZAxS7XagfQMFgRtLUi5cjqqU9VCfo3tnWmAXh/wt8QtUfCVVCcXVwZLS/RNvI19CtfjlrJU61nOg=="
|
"integrity" "sha512-3ue+1T4FR5TaAu4/V1eFMG8Uwn0pgAwQZb/WwL1X78d5Cy8wOVQ67KNH1lsjU+y/9AcwMKZ9x0GGNxBB4a1Rbw=="
|
||||||
"resolved" "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.9.tgz"
|
"resolved" "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.9.tgz"
|
||||||
"version" "0.14.9"
|
"version" "0.14.9"
|
||||||
|
|
||||||
"esbuild@^0.14.9":
|
"esbuild@^0.14.9":
|
||||||
|
@@ -5,4 +5,6 @@ const (
|
|||||||
AppCookieName = "cookie"
|
AppCookieName = "cookie"
|
||||||
// AdminCookieName is the name of the cookie that is used to store the admin token
|
// AdminCookieName is the name of the cookie that is used to store the admin token
|
||||||
AdminCookieName = "authorizer-admin"
|
AdminCookieName = "authorizer-admin"
|
||||||
|
// MfaCookieName is the name of the cookie that is used to store the mfa session
|
||||||
|
MfaCookieName = "mfa"
|
||||||
)
|
)
|
||||||
|
89
server/cookie/mfa_session.go
Normal file
89
server/cookie/mfa_session.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package cookie
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
|
"github.com/authorizerdev/authorizer/server/memorystore"
|
||||||
|
"github.com/authorizerdev/authorizer/server/parsers"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetMfaSession sets the mfa session cookie in the response
|
||||||
|
func SetMfaSession(gc *gin.Context, sessionID string) {
|
||||||
|
appCookieSecure, err := memorystore.Provider.GetBoolStoreEnvVariable(constants.EnvKeyAppCookieSecure)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug("Error while getting app cookie secure from env variable: %v", err)
|
||||||
|
appCookieSecure = true
|
||||||
|
}
|
||||||
|
|
||||||
|
secure := appCookieSecure
|
||||||
|
httpOnly := appCookieSecure
|
||||||
|
hostname := parsers.GetHost(gc)
|
||||||
|
host, _ := parsers.GetHostParts(hostname)
|
||||||
|
domain := parsers.GetDomainName(hostname)
|
||||||
|
if domain != "localhost" {
|
||||||
|
domain = "." + domain
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since app cookie can come from cross site it becomes important to set this in lax mode when insecure.
|
||||||
|
// Example person using custom UI on their app domain and making request to authorizer domain.
|
||||||
|
// For more information check:
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
|
||||||
|
// https://github.com/gin-gonic/gin/blob/master/context.go#L86
|
||||||
|
// TODO add ability to sameSite = none / strict from dashboard
|
||||||
|
if !appCookieSecure {
|
||||||
|
gc.SetSameSite(http.SameSiteLaxMode)
|
||||||
|
} else {
|
||||||
|
gc.SetSameSite(http.SameSiteNoneMode)
|
||||||
|
}
|
||||||
|
// TODO allow configuring from dashboard
|
||||||
|
age := 60
|
||||||
|
|
||||||
|
gc.SetCookie(constants.MfaCookieName+"_session", sessionID, age, "/", host, secure, httpOnly)
|
||||||
|
gc.SetCookie(constants.MfaCookieName+"_session_domain", sessionID, age, "/", domain, secure, httpOnly)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteMfaSession deletes the mfa session cookies to expire
|
||||||
|
func DeleteMfaSession(gc *gin.Context) {
|
||||||
|
appCookieSecure, err := memorystore.Provider.GetBoolStoreEnvVariable(constants.EnvKeyAppCookieSecure)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug("Error while getting app cookie secure from env variable: %v", err)
|
||||||
|
appCookieSecure = true
|
||||||
|
}
|
||||||
|
|
||||||
|
secure := appCookieSecure
|
||||||
|
httpOnly := appCookieSecure
|
||||||
|
hostname := parsers.GetHost(gc)
|
||||||
|
host, _ := parsers.GetHostParts(hostname)
|
||||||
|
domain := parsers.GetDomainName(hostname)
|
||||||
|
if domain != "localhost" {
|
||||||
|
domain = "." + domain
|
||||||
|
}
|
||||||
|
|
||||||
|
gc.SetSameSite(http.SameSiteNoneMode)
|
||||||
|
gc.SetCookie(constants.MfaCookieName+"_session", "", -1, "/", host, secure, httpOnly)
|
||||||
|
gc.SetCookie(constants.MfaCookieName+"_session_domain", "", -1, "/", domain, secure, httpOnly)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMfaSession gets the mfa session cookie from context
|
||||||
|
func GetMfaSession(gc *gin.Context) (string, error) {
|
||||||
|
var cookie *http.Cookie
|
||||||
|
var err error
|
||||||
|
cookie, err = gc.Request.Cookie(constants.MfaCookieName + "_session")
|
||||||
|
if err != nil {
|
||||||
|
cookie, err = gc.Request.Cookie(constants.MfaCookieName + "_session_domain")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
decodedValue, err := url.PathUnescape(cookie.Value)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return decodedValue, nil
|
||||||
|
}
|
@@ -12,16 +12,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEmailTemplate to add EmailTemplate
|
// AddEmailTemplate to add EmailTemplate
|
||||||
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
if emailTemplate.ID == "" {
|
if emailTemplate.ID == "" {
|
||||||
emailTemplate.ID = uuid.New().String()
|
emailTemplate.ID = uuid.New().String()
|
||||||
emailTemplate.Key = emailTemplate.ID
|
emailTemplate.Key = emailTemplate.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
emailTemplate.Key = emailTemplate.ID
|
emailTemplate.Key = emailTemplate.ID
|
||||||
emailTemplate.CreatedAt = time.Now().Unix()
|
emailTemplate.CreatedAt = time.Now().Unix()
|
||||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
emailTemplateCollection, _ := p.db.Collection(ctx, models.Collections.EmailTemplate)
|
emailTemplateCollection, _ := p.db.Collection(ctx, models.Collections.EmailTemplate)
|
||||||
_, err := emailTemplateCollection.CreateDocument(ctx, emailTemplate)
|
_, err := emailTemplateCollection.CreateDocument(ctx, emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -31,74 +29,63 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.Em
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEmailTemplate to update EmailTemplate
|
// UpdateEmailTemplate to update EmailTemplate
|
||||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
emailTemplateCollection, _ := p.db.Collection(ctx, models.Collections.EmailTemplate)
|
emailTemplateCollection, _ := p.db.Collection(ctx, models.Collections.EmailTemplate)
|
||||||
meta, err := emailTemplateCollection.UpdateDocument(ctx, emailTemplate.Key, emailTemplate)
|
meta, err := emailTemplateCollection.UpdateDocument(ctx, emailTemplate.Key, emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
emailTemplate.Key = meta.Key
|
emailTemplate.Key = meta.Key
|
||||||
emailTemplate.ID = meta.ID.String()
|
emailTemplate.ID = meta.ID.String()
|
||||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListEmailTemplates to list EmailTemplate
|
// ListEmailTemplates to list EmailTemplate
|
||||||
func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagination) (*model.EmailTemplates, error) {
|
func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagination) (*model.EmailTemplates, error) {
|
||||||
emailTemplates := []*model.EmailTemplate{}
|
emailTemplates := []*model.EmailTemplate{}
|
||||||
|
|
||||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.EmailTemplate, pagination.Offset, pagination.Limit)
|
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.EmailTemplate, pagination.Offset, pagination.Limit)
|
||||||
|
|
||||||
sctx := arangoDriver.WithQueryFullCount(ctx)
|
sctx := arangoDriver.WithQueryFullCount(ctx)
|
||||||
cursor, err := p.db.Query(sctx, query, nil)
|
cursor, err := p.db.Query(sctx, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
paginationClone.Total = cursor.Statistics().FullCount()
|
paginationClone.Total = cursor.Statistics().FullCount()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
meta, err := cursor.ReadDocument(ctx, &emailTemplate)
|
meta, err := cursor.ReadDocument(ctx, &emailTemplate)
|
||||||
|
|
||||||
if arangoDriver.IsNoMoreDocuments(err) {
|
if arangoDriver.IsNoMoreDocuments(err) {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.Key != "" {
|
if meta.Key != "" {
|
||||||
emailTemplates = append(emailTemplates, emailTemplate.AsAPIEmailTemplate())
|
emailTemplates = append(emailTemplates, emailTemplate.AsAPIEmailTemplate())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.EmailTemplates{
|
return &model.EmailTemplates{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
EmailTemplates: emailTemplates,
|
EmailTemplates: emailTemplates,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEmailTemplateByID to get EmailTemplate by id
|
// GetEmailTemplateByID to get EmailTemplate by id
|
||||||
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d._key == @email_template_id RETURN d", models.Collections.EmailTemplate)
|
query := fmt.Sprintf("FOR d in %s FILTER d._key == @email_template_id RETURN d", models.Collections.EmailTemplate)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"email_template_id": emailTemplateID,
|
"email_template_id": emailTemplateID,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if emailTemplate.Key == "" {
|
if emailTemplate == nil {
|
||||||
return nil, fmt.Errorf("email template not found")
|
return nil, fmt.Errorf("email template not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -113,21 +100,19 @@ func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID str
|
|||||||
|
|
||||||
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
||||||
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.event_name == @event_name RETURN d", models.Collections.EmailTemplate)
|
query := fmt.Sprintf("FOR d in %s FILTER d.event_name == @event_name RETURN d", models.Collections.EmailTemplate)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"event_name": eventName,
|
"event_name": eventName,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if emailTemplate.Key == "" {
|
if emailTemplate == nil {
|
||||||
return nil, fmt.Errorf("email template not found")
|
return nil, fmt.Errorf("email template not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEnv to save environment information in database
|
// AddEnv to save environment information in database
|
||||||
func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
if env.ID == "" {
|
if env.ID == "" {
|
||||||
env.ID = uuid.New().String()
|
env.ID = uuid.New().String()
|
||||||
env.Key = env.ID
|
env.Key = env.ID
|
||||||
@@ -31,7 +31,7 @@ func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEnv to update environment information in database
|
// UpdateEnv to update environment information in database
|
||||||
func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
collection, _ := p.db.Collection(ctx, models.Collections.Env)
|
collection, _ := p.db.Collection(ctx, models.Collections.Env)
|
||||||
meta, err := collection.UpdateDocument(ctx, env.Key, env)
|
meta, err := collection.UpdateDocument(ctx, env.Key, env)
|
||||||
@@ -45,19 +45,17 @@ func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEnv to get environment information from database
|
// GetEnv to get environment information from database
|
||||||
func (p *provider) GetEnv(ctx context.Context) (models.Env, error) {
|
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||||
var env models.Env
|
var env *models.Env
|
||||||
query := fmt.Sprintf("FOR d in %s RETURN d", models.Collections.Env)
|
query := fmt.Sprintf("FOR d in %s RETURN d", models.Collections.Env)
|
||||||
|
|
||||||
cursor, err := p.db.Query(ctx, query, nil)
|
cursor, err := p.db.Query(ctx, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return env, err
|
return env, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if env.Key == "" {
|
if env == nil {
|
||||||
return env, fmt.Errorf("config not found")
|
return env, fmt.Errorf("config not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@@ -44,10 +44,8 @@ func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models
|
|||||||
otp.Otp = otpParam.Otp
|
otp.Otp = otpParam.Otp
|
||||||
otp.ExpiresAt = otpParam.ExpiresAt
|
otp.ExpiresAt = otpParam.ExpiresAt
|
||||||
}
|
}
|
||||||
|
|
||||||
otp.UpdatedAt = time.Now().Unix()
|
otp.UpdatedAt = time.Now().Unix()
|
||||||
otpCollection, _ := p.db.Collection(ctx, models.Collections.OTP)
|
otpCollection, _ := p.db.Collection(ctx, models.Collections.OTP)
|
||||||
|
|
||||||
var meta driver.DocumentMeta
|
var meta driver.DocumentMeta
|
||||||
var err error
|
var err error
|
||||||
if shouldCreate {
|
if shouldCreate {
|
||||||
@@ -55,11 +53,9 @@ func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models
|
|||||||
} else {
|
} else {
|
||||||
meta, err = otpCollection.UpdateDocument(ctx, otp.Key, otp)
|
meta, err = otpCollection.UpdateDocument(ctx, otp.Key, otp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
otp.Key = meta.Key
|
otp.Key = meta.Key
|
||||||
otp.ID = meta.ID.String()
|
otp.ID = meta.ID.String()
|
||||||
return otp, nil
|
return otp, nil
|
||||||
@@ -67,21 +63,19 @@ func (p *provider) UpsertOTP(ctx context.Context, otpParam *models.OTP) (*models
|
|||||||
|
|
||||||
// GetOTPByEmail to get otp for a given email address
|
// GetOTPByEmail to get otp for a given email address
|
||||||
func (p *provider) GetOTPByEmail(ctx context.Context, emailAddress string) (*models.OTP, error) {
|
func (p *provider) GetOTPByEmail(ctx context.Context, emailAddress string) (*models.OTP, error) {
|
||||||
var otp models.OTP
|
var otp *models.OTP
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email RETURN d", models.Collections.OTP)
|
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email RETURN d", models.Collections.OTP)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"email": emailAddress,
|
"email": emailAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if otp.Key == "" {
|
if otp == nil {
|
||||||
return nil, fmt.Errorf("otp with given email not found")
|
return nil, fmt.Errorf("otp with given email not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -91,13 +85,12 @@ func (p *provider) GetOTPByEmail(ctx context.Context, emailAddress string) (*mod
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return otp, nil
|
||||||
return &otp, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOTPByPhoneNumber to get otp for a given phone number
|
// GetOTPByPhoneNumber to get otp for a given phone number
|
||||||
func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string) (*models.OTP, error) {
|
func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string) (*models.OTP, error) {
|
||||||
var otp models.OTP
|
var otp *models.OTP
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.phone_number == @phone_number RETURN d", models.Collections.OTP)
|
query := fmt.Sprintf("FOR d in %s FILTER d.phone_number == @phone_number RETURN d", models.Collections.OTP)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"phone_number": phoneNumber,
|
"phone_number": phoneNumber,
|
||||||
@@ -109,7 +102,7 @@ func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string)
|
|||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if otp.Key == "" {
|
if otp == nil {
|
||||||
return nil, fmt.Errorf("otp with given phone_number not found")
|
return nil, fmt.Errorf("otp with given phone_number not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -119,8 +112,7 @@ func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return otp, nil
|
||||||
return &otp, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteOTP to delete otp
|
// DeleteOTP to delete otp
|
||||||
@@ -130,6 +122,5 @@ func (p *provider) DeleteOTP(ctx context.Context, otp *models.OTP) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,6 @@ func NewProvider() (*provider, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var arangodb arangoDriver.Database
|
var arangodb arangoDriver.Database
|
||||||
dbName := memorystore.RequiredEnvStoreObj.GetRequiredEnv().DatabaseName
|
dbName := memorystore.RequiredEnvStoreObj.GetRequiredEnv().DatabaseName
|
||||||
arangodb_exists, err := arangoClient.DatabaseExists(ctx, dbName)
|
arangodb_exists, err := arangoClient.DatabaseExists(ctx, dbName)
|
||||||
@@ -79,7 +78,6 @@ func NewProvider() (*provider, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.User)
|
userCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.User)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -113,7 +111,6 @@ func NewProvider() (*provider, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequestCollection, err := arangodb.Collection(ctx, models.Collections.VerificationRequest)
|
verificationRequestCollection, err := arangodb.Collection(ctx, models.Collections.VerificationRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -136,7 +133,6 @@ func NewProvider() (*provider, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionCollection, err := arangodb.Collection(ctx, models.Collections.Session)
|
sessionCollection, err := arangodb.Collection(ctx, models.Collections.Session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -144,7 +140,6 @@ func NewProvider() (*provider, error) {
|
|||||||
sessionCollection.EnsureHashIndex(ctx, []string{"user_id"}, &arangoDriver.EnsureHashIndexOptions{
|
sessionCollection.EnsureHashIndex(ctx, []string{"user_id"}, &arangoDriver.EnsureHashIndexOptions{
|
||||||
Sparse: true,
|
Sparse: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
envCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Env)
|
envCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -155,7 +150,6 @@ func NewProvider() (*provider, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webhookCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Webhook)
|
webhookCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.Webhook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -166,7 +160,6 @@ func NewProvider() (*provider, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webhookCollection, err := arangodb.Collection(ctx, models.Collections.Webhook)
|
webhookCollection, err := arangodb.Collection(ctx, models.Collections.Webhook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -186,7 +179,6 @@ func NewProvider() (*provider, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webhookLogCollection, err := arangodb.Collection(ctx, models.Collections.WebhookLog)
|
webhookLogCollection, err := arangodb.Collection(ctx, models.Collections.WebhookLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -194,7 +186,6 @@ func NewProvider() (*provider, error) {
|
|||||||
webhookLogCollection.EnsureHashIndex(ctx, []string{"webhook_id"}, &arangoDriver.EnsureHashIndexOptions{
|
webhookLogCollection.EnsureHashIndex(ctx, []string{"webhook_id"}, &arangoDriver.EnsureHashIndexOptions{
|
||||||
Sparse: true,
|
Sparse: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
emailTemplateCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.EmailTemplate)
|
emailTemplateCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.EmailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -205,7 +196,6 @@ func NewProvider() (*provider, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emailTemplateCollection, err := arangodb.Collection(ctx, models.Collections.EmailTemplate)
|
emailTemplateCollection, err := arangodb.Collection(ctx, models.Collections.EmailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -214,7 +204,6 @@ func NewProvider() (*provider, error) {
|
|||||||
Unique: true,
|
Unique: true,
|
||||||
Sparse: true,
|
Sparse: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
otpCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.OTP)
|
otpCollectionExists, err := arangodb.CollectionExists(ctx, models.Collections.OTP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -9,12 +9,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddSession to save session information in database
|
// AddSession to save session information in database
|
||||||
func (p *provider) AddSession(ctx context.Context, session models.Session) error {
|
func (p *provider) AddSession(ctx context.Context, session *models.Session) error {
|
||||||
if session.ID == "" {
|
if session.ID == "" {
|
||||||
session.ID = uuid.New().String()
|
session.ID = uuid.New().String()
|
||||||
session.Key = session.ID
|
session.Key = session.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
session.CreatedAt = time.Now().Unix()
|
session.CreatedAt = time.Now().Unix()
|
||||||
session.UpdatedAt = time.Now().Unix()
|
session.UpdatedAt = time.Now().Unix()
|
||||||
sessionCollection, _ := p.db.Collection(ctx, models.Collections.Session)
|
sessionCollection, _ := p.db.Collection(ctx, models.Collections.Session)
|
||||||
@@ -24,3 +23,8 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteSession to delete session information from database
|
||||||
|
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@@ -18,7 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddUser to save user information in database
|
// AddUser to save user information in database
|
||||||
func (p *provider) AddUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) AddUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
if user.ID == "" {
|
if user.ID == "" {
|
||||||
user.ID = uuid.New().String()
|
user.ID = uuid.New().String()
|
||||||
user.Key = user.ID
|
user.Key = user.ID
|
||||||
@@ -52,7 +52,7 @@ func (p *provider) AddUser(ctx context.Context, user models.User) (models.User,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser to update user information in database
|
// UpdateUser to update user information in database
|
||||||
func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) UpdateUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
user.UpdatedAt = time.Now().Unix()
|
user.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
collection, _ := p.db.Collection(ctx, models.Collections.User)
|
collection, _ := p.db.Collection(ctx, models.Collections.User)
|
||||||
@@ -67,13 +67,12 @@ func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.Use
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUser to delete user information from database
|
// DeleteUser to delete user information from database
|
||||||
func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
||||||
collection, _ := p.db.Collection(ctx, models.Collections.User)
|
collection, _ := p.db.Collection(ctx, models.Collections.User)
|
||||||
_, err := collection.RemoveDocument(ctx, user.Key)
|
_, err := collection.RemoveDocument(ctx, user.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
query := fmt.Sprintf(`FOR d IN %s FILTER d.user_id == @user_id REMOVE { _key: d._key } IN %s`, models.Collections.Session, models.Collections.Session)
|
query := fmt.Sprintf(`FOR d IN %s FILTER d.user_id == @user_id REMOVE { _key: d._key } IN %s`, models.Collections.Session, models.Collections.Session)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"user_id": user.Key,
|
"user_id": user.Key,
|
||||||
@@ -83,65 +82,55 @@ func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListUsers to get list of users from database
|
// ListUsers to get list of users from database
|
||||||
func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (*model.Users, error) {
|
func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination) (*model.Users, error) {
|
||||||
var users []*model.User
|
var users []*model.User
|
||||||
sctx := arangoDriver.WithQueryFullCount(ctx)
|
sctx := arangoDriver.WithQueryFullCount(ctx)
|
||||||
|
|
||||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.User, pagination.Offset, pagination.Limit)
|
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.User, pagination.Offset, pagination.Limit)
|
||||||
|
|
||||||
cursor, err := p.db.Query(sctx, query, nil)
|
cursor, err := p.db.Query(sctx, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
paginationClone.Total = cursor.Statistics().FullCount()
|
paginationClone.Total = cursor.Statistics().FullCount()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var user models.User
|
var user *models.User
|
||||||
meta, err := cursor.ReadDocument(ctx, &user)
|
meta, err := cursor.ReadDocument(ctx, &user)
|
||||||
|
|
||||||
if arangoDriver.IsNoMoreDocuments(err) {
|
if arangoDriver.IsNoMoreDocuments(err) {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.Key != "" {
|
if meta.Key != "" {
|
||||||
users = append(users, user.AsAPIUser())
|
users = append(users, user.AsAPIUser())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.Users{
|
return &model.Users{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Users: users,
|
Users: users,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByEmail to get user information from database using email address
|
// GetUserByEmail to get user information from database using email address
|
||||||
func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.User, error) {
|
func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email RETURN d", models.Collections.User)
|
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email RETURN d", models.Collections.User)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"email": email,
|
"email": email,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if user.Key == "" {
|
if user == nil {
|
||||||
return user, fmt.Errorf("user not found")
|
return user, fmt.Errorf("user not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -151,28 +140,24 @@ func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.Use
|
|||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByID to get user information from database using user ID
|
// GetUserByID to get user information from database using user ID
|
||||||
func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, error) {
|
func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d._id == @id LIMIT 1 RETURN d", models.Collections.User)
|
query := fmt.Sprintf("FOR d in %s FILTER d._id == @id LIMIT 1 RETURN d", models.Collections.User)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"id": id,
|
"id": id,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if user.Key == "" {
|
if user == nil {
|
||||||
return user, fmt.Errorf("user not found")
|
return user, fmt.Errorf("user not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -182,7 +167,6 @@ func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, err
|
|||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,12 +175,10 @@ func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, err
|
|||||||
func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error {
|
func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error {
|
||||||
// set updated_at time for all users
|
// set updated_at time for all users
|
||||||
data["updated_at"] = time.Now().Unix()
|
data["updated_at"] = time.Now().Unix()
|
||||||
|
|
||||||
userInfoBytes, err := json.Marshal(data)
|
userInfoBytes, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
query := ""
|
query := ""
|
||||||
if len(ids) > 0 {
|
if len(ids) > 0 {
|
||||||
keysArray := ""
|
keysArray := ""
|
||||||
@@ -209,33 +191,28 @@ func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{},
|
|||||||
} else {
|
} else {
|
||||||
query = fmt.Sprintf("FOR u IN %s UPDATE u._key with %s IN %s", models.Collections.User, string(userInfoBytes), models.Collections.User)
|
query = fmt.Sprintf("FOR u IN %s UPDATE u._key with %s IN %s", models.Collections.User, string(userInfoBytes), models.Collections.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = p.db.Query(ctx, query, nil)
|
_, err = p.db.Query(ctx, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByPhoneNumber to get user information from database using phone number
|
// GetUserByPhoneNumber to get user information from database using phone number
|
||||||
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.phone_number == @phone_number RETURN d", models.Collections.User)
|
query := fmt.Sprintf("FOR d in %s FILTER d.phone_number == @phone_number RETURN d", models.Collections.User)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"phone_number": phoneNumber,
|
"phone_number": phoneNumber,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if user.Key == "" {
|
if user == nil {
|
||||||
return nil, fmt.Errorf("user not found")
|
return nil, fmt.Errorf("user not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -245,6 +222,5 @@ func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return user, nil
|
||||||
return &user, nil
|
|
||||||
}
|
}
|
||||||
|
@@ -12,12 +12,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddVerification to save verification request in database
|
// AddVerification to save verification request in database
|
||||||
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) (models.VerificationRequest, error) {
|
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) (*models.VerificationRequest, error) {
|
||||||
if verificationRequest.ID == "" {
|
if verificationRequest.ID == "" {
|
||||||
verificationRequest.ID = uuid.New().String()
|
verificationRequest.ID = uuid.New().String()
|
||||||
verificationRequest.Key = verificationRequest.ID
|
verificationRequest.Key = verificationRequest.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest.CreatedAt = time.Now().Unix()
|
verificationRequest.CreatedAt = time.Now().Unix()
|
||||||
verificationRequest.UpdatedAt = time.Now().Unix()
|
verificationRequest.UpdatedAt = time.Now().Unix()
|
||||||
verificationRequestRequestCollection, _ := p.db.Collection(ctx, models.Collections.VerificationRequest)
|
verificationRequestRequestCollection, _ := p.db.Collection(ctx, models.Collections.VerificationRequest)
|
||||||
@@ -27,27 +26,24 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||||||
}
|
}
|
||||||
verificationRequest.Key = meta.Key
|
verificationRequest.Key = meta.Key
|
||||||
verificationRequest.ID = meta.ID.String()
|
verificationRequest.ID = meta.ID.String()
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByToken to get verification request from database using token
|
// GetVerificationRequestByToken to get verification request from database using token
|
||||||
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.token == @token LIMIT 1 RETURN d", models.Collections.VerificationRequest)
|
query := fmt.Sprintf("FOR d in %s FILTER d.token == @token LIMIT 1 RETURN d", models.Collections.VerificationRequest)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"token": token,
|
"token": token,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return verificationRequest, err
|
return verificationRequest, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if verificationRequest.Key == "" {
|
if verificationRequest == nil {
|
||||||
return verificationRequest, fmt.Errorf("verification request not found")
|
return verificationRequest, fmt.Errorf("verification request not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -57,29 +53,25 @@ func (p *provider) GetVerificationRequestByToken(ctx context.Context, token stri
|
|||||||
return verificationRequest, err
|
return verificationRequest, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByEmail to get verification request by email from database
|
// GetVerificationRequestByEmail to get verification request by email from database
|
||||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
|
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email FILTER d.identifier == @identifier LIMIT 1 RETURN d", models.Collections.VerificationRequest)
|
query := fmt.Sprintf("FOR d in %s FILTER d.email == @email FILTER d.identifier == @identifier LIMIT 1 RETURN d", models.Collections.VerificationRequest)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"email": email,
|
"email": email,
|
||||||
"identifier": identifier,
|
"identifier": identifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor, err := p.db.Query(ctx, query, bindVars)
|
cursor, err := p.db.Query(ctx, query, bindVars)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return verificationRequest, err
|
return verificationRequest, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if verificationRequest.Key == "" {
|
if verificationRequest == nil {
|
||||||
return verificationRequest, fmt.Errorf("verification request not found")
|
return verificationRequest, fmt.Errorf("verification request not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -89,27 +81,23 @@ func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email stri
|
|||||||
return verificationRequest, err
|
return verificationRequest, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListVerificationRequests to get list of verification requests from database
|
// ListVerificationRequests to get list of verification requests from database
|
||||||
func (p *provider) ListVerificationRequests(ctx context.Context, pagination model.Pagination) (*model.VerificationRequests, error) {
|
func (p *provider) ListVerificationRequests(ctx context.Context, pagination *model.Pagination) (*model.VerificationRequests, error) {
|
||||||
var verificationRequests []*model.VerificationRequest
|
var verificationRequests []*model.VerificationRequest
|
||||||
sctx := arangoDriver.WithQueryFullCount(ctx)
|
sctx := arangoDriver.WithQueryFullCount(ctx)
|
||||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.VerificationRequest, pagination.Offset, pagination.Limit)
|
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.VerificationRequest, pagination.Offset, pagination.Limit)
|
||||||
|
|
||||||
cursor, err := p.db.Query(sctx, query, nil)
|
cursor, err := p.db.Query(sctx, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
paginationClone.Total = cursor.Statistics().FullCount()
|
paginationClone.Total = cursor.Statistics().FullCount()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
meta, err := cursor.ReadDocument(ctx, &verificationRequest)
|
meta, err := cursor.ReadDocument(ctx, &verificationRequest)
|
||||||
|
|
||||||
if arangoDriver.IsNoMoreDocuments(err) {
|
if arangoDriver.IsNoMoreDocuments(err) {
|
||||||
@@ -123,15 +111,14 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.VerificationRequests{
|
return &model.VerificationRequests{
|
||||||
VerificationRequests: verificationRequests,
|
VerificationRequests: verificationRequests,
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteVerificationRequest to delete verification request from database
|
// DeleteVerificationRequest to delete verification request from database
|
||||||
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) error {
|
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) error {
|
||||||
collection, _ := p.db.Collection(ctx, models.Collections.VerificationRequest)
|
collection, _ := p.db.Collection(ctx, models.Collections.VerificationRequest)
|
||||||
_, err := collection.RemoveDocument(ctx, verificationRequest.Key)
|
_, err := collection.RemoveDocument(ctx, verificationRequest.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhook to add webhook
|
// AddWebhook to add webhook
|
||||||
func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) AddWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
if webhook.ID == "" {
|
if webhook.ID == "" {
|
||||||
webhook.ID = uuid.New().String()
|
webhook.ID = uuid.New().String()
|
||||||
webhook.Key = webhook.ID
|
webhook.Key = webhook.ID
|
||||||
@@ -33,7 +33,7 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWebhook to update webhook
|
// UpdateWebhook to update webhook
|
||||||
func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) UpdateWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
// Event is changed
|
// Event is changed
|
||||||
if !strings.Contains(webhook.EventName, "-") {
|
if !strings.Contains(webhook.EventName, "-") {
|
||||||
@@ -50,11 +50,9 @@ func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhooks to list webhook
|
// ListWebhooks to list webhook
|
||||||
func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination) (*model.Webhooks, error) {
|
func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination) (*model.Webhooks, error) {
|
||||||
webhooks := []*model.Webhook{}
|
webhooks := []*model.Webhook{}
|
||||||
|
|
||||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.Webhook, pagination.Offset, pagination.Limit)
|
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.Webhook, pagination.Offset, pagination.Limit)
|
||||||
|
|
||||||
sctx := arangoDriver.WithQueryFullCount(ctx)
|
sctx := arangoDriver.WithQueryFullCount(ctx)
|
||||||
cursor, err := p.db.Query(sctx, query, nil)
|
cursor, err := p.db.Query(sctx, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -64,9 +62,8 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
|||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
paginationClone.Total = cursor.Statistics().FullCount()
|
paginationClone.Total = cursor.Statistics().FullCount()
|
||||||
for {
|
for {
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
meta, err := cursor.ReadDocument(ctx, &webhook)
|
meta, err := cursor.ReadDocument(ctx, &webhook)
|
||||||
|
|
||||||
if arangoDriver.IsNoMoreDocuments(err) {
|
if arangoDriver.IsNoMoreDocuments(err) {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
@@ -79,14 +76,14 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &model.Webhooks{
|
return &model.Webhooks{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Webhooks: webhooks,
|
Webhooks: webhooks,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWebhookByID to get webhook by id
|
// GetWebhookByID to get webhook by id
|
||||||
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
query := fmt.Sprintf("FOR d in %s FILTER d._key == @webhook_id RETURN d", models.Collections.Webhook)
|
query := fmt.Sprintf("FOR d in %s FILTER d._key == @webhook_id RETURN d", models.Collections.Webhook)
|
||||||
bindVars := map[string]interface{}{
|
bindVars := map[string]interface{}{
|
||||||
"webhook_id": webhookID,
|
"webhook_id": webhookID,
|
||||||
@@ -98,7 +95,7 @@ func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model
|
|||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
for {
|
for {
|
||||||
if !cursor.HasMore() {
|
if !cursor.HasMore() {
|
||||||
if webhook.Key == "" {
|
if webhook == nil {
|
||||||
return nil, fmt.Errorf("webhook not found")
|
return nil, fmt.Errorf("webhook not found")
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -124,7 +121,7 @@ func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string)
|
|||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
webhooks := []*model.Webhook{}
|
webhooks := []*model.Webhook{}
|
||||||
for {
|
for {
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
if _, err := cursor.ReadDocument(ctx, &webhook); driver.IsNoMoreDocuments(err) {
|
if _, err := cursor.ReadDocument(ctx, &webhook); driver.IsNoMoreDocuments(err) {
|
||||||
// We're done
|
// We're done
|
||||||
break
|
break
|
||||||
|
@@ -12,12 +12,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhookLog to add webhook log
|
// AddWebhookLog to add webhook log
|
||||||
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookLog) (*model.WebhookLog, error) {
|
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.WebhookLog) (*model.WebhookLog, error) {
|
||||||
if webhookLog.ID == "" {
|
if webhookLog.ID == "" {
|
||||||
webhookLog.ID = uuid.New().String()
|
webhookLog.ID = uuid.New().String()
|
||||||
webhookLog.Key = webhookLog.ID
|
webhookLog.Key = webhookLog.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
webhookLog.Key = webhookLog.ID
|
webhookLog.Key = webhookLog.ID
|
||||||
webhookLog.CreatedAt = time.Now().Unix()
|
webhookLog.CreatedAt = time.Now().Unix()
|
||||||
webhookLog.UpdatedAt = time.Now().Unix()
|
webhookLog.UpdatedAt = time.Now().Unix()
|
||||||
@@ -30,46 +29,38 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhookLogs to list webhook logs
|
// ListWebhookLogs to list webhook logs
|
||||||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||||
webhookLogs := []*model.WebhookLog{}
|
webhookLogs := []*model.WebhookLog{}
|
||||||
bindVariables := map[string]interface{}{}
|
bindVariables := map[string]interface{}{}
|
||||||
|
|
||||||
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
query := fmt.Sprintf("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
||||||
|
|
||||||
if webhookID != "" {
|
if webhookID != "" {
|
||||||
query = fmt.Sprintf("FOR d in %s FILTER d.webhook_id == @webhook_id SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
query = fmt.Sprintf("FOR d in %s FILTER d.webhook_id == @webhook_id SORT d.created_at DESC LIMIT %d, %d RETURN d", models.Collections.WebhookLog, pagination.Offset, pagination.Limit)
|
||||||
bindVariables = map[string]interface{}{
|
bindVariables = map[string]interface{}{
|
||||||
"webhook_id": webhookID,
|
"webhook_id": webhookID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sctx := arangoDriver.WithQueryFullCount(ctx)
|
sctx := arangoDriver.WithQueryFullCount(ctx)
|
||||||
cursor, err := p.db.Query(sctx, query, bindVariables)
|
cursor, err := p.db.Query(sctx, query, bindVariables)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close()
|
defer cursor.Close()
|
||||||
|
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
paginationClone.Total = cursor.Statistics().FullCount()
|
paginationClone.Total = cursor.Statistics().FullCount()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var webhookLog models.WebhookLog
|
var webhookLog *models.WebhookLog
|
||||||
meta, err := cursor.ReadDocument(ctx, &webhookLog)
|
meta, err := cursor.ReadDocument(ctx, &webhookLog)
|
||||||
|
|
||||||
if arangoDriver.IsNoMoreDocuments(err) {
|
if arangoDriver.IsNoMoreDocuments(err) {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.Key != "" {
|
if meta.Key != "" {
|
||||||
webhookLogs = append(webhookLogs, webhookLog.AsAPIWebhookLog())
|
webhookLogs = append(webhookLogs, webhookLog.AsAPIWebhookLog())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.WebhookLogs{
|
return &model.WebhookLogs{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
WebhookLogs: webhookLogs,
|
WebhookLogs: webhookLogs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -15,33 +15,28 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEmailTemplate to add EmailTemplate
|
// AddEmailTemplate to add EmailTemplate
|
||||||
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
if emailTemplate.ID == "" {
|
if emailTemplate.ID == "" {
|
||||||
emailTemplate.ID = uuid.New().String()
|
emailTemplate.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
emailTemplate.Key = emailTemplate.ID
|
emailTemplate.Key = emailTemplate.ID
|
||||||
emailTemplate.CreatedAt = time.Now().Unix()
|
emailTemplate.CreatedAt = time.Now().Unix()
|
||||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
existingEmailTemplate, _ := p.GetEmailTemplateByEventName(ctx, emailTemplate.EventName)
|
existingEmailTemplate, _ := p.GetEmailTemplateByEventName(ctx, emailTemplate.EventName)
|
||||||
if existingEmailTemplate != nil {
|
if existingEmailTemplate != nil {
|
||||||
return nil, fmt.Errorf("Email template with %s event_name already exists", emailTemplate.EventName)
|
return nil, fmt.Errorf("Email template with %s event_name already exists", emailTemplate.EventName)
|
||||||
}
|
}
|
||||||
|
|
||||||
insertQuery := fmt.Sprintf("INSERT INTO %s (id, event_name, subject, design, template, created_at, updated_at) VALUES ('%s', '%s', '%s','%s','%s', %d, %d)", KeySpace+"."+models.Collections.EmailTemplate, emailTemplate.ID, emailTemplate.EventName, emailTemplate.Subject, emailTemplate.Design, emailTemplate.Template, emailTemplate.CreatedAt, emailTemplate.UpdatedAt)
|
insertQuery := fmt.Sprintf("INSERT INTO %s (id, event_name, subject, design, template, created_at, updated_at) VALUES ('%s', '%s', '%s','%s','%s', %d, %d)", KeySpace+"."+models.Collections.EmailTemplate, emailTemplate.ID, emailTemplate.EventName, emailTemplate.Subject, emailTemplate.Design, emailTemplate.Template, emailTemplate.CreatedAt, emailTemplate.UpdatedAt)
|
||||||
err := p.db.Query(insertQuery).Exec()
|
err := p.db.Query(insertQuery).Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEmailTemplate to update EmailTemplate
|
// UpdateEmailTemplate to update EmailTemplate
|
||||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
bytes, err := json.Marshal(emailTemplate)
|
bytes, err := json.Marshal(emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -54,22 +49,18 @@ func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFields := ""
|
updateFields := ""
|
||||||
for key, value := range emailTemplateMap {
|
for key, value := range emailTemplateMap {
|
||||||
if key == "_id" {
|
if key == "_id" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if key == "_key" {
|
if key == "_key" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if value == nil {
|
if value == nil {
|
||||||
updateFields += fmt.Sprintf("%s = null,", key)
|
updateFields += fmt.Sprintf("%s = null,", key)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
valueType := reflect.TypeOf(value)
|
valueType := reflect.TypeOf(value)
|
||||||
if valueType.Name() == "string" {
|
if valueType.Name() == "string" {
|
||||||
updateFields += fmt.Sprintf("%s = '%s', ", key, value.(string))
|
updateFields += fmt.Sprintf("%s = '%s', ", key, value.(string))
|
||||||
@@ -90,7 +81,7 @@ func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListEmailTemplates to list EmailTemplate
|
// ListEmailTemplates to list EmailTemplate
|
||||||
func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagination) (*model.EmailTemplates, error) {
|
func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagination) (*model.EmailTemplates, error) {
|
||||||
emailTemplates := []*model.EmailTemplate{}
|
emailTemplates := []*model.EmailTemplate{}
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
|
|
||||||
@@ -120,7 +111,7 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagin
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &model.EmailTemplates{
|
return &model.EmailTemplates{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
EmailTemplates: emailTemplates,
|
EmailTemplates: emailTemplates,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -11,11 +11,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEnv to save environment information in database
|
// AddEnv to save environment information in database
|
||||||
func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
if env.ID == "" {
|
if env.ID == "" {
|
||||||
env.ID = uuid.New().String()
|
env.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
env.CreatedAt = time.Now().Unix()
|
env.CreatedAt = time.Now().Unix()
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
insertEnvQuery := fmt.Sprintf("INSERT INTO %s (id, env, hash, created_at, updated_at) VALUES ('%s', '%s', '%s', %d, %d)", KeySpace+"."+models.Collections.Env, env.ID, env.EnvData, env.Hash, env.CreatedAt, env.UpdatedAt)
|
insertEnvQuery := fmt.Sprintf("INSERT INTO %s (id, env, hash, created_at, updated_at) VALUES ('%s', '%s', '%s', %d, %d)", KeySpace+"."+models.Collections.Env, env.ID, env.EnvData, env.Hash, env.CreatedAt, env.UpdatedAt)
|
||||||
@@ -28,9 +27,8 @@ func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEnv to update environment information in database
|
// UpdateEnv to update environment information in database
|
||||||
func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
updateEnvQuery := fmt.Sprintf("UPDATE %s SET env = '%s', updated_at = %d WHERE id = '%s'", KeySpace+"."+models.Collections.Env, env.EnvData, env.UpdatedAt, env.ID)
|
updateEnvQuery := fmt.Sprintf("UPDATE %s SET env = '%s', updated_at = %d WHERE id = '%s'", KeySpace+"."+models.Collections.Env, env.EnvData, env.UpdatedAt, env.ID)
|
||||||
err := p.db.Query(updateEnvQuery).Exec()
|
err := p.db.Query(updateEnvQuery).Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -40,14 +38,12 @@ func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEnv to get environment information from database
|
// GetEnv to get environment information from database
|
||||||
func (p *provider) GetEnv(ctx context.Context) (models.Env, error) {
|
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||||
var env models.Env
|
var env models.Env
|
||||||
|
|
||||||
query := fmt.Sprintf("SELECT id, env, hash, created_at, updated_at FROM %s LIMIT 1", KeySpace+"."+models.Collections.Env)
|
query := fmt.Sprintf("SELECT id, env, hash, created_at, updated_at FROM %s LIMIT 1", KeySpace+"."+models.Collections.Env)
|
||||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&env.ID, &env.EnvData, &env.Hash, &env.CreatedAt, &env.UpdatedAt)
|
err := p.db.Query(query).Consistency(gocql.One).Scan(&env.ID, &env.EnvData, &env.Hash, &env.CreatedAt, &env.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return env, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return &env, nil
|
||||||
return env, nil
|
|
||||||
}
|
}
|
||||||
|
@@ -10,14 +10,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddSession to save session information in database
|
// AddSession to save session information in database
|
||||||
func (p *provider) AddSession(ctx context.Context, session models.Session) error {
|
func (p *provider) AddSession(ctx context.Context, session *models.Session) error {
|
||||||
if session.ID == "" {
|
if session.ID == "" {
|
||||||
session.ID = uuid.New().String()
|
session.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
session.CreatedAt = time.Now().Unix()
|
session.CreatedAt = time.Now().Unix()
|
||||||
session.UpdatedAt = time.Now().Unix()
|
session.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
insertSessionQuery := fmt.Sprintf("INSERT INTO %s (id, user_id, user_agent, ip, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', %d, %d)", KeySpace+"."+models.Collections.Session, session.ID, session.UserID, session.UserAgent, session.IP, session.CreatedAt, session.UpdatedAt)
|
insertSessionQuery := fmt.Sprintf("INSERT INTO %s (id, user_id, user_agent, ip, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', %d, %d)", KeySpace+"."+models.Collections.Session, session.ID, session.UserID, session.UserAgent, session.IP, session.CreatedAt, session.UpdatedAt)
|
||||||
err := p.db.Query(insertSessionQuery).Exec()
|
err := p.db.Query(insertSessionQuery).Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -25,3 +23,8 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteSession to delete session information from database
|
||||||
|
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@@ -18,7 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddUser to save user information in database
|
// AddUser to save user information in database
|
||||||
func (p *provider) AddUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) AddUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
if user.ID == "" {
|
if user.ID == "" {
|
||||||
user.ID = uuid.New().String()
|
user.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,6 @@ func (p *provider) AddUser(ctx context.Context, user models.User) (models.User,
|
|||||||
values = values[:len(values)-1] + ")"
|
values = values[:len(values)-1] + ")"
|
||||||
|
|
||||||
query := fmt.Sprintf("INSERT INTO %s %s VALUES %s IF NOT EXISTS", KeySpace+"."+models.Collections.User, fields, values)
|
query := fmt.Sprintf("INSERT INTO %s %s VALUES %s IF NOT EXISTS", KeySpace+"."+models.Collections.User, fields, values)
|
||||||
|
|
||||||
err = p.db.Query(query).Exec()
|
err = p.db.Query(query).Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
@@ -87,7 +86,7 @@ func (p *provider) AddUser(ctx context.Context, user models.User) (models.User,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser to update user information in database
|
// UpdateUser to update user information in database
|
||||||
func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) UpdateUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
user.UpdatedAt = time.Now().Unix()
|
user.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
bytes, err := json.Marshal(user)
|
bytes, err := json.Marshal(user)
|
||||||
@@ -138,13 +137,12 @@ func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.Use
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUser to delete user information from database
|
// DeleteUser to delete user information from database
|
||||||
func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
||||||
query := fmt.Sprintf("DELETE FROM %s WHERE id = '%s'", KeySpace+"."+models.Collections.User, user.ID)
|
query := fmt.Sprintf("DELETE FROM %s WHERE id = '%s'", KeySpace+"."+models.Collections.User, user.ID)
|
||||||
err := p.db.Query(query).Exec()
|
err := p.db.Query(query).Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
getSessionsQuery := fmt.Sprintf("SELECT id FROM %s WHERE user_id = '%s' ALLOW FILTERING", KeySpace+"."+models.Collections.Session, user.ID)
|
getSessionsQuery := fmt.Sprintf("SELECT id FROM %s WHERE user_id = '%s' ALLOW FILTERING", KeySpace+"."+models.Collections.Session, user.ID)
|
||||||
scanner := p.db.Query(getSessionsQuery).Iter().Scanner()
|
scanner := p.db.Query(getSessionsQuery).Iter().Scanner()
|
||||||
sessionIDs := ""
|
sessionIDs := ""
|
||||||
@@ -167,7 +165,7 @@ func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListUsers to get list of users from database
|
// ListUsers to get list of users from database
|
||||||
func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (*model.Users, error) {
|
func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination) (*model.Users, error) {
|
||||||
responseUsers := []*model.User{}
|
responseUsers := []*model.User{}
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.User)
|
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.User)
|
||||||
@@ -180,7 +178,6 @@ func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (
|
|||||||
// so we fetch till limit + offset
|
// so we fetch till limit + offset
|
||||||
// and return the results from offset to limit
|
// and return the results from offset to limit
|
||||||
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s LIMIT %d", KeySpace+"."+models.Collections.User, pagination.Limit+pagination.Offset)
|
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s LIMIT %d", KeySpace+"."+models.Collections.User, pagination.Limit+pagination.Offset)
|
||||||
|
|
||||||
scanner := p.db.Query(query).Iter().Scanner()
|
scanner := p.db.Query(query).Iter().Scanner()
|
||||||
counter := int64(0)
|
counter := int64(0)
|
||||||
for scanner.Next() {
|
for scanner.Next() {
|
||||||
@@ -195,31 +192,31 @@ func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (
|
|||||||
counter++
|
counter++
|
||||||
}
|
}
|
||||||
return &model.Users{
|
return &model.Users{
|
||||||
|
Pagination: paginationClone,
|
||||||
Users: responseUsers,
|
Users: responseUsers,
|
||||||
Pagination: &paginationClone,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByEmail to get user information from database using email address
|
// GetUserByEmail to get user information from database using email address
|
||||||
func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.User, error) {
|
func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.User, error) {
|
||||||
var user models.User
|
var user models.User
|
||||||
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s WHERE email = '%s' LIMIT 1 ALLOW FILTERING", KeySpace+"."+models.Collections.User, email)
|
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s WHERE email = '%s' LIMIT 1 ALLOW FILTERING", KeySpace+"."+models.Collections.User, email)
|
||||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&user.ID, &user.Email, &user.EmailVerifiedAt, &user.Password, &user.SignupMethods, &user.GivenName, &user.FamilyName, &user.MiddleName, &user.Nickname, &user.Birthdate, &user.PhoneNumber, &user.PhoneNumberVerifiedAt, &user.Picture, &user.Roles, &user.RevokedTimestamp, &user.IsMultiFactorAuthEnabled, &user.CreatedAt, &user.UpdatedAt)
|
err := p.db.Query(query).Consistency(gocql.One).Scan(&user.ID, &user.Email, &user.EmailVerifiedAt, &user.Password, &user.SignupMethods, &user.GivenName, &user.FamilyName, &user.MiddleName, &user.Nickname, &user.Birthdate, &user.PhoneNumber, &user.PhoneNumberVerifiedAt, &user.Picture, &user.Roles, &user.RevokedTimestamp, &user.IsMultiFactorAuthEnabled, &user.CreatedAt, &user.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return user, nil
|
return &user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByID to get user information from database using user ID
|
// GetUserByID to get user information from database using user ID
|
||||||
func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, error) {
|
func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, error) {
|
||||||
var user models.User
|
var user models.User
|
||||||
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s WHERE id = '%s' LIMIT 1", KeySpace+"."+models.Collections.User, id)
|
query := fmt.Sprintf("SELECT id, email, email_verified_at, password, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s WHERE id = '%s' LIMIT 1", KeySpace+"."+models.Collections.User, id)
|
||||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&user.ID, &user.Email, &user.EmailVerifiedAt, &user.Password, &user.SignupMethods, &user.GivenName, &user.FamilyName, &user.MiddleName, &user.Nickname, &user.Birthdate, &user.PhoneNumber, &user.PhoneNumberVerifiedAt, &user.Picture, &user.Roles, &user.RevokedTimestamp, &user.IsMultiFactorAuthEnabled, &user.CreatedAt, &user.UpdatedAt)
|
err := p.db.Query(query).Consistency(gocql.One).Scan(&user.ID, &user.Email, &user.EmailVerifiedAt, &user.Password, &user.SignupMethods, &user.GivenName, &user.FamilyName, &user.MiddleName, &user.Nickname, &user.Birthdate, &user.PhoneNumber, &user.PhoneNumberVerifiedAt, &user.Picture, &user.Roles, &user.RevokedTimestamp, &user.IsMultiFactorAuthEnabled, &user.CreatedAt, &user.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return user, nil
|
return &user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUsers to update multiple users, with parameters of user IDs slice
|
// UpdateUsers to update multiple users, with parameters of user IDs slice
|
||||||
@@ -252,9 +249,8 @@ func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{},
|
|||||||
}
|
}
|
||||||
updateFields = strings.Trim(updateFields, " ")
|
updateFields = strings.Trim(updateFields, " ")
|
||||||
updateFields = strings.TrimSuffix(updateFields, ",")
|
updateFields = strings.TrimSuffix(updateFields, ",")
|
||||||
|
|
||||||
query := ""
|
query := ""
|
||||||
if ids != nil && len(ids) > 0 {
|
if len(ids) > 0 {
|
||||||
idsString := ""
|
idsString := ""
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
idsString += fmt.Sprintf("'%s', ", id)
|
idsString += fmt.Sprintf("'%s', ", id)
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddVerification to save verification request in database
|
// AddVerification to save verification request in database
|
||||||
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) (models.VerificationRequest, error) {
|
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) (*models.VerificationRequest, error) {
|
||||||
if verificationRequest.ID == "" {
|
if verificationRequest.ID == "" {
|
||||||
verificationRequest.ID = uuid.New().String()
|
verificationRequest.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -29,41 +29,39 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByToken to get verification request from database using token
|
// GetVerificationRequestByToken to get verification request from database using token
|
||||||
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest models.VerificationRequest
|
||||||
query := fmt.Sprintf(`SELECT id, jwt_token, identifier, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s WHERE jwt_token = '%s' LIMIT 1`, KeySpace+"."+models.Collections.VerificationRequest, token)
|
query := fmt.Sprintf(`SELECT id, jwt_token, identifier, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s WHERE jwt_token = '%s' LIMIT 1`, KeySpace+"."+models.Collections.VerificationRequest, token)
|
||||||
|
|
||||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
err := p.db.Query(query).Consistency(gocql.One).Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return verificationRequest, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return verificationRequest, nil
|
return &verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByEmail to get verification request by email from database
|
// GetVerificationRequestByEmail to get verification request by email from database
|
||||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest models.VerificationRequest
|
||||||
query := fmt.Sprintf(`SELECT id, jwt_token, identifier, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s WHERE email = '%s' AND identifier = '%s' LIMIT 1 ALLOW FILTERING`, KeySpace+"."+models.Collections.VerificationRequest, email, identifier)
|
query := fmt.Sprintf(`SELECT id, jwt_token, identifier, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s WHERE email = '%s' AND identifier = '%s' LIMIT 1 ALLOW FILTERING`, KeySpace+"."+models.Collections.VerificationRequest, email, identifier)
|
||||||
|
|
||||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
err := p.db.Query(query).Consistency(gocql.One).Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return verificationRequest, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return verificationRequest, nil
|
return &verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListVerificationRequests to get list of verification requests from database
|
// ListVerificationRequests to get list of verification requests from database
|
||||||
func (p *provider) ListVerificationRequests(ctx context.Context, pagination model.Pagination) (*model.VerificationRequests, error) {
|
func (p *provider) ListVerificationRequests(ctx context.Context, pagination *model.Pagination) (*model.VerificationRequests, error) {
|
||||||
var verificationRequests []*model.VerificationRequest
|
var verificationRequests []*model.VerificationRequest
|
||||||
|
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.VerificationRequest)
|
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.VerificationRequest)
|
||||||
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(&paginationClone.Total)
|
err := p.db.Query(totalCountQuery).Consistency(gocql.One).Scan(&paginationClone.Total)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// there is no offset in cassandra
|
// there is no offset in cassandra
|
||||||
// so we fetch till limit + offset
|
// so we fetch till limit + offset
|
||||||
// and return the results from offset to limit
|
// and return the results from offset to limit
|
||||||
@@ -76,6 +74,7 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination mode
|
|||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest models.VerificationRequest
|
||||||
err := scanner.Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
err := scanner.Scan(&verificationRequest.ID, &verificationRequest.Token, &verificationRequest.Identifier, &verificationRequest.ExpiresAt, &verificationRequest.Email, &verificationRequest.Nonce, &verificationRequest.RedirectURI, &verificationRequest.CreatedAt, &verificationRequest.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("=> getting error here...", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
verificationRequests = append(verificationRequests, verificationRequest.AsAPIVerificationRequest())
|
verificationRequests = append(verificationRequests, verificationRequest.AsAPIVerificationRequest())
|
||||||
@@ -85,12 +84,12 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination mode
|
|||||||
|
|
||||||
return &model.VerificationRequests{
|
return &model.VerificationRequests{
|
||||||
VerificationRequests: verificationRequests,
|
VerificationRequests: verificationRequests,
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteVerificationRequest to delete verification request from database
|
// DeleteVerificationRequest to delete verification request from database
|
||||||
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) error {
|
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) error {
|
||||||
query := fmt.Sprintf("DELETE FROM %s WHERE id = '%s'", KeySpace+"."+models.Collections.VerificationRequest, verificationRequest.ID)
|
query := fmt.Sprintf("DELETE FROM %s WHERE id = '%s'", KeySpace+"."+models.Collections.VerificationRequest, verificationRequest.ID)
|
||||||
err := p.db.Query(query).Exec()
|
err := p.db.Query(query).Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhook to add webhook
|
// AddWebhook to add webhook
|
||||||
func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) AddWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
if webhook.ID == "" {
|
if webhook.ID == "" {
|
||||||
webhook.ID = uuid.New().String()
|
webhook.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWebhook to update webhook
|
// UpdateWebhook to update webhook
|
||||||
func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) UpdateWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
// Event is changed
|
// Event is changed
|
||||||
if !strings.Contains(webhook.EventName, "-") {
|
if !strings.Contains(webhook.EventName, "-") {
|
||||||
@@ -81,7 +81,7 @@ func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhooks to list webhook
|
// ListWebhooks to list webhook
|
||||||
func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination) (*model.Webhooks, error) {
|
func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination) (*model.Webhooks, error) {
|
||||||
webhooks := []*model.Webhook{}
|
webhooks := []*model.Webhook{}
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.Webhook)
|
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.Webhook)
|
||||||
@@ -108,7 +108,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &model.Webhooks{
|
return &model.Webhooks{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Webhooks: webhooks,
|
Webhooks: webhooks,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhookLog to add webhook log
|
// AddWebhookLog to add webhook log
|
||||||
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookLog) (*model.WebhookLog, error) {
|
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.WebhookLog) (*model.WebhookLog, error) {
|
||||||
if webhookLog.ID == "" {
|
if webhookLog.ID == "" {
|
||||||
webhookLog.ID = uuid.New().String()
|
webhookLog.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhookLogs to list webhook logs
|
// ListWebhookLogs to list webhook logs
|
||||||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||||
webhookLogs := []*model.WebhookLog{}
|
webhookLogs := []*model.WebhookLog{}
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.WebhookLog)
|
totalCountQuery := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, KeySpace+"."+models.Collections.WebhookLog)
|
||||||
@@ -38,7 +38,6 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
|||||||
// so we fetch till limit + offset
|
// so we fetch till limit + offset
|
||||||
// and return the results from offset to limit
|
// and return the results from offset to limit
|
||||||
query := fmt.Sprintf("SELECT id, http_status, response, request, webhook_id, created_at, updated_at FROM %s LIMIT %d", KeySpace+"."+models.Collections.WebhookLog, pagination.Limit+pagination.Offset)
|
query := fmt.Sprintf("SELECT id, http_status, response, request, webhook_id, created_at, updated_at FROM %s LIMIT %d", KeySpace+"."+models.Collections.WebhookLog, pagination.Limit+pagination.Offset)
|
||||||
|
|
||||||
if webhookID != "" {
|
if webhookID != "" {
|
||||||
totalCountQuery = fmt.Sprintf(`SELECT COUNT(*) FROM %s WHERE webhook_id='%s' ALLOW FILTERING`, KeySpace+"."+models.Collections.WebhookLog, webhookID)
|
totalCountQuery = fmt.Sprintf(`SELECT COUNT(*) FROM %s WHERE webhook_id='%s' ALLOW FILTERING`, KeySpace+"."+models.Collections.WebhookLog, webhookID)
|
||||||
query = fmt.Sprintf("SELECT id, http_status, response, request, webhook_id, created_at, updated_at FROM %s WHERE webhook_id = '%s' LIMIT %d ALLOW FILTERING", KeySpace+"."+models.Collections.WebhookLog, webhookID, pagination.Limit+pagination.Offset)
|
query = fmt.Sprintf("SELECT id, http_status, response, request, webhook_id, created_at, updated_at FROM %s WHERE webhook_id = '%s' LIMIT %d ALLOW FILTERING", KeySpace+"."+models.Collections.WebhookLog, webhookID, pagination.Limit+pagination.Offset)
|
||||||
@@ -64,7 +63,7 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &model.WebhookLogs{
|
return &model.WebhookLogs{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
WebhookLogs: webhookLogs,
|
WebhookLogs: webhookLogs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEmailTemplate to add EmailTemplate
|
// AddEmailTemplate to add EmailTemplate
|
||||||
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
|
|
||||||
if emailTemplate.ID == "" {
|
if emailTemplate.ID == "" {
|
||||||
emailTemplate.ID = uuid.New().String()
|
emailTemplate.ID = uuid.New().String()
|
||||||
@@ -37,7 +37,7 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.Em
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEmailTemplate to update EmailTemplate
|
// UpdateEmailTemplate to update EmailTemplate
|
||||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
bytes, err := json.Marshal(emailTemplate)
|
bytes, err := json.Marshal(emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -67,7 +67,7 @@ func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListEmailTemplates to list EmailTemplate
|
// ListEmailTemplates to list EmailTemplate
|
||||||
func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagination) (*model.EmailTemplates, error) {
|
func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagination) (*model.EmailTemplates, error) {
|
||||||
emailTemplates := []*model.EmailTemplate{}
|
emailTemplates := []*model.EmailTemplate{}
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
total, err := p.GetTotalDocs(ctx, models.Collections.EmailTemplate)
|
total, err := p.GetTotalDocs(ctx, models.Collections.EmailTemplate)
|
||||||
@@ -88,7 +88,7 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagin
|
|||||||
}
|
}
|
||||||
|
|
||||||
for queryResult.Next() {
|
for queryResult.Next() {
|
||||||
emailTemplate := models.EmailTemplate{}
|
var emailTemplate *models.EmailTemplate
|
||||||
err := queryResult.Row(&emailTemplate)
|
err := queryResult.Row(&emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -102,54 +102,46 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagin
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &model.EmailTemplates{
|
return &model.EmailTemplates{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
EmailTemplates: emailTemplates,
|
EmailTemplates: emailTemplates,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEmailTemplateByID to get EmailTemplate by id
|
// GetEmailTemplateByID to get EmailTemplate by id
|
||||||
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
||||||
emailTemplate := models.EmailTemplate{}
|
var emailTemplate *models.EmailTemplate
|
||||||
|
|
||||||
query := fmt.Sprintf(`SELECT _id, event_name, subject, design, template, created_at, updated_at FROM %s.%s WHERE _id = $1 LIMIT 1`, p.scopeName, models.Collections.EmailTemplate)
|
query := fmt.Sprintf(`SELECT _id, event_name, subject, design, template, created_at, updated_at FROM %s.%s WHERE _id = $1 LIMIT 1`, p.scopeName, models.Collections.EmailTemplate)
|
||||||
q, err := p.db.Query(query, &gocb.QueryOptions{
|
q, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
PositionalParameters: []interface{}{emailTemplateID},
|
PositionalParameters: []interface{}{emailTemplateID},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = q.One(&emailTemplate)
|
err = q.One(&emailTemplate)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
||||||
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
||||||
emailTemplate := models.EmailTemplate{}
|
var emailTemplate models.EmailTemplate
|
||||||
|
|
||||||
query := fmt.Sprintf("SELECT _id, event_name, subject, design, template, created_at, updated_at FROM %s.%s WHERE event_name=$1 LIMIT 1", p.scopeName, models.Collections.EmailTemplate)
|
query := fmt.Sprintf("SELECT _id, event_name, subject, design, template, created_at, updated_at FROM %s.%s WHERE event_name=$1 LIMIT 1", p.scopeName, models.Collections.EmailTemplate)
|
||||||
q, err := p.db.Query(query, &gocb.QueryOptions{
|
q, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
PositionalParameters: []interface{}{eventName},
|
PositionalParameters: []interface{}{eventName},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = q.One(&emailTemplate)
|
err = q.One(&emailTemplate)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEnv to save environment information in database
|
// AddEnv to save environment information in database
|
||||||
func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
if env.ID == "" {
|
if env.ID == "" {
|
||||||
env.ID = uuid.New().String()
|
env.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,6 @@ func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, erro
|
|||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
env.Key = env.ID
|
env.Key = env.ID
|
||||||
env.EncryptionKey = env.Hash
|
env.EncryptionKey = env.Hash
|
||||||
|
|
||||||
insertOpt := gocb.InsertOptions{
|
insertOpt := gocb.InsertOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
@@ -31,7 +30,7 @@ func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEnv to update environment information in database
|
// UpdateEnv to update environment information in database
|
||||||
func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
env.EncryptionKey = env.Hash
|
env.EncryptionKey = env.Hash
|
||||||
|
|
||||||
@@ -40,17 +39,15 @@ func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, e
|
|||||||
Context: ctx,
|
Context: ctx,
|
||||||
PositionalParameters: []interface{}{env.EnvData, env.UpdatedAt, env.UpdatedAt, env.ID},
|
PositionalParameters: []interface{}{env.EnvData, env.UpdatedAt, env.UpdatedAt, env.ID},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return env, err
|
return env, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEnv to get environment information from database
|
// GetEnv to get environment information from database
|
||||||
func (p *provider) GetEnv(ctx context.Context) (models.Env, error) {
|
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||||
var env models.Env
|
var env *models.Env
|
||||||
|
|
||||||
query := fmt.Sprintf("SELECT _id, env, encryption_key, created_at, updated_at FROM %s.%s LIMIT 1", p.scopeName, models.Collections.Env)
|
query := fmt.Sprintf("SELECT _id, env, encryption_key, created_at, updated_at FROM %s.%s LIMIT 1", p.scopeName, models.Collections.Env)
|
||||||
q, err := p.db.Query(query, &gocb.QueryOptions{
|
q, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
@@ -61,7 +58,6 @@ func (p *provider) GetEnv(ctx context.Context) (models.Env, error) {
|
|||||||
return env, err
|
return env, err
|
||||||
}
|
}
|
||||||
err = q.One(&env)
|
err = q.One(&env)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return env, err
|
return env, err
|
||||||
}
|
}
|
||||||
|
@@ -10,11 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddSession to save session information in database
|
// AddSession to save session information in database
|
||||||
func (p *provider) AddSession(ctx context.Context, session models.Session) error {
|
func (p *provider) AddSession(ctx context.Context, session *models.Session) error {
|
||||||
if session.ID == "" {
|
if session.ID == "" {
|
||||||
session.ID = uuid.New().String()
|
session.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
session.CreatedAt = time.Now().Unix()
|
session.CreatedAt = time.Now().Unix()
|
||||||
session.UpdatedAt = time.Now().Unix()
|
session.UpdatedAt = time.Now().Unix()
|
||||||
insertOpt := gocb.InsertOptions{
|
insertOpt := gocb.InsertOptions{
|
||||||
@@ -24,7 +23,6 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,14 +41,11 @@ func GetSetFields(webhookMap map[string]interface{}) (string, map[string]interfa
|
|||||||
|
|
||||||
func (p *provider) GetTotalDocs(ctx context.Context, collection string) (int64, error) {
|
func (p *provider) GetTotalDocs(ctx context.Context, collection string) (int64, error) {
|
||||||
totalDocs := TotalDocs{}
|
totalDocs := TotalDocs{}
|
||||||
|
|
||||||
countQuery := fmt.Sprintf("SELECT COUNT(*) as Total FROM %s.%s", p.scopeName, collection)
|
countQuery := fmt.Sprintf("SELECT COUNT(*) as Total FROM %s.%s", p.scopeName, collection)
|
||||||
queryRes, err := p.db.Query(countQuery, &gocb.QueryOptions{
|
queryRes, err := p.db.Query(countQuery, &gocb.QueryOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
})
|
})
|
||||||
|
|
||||||
queryRes.One(&totalDocs)
|
queryRes.One(&totalDocs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return totalDocs.Total, err
|
return totalDocs.Total, err
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddUser to save user information in database
|
// AddUser to save user information in database
|
||||||
func (p *provider) AddUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) AddUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
if user.ID == "" {
|
if user.ID == "" {
|
||||||
user.ID = uuid.New().String()
|
user.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ func (p *provider) AddUser(ctx context.Context, user models.User) (models.User,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser to update user information in database
|
// UpdateUser to update user information in database
|
||||||
func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) UpdateUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
user.UpdatedAt = time.Now().Unix()
|
user.UpdatedAt = time.Now().Unix()
|
||||||
unsertOpt := gocb.UpsertOptions{
|
unsertOpt := gocb.UpsertOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
@@ -54,7 +54,7 @@ func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.Use
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUser to delete user information from database
|
// DeleteUser to delete user information from database
|
||||||
func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
||||||
removeOpt := gocb.RemoveOptions{
|
removeOpt := gocb.RemoveOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
@@ -66,12 +66,10 @@ func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListUsers to get list of users from database
|
// ListUsers to get list of users from database
|
||||||
func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (*model.Users, error) {
|
func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination) (*model.Users, error) {
|
||||||
users := []*model.User{}
|
users := []*model.User{}
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
|
|
||||||
userQuery := fmt.Sprintf("SELECT _id, email, email_verified_at, `password`, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s.%s ORDER BY id OFFSET $1 LIMIT $2", p.scopeName, models.Collections.User)
|
userQuery := fmt.Sprintf("SELECT _id, email, email_verified_at, `password`, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s.%s ORDER BY id OFFSET $1 LIMIT $2", p.scopeName, models.Collections.User)
|
||||||
|
|
||||||
queryResult, err := p.db.Query(userQuery, &gocb.QueryOptions{
|
queryResult, err := p.db.Query(userQuery, &gocb.QueryOptions{
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
@@ -97,21 +95,20 @@ func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &model.Users{
|
return &model.Users{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Users: users,
|
Users: users,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByEmail to get user information from database using email address
|
// GetUserByEmail to get user information from database using email address
|
||||||
func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.User, error) {
|
func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.User, error) {
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
query := fmt.Sprintf("SELECT _id, email, email_verified_at, `password`, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s.%s WHERE email = $1 LIMIT 1", p.scopeName, models.Collections.User)
|
query := fmt.Sprintf("SELECT _id, email, email_verified_at, `password`, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s.%s WHERE email = $1 LIMIT 1", p.scopeName, models.Collections.User)
|
||||||
q, err := p.db.Query(query, &gocb.QueryOptions{
|
q, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
PositionalParameters: []interface{}{email},
|
PositionalParameters: []interface{}{email},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
@@ -119,13 +116,12 @@ func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.Use
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByID to get user information from database using user ID
|
// GetUserByID to get user information from database using user ID
|
||||||
func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, error) {
|
func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, error) {
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
query := fmt.Sprintf("SELECT _id, email, email_verified_at, `password`, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s.%s WHERE _id = $1 LIMIT 1", p.scopeName, models.Collections.User)
|
query := fmt.Sprintf("SELECT _id, email, email_verified_at, `password`, signup_methods, given_name, family_name, middle_name, nickname, birthdate, phone_number, phone_number_verified_at, picture, roles, revoked_timestamp, is_multi_factor_auth_enabled, created_at, updated_at FROM %s.%s WHERE _id = $1 LIMIT 1", p.scopeName, models.Collections.User)
|
||||||
q, err := p.db.Query(query, &gocb.QueryOptions{
|
q, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
@@ -139,7 +135,6 @@ func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +169,6 @@ func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{},
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +188,5 @@ func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
@@ -13,11 +13,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddVerification to save verification request in database
|
// AddVerification to save verification request in database
|
||||||
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) (models.VerificationRequest, error) {
|
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) (*models.VerificationRequest, error) {
|
||||||
if verificationRequest.ID == "" {
|
if verificationRequest.ID == "" {
|
||||||
verificationRequest.ID = uuid.New().String()
|
verificationRequest.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest.Key = verificationRequest.ID
|
verificationRequest.Key = verificationRequest.ID
|
||||||
verificationRequest.CreatedAt = time.Now().Unix()
|
verificationRequest.CreatedAt = time.Now().Unix()
|
||||||
verificationRequest.UpdatedAt = time.Now().Unix()
|
verificationRequest.UpdatedAt = time.Now().Unix()
|
||||||
@@ -28,13 +27,12 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return verificationRequest, err
|
return verificationRequest, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByToken to get verification request from database using token
|
// GetVerificationRequestByToken to get verification request from database using token
|
||||||
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error) {
|
||||||
verificationRequest := models.VerificationRequest{}
|
var verificationRequest *models.VerificationRequest
|
||||||
params := make(map[string]interface{}, 1)
|
params := make(map[string]interface{}, 1)
|
||||||
params["token"] = token
|
params["token"] = token
|
||||||
query := fmt.Sprintf("SELECT _id, token, identifier, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s.%s WHERE token=$1 LIMIT 1", p.scopeName, models.Collections.VerificationRequest)
|
query := fmt.Sprintf("SELECT _id, token, identifier, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s.%s WHERE token=$1 LIMIT 1", p.scopeName, models.Collections.VerificationRequest)
|
||||||
@@ -57,7 +55,7 @@ func (p *provider) GetVerificationRequestByToken(ctx context.Context, token stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByEmail to get verification request by email from database
|
// GetVerificationRequestByEmail to get verification request by email from database
|
||||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||||
|
|
||||||
query := fmt.Sprintf("SELECT _id, identifier, token, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s.%s WHERE email=$1 AND identifier=$2 LIMIT 1", p.scopeName, models.Collections.VerificationRequest)
|
query := fmt.Sprintf("SELECT _id, identifier, token, expires_at, email, nonce, redirect_uri, created_at, updated_at FROM %s.%s WHERE email=$1 AND identifier=$2 LIMIT 1", p.scopeName, models.Collections.VerificationRequest)
|
||||||
queryResult, err := p.db.Query(query, &gocb.QueryOptions{
|
queryResult, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
@@ -65,14 +63,11 @@ func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email stri
|
|||||||
PositionalParameters: []interface{}{email, identifier},
|
PositionalParameters: []interface{}{email, identifier},
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
})
|
})
|
||||||
verificationRequest := models.VerificationRequest{}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return verificationRequest, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var verificationRequest *models.VerificationRequest
|
||||||
err = queryResult.One(&verificationRequest)
|
err = queryResult.One(&verificationRequest)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return verificationRequest, err
|
return verificationRequest, err
|
||||||
}
|
}
|
||||||
@@ -80,7 +75,7 @@ func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListVerificationRequests to get list of verification requests from database
|
// ListVerificationRequests to get list of verification requests from database
|
||||||
func (p *provider) ListVerificationRequests(ctx context.Context, pagination model.Pagination) (*model.VerificationRequests, error) {
|
func (p *provider) ListVerificationRequests(ctx context.Context, pagination *model.Pagination) (*model.VerificationRequests, error) {
|
||||||
var verificationRequests []*model.VerificationRequest
|
var verificationRequests []*model.VerificationRequest
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
total, err := p.GetTotalDocs(ctx, models.Collections.VerificationRequest)
|
total, err := p.GetTotalDocs(ctx, models.Collections.VerificationRequest)
|
||||||
@@ -111,12 +106,12 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination mode
|
|||||||
}
|
}
|
||||||
return &model.VerificationRequests{
|
return &model.VerificationRequests{
|
||||||
VerificationRequests: verificationRequests,
|
VerificationRequests: verificationRequests,
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteVerificationRequest to delete verification request from database
|
// DeleteVerificationRequest to delete verification request from database
|
||||||
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) error {
|
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) error {
|
||||||
removeOpt := gocb.RemoveOptions{
|
removeOpt := gocb.RemoveOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhook to add webhook
|
// AddWebhook to add webhook
|
||||||
func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) AddWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
if webhook.ID == "" {
|
if webhook.ID == "" {
|
||||||
webhook.ID = uuid.New().String()
|
webhook.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWebhook to update webhook
|
// UpdateWebhook to update webhook
|
||||||
func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) UpdateWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
// Event is changed
|
// Event is changed
|
||||||
if !strings.Contains(webhook.EventName, "-") {
|
if !strings.Contains(webhook.EventName, "-") {
|
||||||
@@ -68,7 +68,7 @@ func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhooks to list webhook
|
// ListWebhooks to list webhook
|
||||||
func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination) (*model.Webhooks, error) {
|
func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination) (*model.Webhooks, error) {
|
||||||
webhooks := []*model.Webhook{}
|
webhooks := []*model.Webhook{}
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
params := make(map[string]interface{}, 1)
|
params := make(map[string]interface{}, 1)
|
||||||
@@ -100,14 +100,14 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &model.Webhooks{
|
return &model.Webhooks{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Webhooks: webhooks,
|
Webhooks: webhooks,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWebhookByID to get webhook by id
|
// GetWebhookByID to get webhook by id
|
||||||
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
params := make(map[string]interface{}, 1)
|
params := make(map[string]interface{}, 1)
|
||||||
params["_id"] = webhookID
|
params["_id"] = webhookID
|
||||||
query := fmt.Sprintf(`SELECT _id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s.%s WHERE _id=$_id LIMIT 1`, p.scopeName, models.Collections.Webhook)
|
query := fmt.Sprintf(`SELECT _id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s.%s WHERE _id=$_id LIMIT 1`, p.scopeName, models.Collections.Webhook)
|
||||||
@@ -141,7 +141,7 @@ func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string)
|
|||||||
}
|
}
|
||||||
webhooks := []*model.Webhook{}
|
webhooks := []*model.Webhook{}
|
||||||
for queryResult.Next() {
|
for queryResult.Next() {
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
err := queryResult.Row(&webhook)
|
err := queryResult.Row(&webhook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -162,11 +162,9 @@ func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) er
|
|||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
_, err := p.db.Collection(models.Collections.Webhook).Remove(webhook.ID, &removeOpt)
|
_, err := p.db.Collection(models.Collections.Webhook).Remove(webhook.ID, &removeOpt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
query := fmt.Sprintf(`DELETE FROM %s.%s WHERE webhook_id=$webhook_id`, p.scopeName, models.Collections.WebhookLog)
|
query := fmt.Sprintf(`DELETE FROM %s.%s WHERE webhook_id=$webhook_id`, p.scopeName, models.Collections.WebhookLog)
|
||||||
_, err = p.db.Query(query, &gocb.QueryOptions{
|
_, err = p.db.Query(query, &gocb.QueryOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
@@ -176,6 +174,5 @@ func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -13,15 +13,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhookLog to add webhook log
|
// AddWebhookLog to add webhook log
|
||||||
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookLog) (*model.WebhookLog, error) {
|
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.WebhookLog) (*model.WebhookLog, error) {
|
||||||
if webhookLog.ID == "" {
|
if webhookLog.ID == "" {
|
||||||
webhookLog.ID = uuid.New().String()
|
webhookLog.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
webhookLog.Key = webhookLog.ID
|
webhookLog.Key = webhookLog.ID
|
||||||
webhookLog.CreatedAt = time.Now().Unix()
|
webhookLog.CreatedAt = time.Now().Unix()
|
||||||
webhookLog.UpdatedAt = time.Now().Unix()
|
webhookLog.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
insertOpt := gocb.InsertOptions{
|
insertOpt := gocb.InsertOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
@@ -29,19 +27,16 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookL
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return webhookLog.AsAPIWebhookLog(), err
|
return webhookLog.AsAPIWebhookLog(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
return webhookLog.AsAPIWebhookLog(), nil
|
return webhookLog.AsAPIWebhookLog(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhookLogs to list webhook logs
|
// ListWebhookLogs to list webhook logs
|
||||||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||||
var query string
|
var query string
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
webhookLogs := []*model.WebhookLog{}
|
webhookLogs := []*model.WebhookLog{}
|
||||||
params := make(map[string]interface{}, 1)
|
params := make(map[string]interface{}, 1)
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
|
|
||||||
params["webhookID"] = webhookID
|
params["webhookID"] = webhookID
|
||||||
params["offset"] = paginationClone.Offset
|
params["offset"] = paginationClone.Offset
|
||||||
params["limit"] = paginationClone.Limit
|
params["limit"] = paginationClone.Limit
|
||||||
@@ -55,13 +50,11 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
|||||||
} else {
|
} else {
|
||||||
query = fmt.Sprintf("SELECT _id, http_status, response, request, webhook_id, created_at, updated_at FROM %s.%s OFFSET $offset LIMIT $limit", p.scopeName, models.Collections.WebhookLog)
|
query = fmt.Sprintf("SELECT _id, http_status, response, request, webhook_id, created_at, updated_at FROM %s.%s OFFSET $offset LIMIT $limit", p.scopeName, models.Collections.WebhookLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
queryResult, err := p.db.Query(query, &gocb.QueryOptions{
|
queryResult, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
NamedParameters: params,
|
NamedParameters: params,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -73,13 +66,12 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
|||||||
}
|
}
|
||||||
webhookLogs = append(webhookLogs, webhookLog.AsAPIWebhookLog())
|
webhookLogs = append(webhookLogs, webhookLog.AsAPIWebhookLog())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := queryResult.Err(); err != nil {
|
if err := queryResult.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
||||||
}
|
}
|
||||||
return &model.WebhookLogs{
|
return &model.WebhookLogs{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
WebhookLogs: webhookLogs,
|
WebhookLogs: webhookLogs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEmailTemplate to add EmailTemplate
|
// AddEmailTemplate to add EmailTemplate
|
||||||
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
collection := p.db.Table(models.Collections.EmailTemplate)
|
collection := p.db.Table(models.Collections.EmailTemplate)
|
||||||
if emailTemplate.ID == "" {
|
if emailTemplate.ID == "" {
|
||||||
emailTemplate.ID = uuid.New().String()
|
emailTemplate.ID = uuid.New().String()
|
||||||
@@ -31,7 +31,7 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.Em
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEmailTemplate to update EmailTemplate
|
// UpdateEmailTemplate to update EmailTemplate
|
||||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
collection := p.db.Table(models.Collections.EmailTemplate)
|
collection := p.db.Table(models.Collections.EmailTemplate)
|
||||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||||
err := UpdateByHashKey(collection, "id", emailTemplate.ID, emailTemplate)
|
err := UpdateByHashKey(collection, "id", emailTemplate.ID, emailTemplate)
|
||||||
@@ -42,23 +42,19 @@ func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListEmailTemplates to list EmailTemplate
|
// ListEmailTemplates to list EmailTemplate
|
||||||
func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagination) (*model.EmailTemplates, error) {
|
func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagination) (*model.EmailTemplates, error) {
|
||||||
|
var emailTemplate *models.EmailTemplate
|
||||||
var emailTemplate models.EmailTemplate
|
|
||||||
var iter dynamo.PagingIter
|
var iter dynamo.PagingIter
|
||||||
var lastEval dynamo.PagingKey
|
var lastEval dynamo.PagingKey
|
||||||
var iteration int64 = 0
|
var iteration int64 = 0
|
||||||
|
|
||||||
collection := p.db.Table(models.Collections.EmailTemplate)
|
collection := p.db.Table(models.Collections.EmailTemplate)
|
||||||
emailTemplates := []*model.EmailTemplate{}
|
emailTemplates := []*model.EmailTemplate{}
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
scanner := collection.Scan()
|
scanner := collection.Scan()
|
||||||
count, err := scanner.Count()
|
count, err := scanner.Count()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for (paginationClone.Offset + paginationClone.Limit) > iteration {
|
for (paginationClone.Offset + paginationClone.Limit) > iteration {
|
||||||
iter = scanner.StartFrom(lastEval).Limit(paginationClone.Limit).Iter()
|
iter = scanner.StartFrom(lastEval).Limit(paginationClone.Limit).Iter()
|
||||||
for iter.NextWithContext(ctx, &emailTemplate) {
|
for iter.NextWithContext(ctx, &emailTemplate) {
|
||||||
@@ -69,11 +65,9 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagin
|
|||||||
lastEval = iter.LastEvaluatedKey()
|
lastEval = iter.LastEvaluatedKey()
|
||||||
iteration += paginationClone.Limit
|
iteration += paginationClone.Limit
|
||||||
}
|
}
|
||||||
|
|
||||||
paginationClone.Total = count
|
paginationClone.Total = count
|
||||||
|
|
||||||
return &model.EmailTemplates{
|
return &model.EmailTemplates{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
EmailTemplates: emailTemplates,
|
EmailTemplates: emailTemplates,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -81,7 +75,7 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagin
|
|||||||
// GetEmailTemplateByID to get EmailTemplate by id
|
// GetEmailTemplateByID to get EmailTemplate by id
|
||||||
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
||||||
collection := p.db.Table(models.Collections.EmailTemplate)
|
collection := p.db.Table(models.Collections.EmailTemplate)
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
err := collection.Get("id", emailTemplateID).OneWithContext(ctx, &emailTemplate)
|
err := collection.Get("id", emailTemplateID).OneWithContext(ctx, &emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -92,9 +86,8 @@ func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID str
|
|||||||
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
||||||
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
||||||
collection := p.db.Table(models.Collections.EmailTemplate)
|
collection := p.db.Table(models.Collections.EmailTemplate)
|
||||||
var emailTemplates []models.EmailTemplate
|
var emailTemplates []*models.EmailTemplate
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
|
|
||||||
err := collection.Scan().Index("event_name").Filter("'event_name' = ?", eventName).Limit(1).AllWithContext(ctx, &emailTemplates)
|
err := collection.Scan().Index("event_name").Filter("'event_name' = ?", eventName).Limit(1).AllWithContext(ctx, &emailTemplates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -112,7 +105,6 @@ func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName st
|
|||||||
func (p *provider) DeleteEmailTemplate(ctx context.Context, emailTemplate *model.EmailTemplate) error {
|
func (p *provider) DeleteEmailTemplate(ctx context.Context, emailTemplate *model.EmailTemplate) error {
|
||||||
collection := p.db.Table(models.Collections.EmailTemplate)
|
collection := p.db.Table(models.Collections.EmailTemplate)
|
||||||
err := collection.Delete("id", emailTemplate.ID).RunWithContext(ctx)
|
err := collection.Delete("id", emailTemplate.ID).RunWithContext(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -11,34 +11,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEnv to save environment information in database
|
// AddEnv to save environment information in database
|
||||||
func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
collection := p.db.Table(models.Collections.Env)
|
collection := p.db.Table(models.Collections.Env)
|
||||||
|
|
||||||
if env.ID == "" {
|
if env.ID == "" {
|
||||||
env.ID = uuid.New().String()
|
env.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
env.Key = env.ID
|
env.Key = env.ID
|
||||||
|
|
||||||
env.CreatedAt = time.Now().Unix()
|
env.CreatedAt = time.Now().Unix()
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
err := collection.Put(env).RunWithContext(ctx)
|
err := collection.Put(env).RunWithContext(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return env, err
|
return env, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEnv to update environment information in database
|
// UpdateEnv to update environment information in database
|
||||||
func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
collection := p.db.Table(models.Collections.Env)
|
collection := p.db.Table(models.Collections.Env)
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
err := UpdateByHashKey(collection, "id", env.ID, env)
|
err := UpdateByHashKey(collection, "id", env.ID, env)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return env, err
|
return env, err
|
||||||
}
|
}
|
||||||
@@ -46,26 +38,21 @@ func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEnv to get environment information from database
|
// GetEnv to get environment information from database
|
||||||
func (p *provider) GetEnv(ctx context.Context) (models.Env, error) {
|
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||||
var env models.Env
|
var env *models.Env
|
||||||
|
|
||||||
collection := p.db.Table(models.Collections.Env)
|
collection := p.db.Table(models.Collections.Env)
|
||||||
// As there is no Findone supported.
|
// As there is no Findone supported.
|
||||||
iter := collection.Scan().Limit(1).Iter()
|
iter := collection.Scan().Limit(1).Iter()
|
||||||
|
|
||||||
for iter.NextWithContext(ctx, &env) {
|
for iter.NextWithContext(ctx, &env) {
|
||||||
if env.ID == "" {
|
if env == nil {
|
||||||
return env, errors.New("no documets found")
|
return env, errors.New("no documets found")
|
||||||
} else {
|
} else {
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := iter.Err()
|
err := iter.Err()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return env, fmt.Errorf("config not found")
|
return env, fmt.Errorf("config not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
|
@@ -91,7 +91,6 @@ func (p *provider) GetOTPByPhoneNumber(ctx context.Context, phoneNumber string)
|
|||||||
// DeleteOTP to delete otp
|
// DeleteOTP to delete otp
|
||||||
func (p *provider) DeleteOTP(ctx context.Context, otp *models.OTP) error {
|
func (p *provider) DeleteOTP(ctx context.Context, otp *models.OTP) error {
|
||||||
collection := p.db.Table(models.Collections.OTP)
|
collection := p.db.Table(models.Collections.OTP)
|
||||||
|
|
||||||
if otp.ID != "" {
|
if otp.ID != "" {
|
||||||
err := collection.Delete("id", otp.ID).RunWithContext(ctx)
|
err := collection.Delete("id", otp.ID).RunWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -42,10 +42,8 @@ func NewProvider() (*provider, error) {
|
|||||||
} else {
|
} else {
|
||||||
log.Debugf("%s or %s or %s not found. Trying to load default credentials from aws config", constants.EnvAwsRegion, constants.EnvAwsAccessKeyID, constants.EnvAwsSecretAccessKey)
|
log.Debugf("%s or %s or %s not found. Trying to load default credentials from aws config", constants.EnvAwsRegion, constants.EnvAwsAccessKeyID, constants.EnvAwsSecretAccessKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
session := session.Must(session.NewSession(&config))
|
session := session.Must(session.NewSession(&config))
|
||||||
db := dynamo.New(session)
|
db := dynamo.New(session)
|
||||||
|
|
||||||
db.CreateTable(models.Collections.User, models.User{}).Wait()
|
db.CreateTable(models.Collections.User, models.User{}).Wait()
|
||||||
db.CreateTable(models.Collections.Session, models.Session{}).Wait()
|
db.CreateTable(models.Collections.Session, models.Session{}).Wait()
|
||||||
db.CreateTable(models.Collections.EmailTemplate, models.EmailTemplate{}).Wait()
|
db.CreateTable(models.Collections.EmailTemplate, models.EmailTemplate{}).Wait()
|
||||||
@@ -54,7 +52,6 @@ func NewProvider() (*provider, error) {
|
|||||||
db.CreateTable(models.Collections.VerificationRequest, models.VerificationRequest{}).Wait()
|
db.CreateTable(models.Collections.VerificationRequest, models.VerificationRequest{}).Wait()
|
||||||
db.CreateTable(models.Collections.Webhook, models.Webhook{}).Wait()
|
db.CreateTable(models.Collections.Webhook, models.Webhook{}).Wait()
|
||||||
db.CreateTable(models.Collections.WebhookLog, models.WebhookLog{}).Wait()
|
db.CreateTable(models.Collections.WebhookLog, models.WebhookLog{}).Wait()
|
||||||
|
|
||||||
return &provider{
|
return &provider{
|
||||||
db: db,
|
db: db,
|
||||||
}, nil
|
}, nil
|
||||||
|
@@ -9,13 +9,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddSession to save session information in database
|
// AddSession to save session information in database
|
||||||
func (p *provider) AddSession(ctx context.Context, session models.Session) error {
|
func (p *provider) AddSession(ctx context.Context, session *models.Session) error {
|
||||||
collection := p.db.Table(models.Collections.Session)
|
collection := p.db.Table(models.Collections.Session)
|
||||||
|
|
||||||
if session.ID == "" {
|
if session.ID == "" {
|
||||||
session.ID = uuid.New().String()
|
session.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
session.CreatedAt = time.Now().Unix()
|
session.CreatedAt = time.Now().Unix()
|
||||||
session.UpdatedAt = time.Now().Unix()
|
session.UpdatedAt = time.Now().Unix()
|
||||||
err := collection.Put(session).RunWithContext(ctx)
|
err := collection.Put(session).RunWithContext(ctx)
|
||||||
|
@@ -9,16 +9,13 @@ import (
|
|||||||
func UpdateByHashKey(table dynamo.Table, hashKey string, hashValue string, item interface{}) error {
|
func UpdateByHashKey(table dynamo.Table, hashKey string, hashValue string, item interface{}) error {
|
||||||
existingValue, err := dynamo.MarshalItem(item)
|
existingValue, err := dynamo.MarshalItem(item)
|
||||||
var i interface{}
|
var i interface{}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nullableValue, err := dynamodbattribute.MarshalMap(item)
|
nullableValue, err := dynamodbattribute.MarshalMap(item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
u := table.Update(hashKey, hashValue)
|
u := table.Update(hashKey, hashValue)
|
||||||
for k, v := range existingValue {
|
for k, v := range existingValue {
|
||||||
if k == hashKey {
|
if k == hashKey {
|
||||||
@@ -26,7 +23,6 @@ func UpdateByHashKey(table dynamo.Table, hashKey string, hashValue string, item
|
|||||||
}
|
}
|
||||||
u = u.Set(k, v)
|
u = u.Set(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range nullableValue {
|
for k, v := range nullableValue {
|
||||||
if k == hashKey {
|
if k == hashKey {
|
||||||
continue
|
continue
|
||||||
@@ -36,11 +32,9 @@ func UpdateByHashKey(table dynamo.Table, hashKey string, hashValue string, item
|
|||||||
u = u.SetNullable(k, v)
|
u = u.SetNullable(k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = u.Run()
|
err = u.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -18,13 +18,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddUser to save user information in database
|
// AddUser to save user information in database
|
||||||
func (p *provider) AddUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) AddUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
collection := p.db.Table(models.Collections.User)
|
collection := p.db.Table(models.Collections.User)
|
||||||
|
|
||||||
if user.ID == "" {
|
if user.ID == "" {
|
||||||
user.ID = uuid.New().String()
|
user.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.Roles == "" {
|
if user.Roles == "" {
|
||||||
defaultRoles, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
defaultRoles, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -32,18 +30,14 @@ func (p *provider) AddUser(ctx context.Context, user models.User) (models.User,
|
|||||||
}
|
}
|
||||||
user.Roles = defaultRoles
|
user.Roles = defaultRoles
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.PhoneNumber != nil && strings.TrimSpace(refs.StringValue(user.PhoneNumber)) != "" {
|
if user.PhoneNumber != nil && strings.TrimSpace(refs.StringValue(user.PhoneNumber)) != "" {
|
||||||
if u, _ := p.GetUserByPhoneNumber(ctx, refs.StringValue(user.PhoneNumber)); u != nil {
|
if u, _ := p.GetUserByPhoneNumber(ctx, refs.StringValue(user.PhoneNumber)); u != nil {
|
||||||
return user, fmt.Errorf("user with given phone number already exists")
|
return user, fmt.Errorf("user with given phone number already exists")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user.CreatedAt = time.Now().Unix()
|
user.CreatedAt = time.Now().Unix()
|
||||||
user.UpdatedAt = time.Now().Unix()
|
user.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
err := collection.Put(user).RunWithContext(ctx)
|
err := collection.Put(user).RunWithContext(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
@@ -51,18 +45,14 @@ func (p *provider) AddUser(ctx context.Context, user models.User) (models.User,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser to update user information in database
|
// UpdateUser to update user information in database
|
||||||
func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) UpdateUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
collection := p.db.Table(models.Collections.User)
|
collection := p.db.Table(models.Collections.User)
|
||||||
|
|
||||||
if user.ID != "" {
|
if user.ID != "" {
|
||||||
|
|
||||||
user.UpdatedAt = time.Now().Unix()
|
user.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
err := UpdateByHashKey(collection, "id", user.ID, user)
|
err := UpdateByHashKey(collection, "id", user.ID, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
@@ -72,18 +62,15 @@ func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.Use
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUser to delete user information from database
|
// DeleteUser to delete user information from database
|
||||||
func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
||||||
collection := p.db.Table(models.Collections.User)
|
collection := p.db.Table(models.Collections.User)
|
||||||
sessionCollection := p.db.Table(models.Collections.Session)
|
sessionCollection := p.db.Table(models.Collections.Session)
|
||||||
|
|
||||||
if user.ID != "" {
|
if user.ID != "" {
|
||||||
err := collection.Delete("id", user.ID).Run()
|
err := collection.Delete("id", user.ID).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = sessionCollection.Batch("id").Write().Delete(dynamo.Keys{"user_id", user.ID}).RunWithContext(ctx)
|
_, err = sessionCollection.Batch("id").Write().Delete(dynamo.Keys{"user_id", user.ID}).RunWithContext(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -92,23 +79,19 @@ func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListUsers to get list of users from database
|
// ListUsers to get list of users from database
|
||||||
func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (*model.Users, error) {
|
func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination) (*model.Users, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
var lastEval dynamo.PagingKey
|
var lastEval dynamo.PagingKey
|
||||||
var iter dynamo.PagingIter
|
var iter dynamo.PagingIter
|
||||||
var iteration int64 = 0
|
var iteration int64 = 0
|
||||||
|
|
||||||
collection := p.db.Table(models.Collections.User)
|
collection := p.db.Table(models.Collections.User)
|
||||||
users := []*model.User{}
|
users := []*model.User{}
|
||||||
|
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
scanner := collection.Scan()
|
scanner := collection.Scan()
|
||||||
count, err := scanner.Count()
|
count, err := scanner.Count()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for (paginationClone.Offset + paginationClone.Limit) > iteration {
|
for (paginationClone.Offset + paginationClone.Limit) > iteration {
|
||||||
iter = scanner.StartFrom(lastEval).Limit(paginationClone.Limit).Iter()
|
iter = scanner.StartFrom(lastEval).Limit(paginationClone.Limit).Iter()
|
||||||
for iter.NextWithContext(ctx, &user) {
|
for iter.NextWithContext(ctx, &user) {
|
||||||
@@ -119,48 +102,39 @@ func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (
|
|||||||
lastEval = iter.LastEvaluatedKey()
|
lastEval = iter.LastEvaluatedKey()
|
||||||
iteration += paginationClone.Limit
|
iteration += paginationClone.Limit
|
||||||
}
|
}
|
||||||
|
|
||||||
err = iter.Err()
|
err = iter.Err()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
paginationClone.Total = count
|
paginationClone.Total = count
|
||||||
|
|
||||||
return &model.Users{
|
return &model.Users{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Users: users,
|
Users: users,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByEmail to get user information from database using email address
|
// GetUserByEmail to get user information from database using email address
|
||||||
func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.User, error) {
|
func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.User, error) {
|
||||||
var users []models.User
|
var users []*models.User
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
collection := p.db.Table(models.Collections.User)
|
collection := p.db.Table(models.Collections.User)
|
||||||
err := collection.Scan().Index("email").Filter("'email' = ?", email).AllWithContext(ctx, &users)
|
err := collection.Scan().Index("email").Filter("'email' = ?", email).AllWithContext(ctx, &users)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(users) > 0 {
|
if len(users) > 0 {
|
||||||
user = users[0]
|
user = users[0]
|
||||||
return user, nil
|
return user, nil
|
||||||
} else {
|
} else {
|
||||||
return user, errors.New("no record found")
|
return user, errors.New("no record found")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByID to get user information from database using user ID
|
// GetUserByID to get user information from database using user ID
|
||||||
func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, error) {
|
func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, error) {
|
||||||
collection := p.db.Table(models.Collections.User)
|
collection := p.db.Table(models.Collections.User)
|
||||||
var user models.User
|
var user *models.User
|
||||||
err := collection.Get("id", id).OneWithContext(ctx, &user)
|
err := collection.Get("id", id).OneWithContext(ctx, &user)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user.Email == "" {
|
if user.Email == "" {
|
||||||
return user, errors.New("no documets found")
|
return user, errors.New("no documets found")
|
||||||
@@ -186,7 +160,6 @@ func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{},
|
|||||||
} else {
|
} else {
|
||||||
// as there is no facility to update all doc - https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SQLtoNoSQL.UpdateData.html
|
// as there is no facility to update all doc - https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SQLtoNoSQL.UpdateData.html
|
||||||
userCollection.Scan().All(&allUsers)
|
userCollection.Scan().All(&allUsers)
|
||||||
|
|
||||||
for _, user := range allUsers {
|
for _, user := range allUsers {
|
||||||
err = UpdateByHashKey(userCollection, "id", user.ID, data)
|
err = UpdateByHashKey(userCollection, "id", user.ID, data)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -194,7 +167,6 @@ func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{},
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
@@ -205,19 +177,16 @@ func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{},
|
|||||||
|
|
||||||
// GetUserByPhoneNumber to get user information from database using phone number
|
// GetUserByPhoneNumber to get user information from database using phone number
|
||||||
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
||||||
var users []models.User
|
var users []*models.User
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
collection := p.db.Table(models.Collections.User)
|
collection := p.db.Table(models.Collections.User)
|
||||||
err := collection.Scan().Filter("'phone_number' = ?", phoneNumber).AllWithContext(ctx, &users)
|
err := collection.Scan().Filter("'phone_number' = ?", phoneNumber).AllWithContext(ctx, &users)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(users) > 0 {
|
if len(users) > 0 {
|
||||||
user = users[0]
|
user = users[0]
|
||||||
return &user, nil
|
return user, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("no record found")
|
return nil, errors.New("no record found")
|
||||||
}
|
}
|
||||||
|
@@ -11,9 +11,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddVerification to save verification request in database
|
// AddVerification to save verification request in database
|
||||||
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) (models.VerificationRequest, error) {
|
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) (*models.VerificationRequest, error) {
|
||||||
collection := p.db.Table(models.Collections.VerificationRequest)
|
collection := p.db.Table(models.Collections.VerificationRequest)
|
||||||
|
|
||||||
if verificationRequest.ID == "" {
|
if verificationRequest.ID == "" {
|
||||||
verificationRequest.ID = uuid.New().String()
|
verificationRequest.ID = uuid.New().String()
|
||||||
verificationRequest.CreatedAt = time.Now().Unix()
|
verificationRequest.CreatedAt = time.Now().Unix()
|
||||||
@@ -23,20 +22,17 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||||||
return verificationRequest, err
|
return verificationRequest, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByToken to get verification request from database using token
|
// GetVerificationRequestByToken to get verification request from database using token
|
||||||
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error) {
|
||||||
collection := p.db.Table(models.Collections.VerificationRequest)
|
collection := p.db.Table(models.Collections.VerificationRequest)
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
|
|
||||||
iter := collection.Scan().Filter("'token' = ?", token).Iter()
|
iter := collection.Scan().Filter("'token' = ?", token).Iter()
|
||||||
for iter.NextWithContext(ctx, &verificationRequest) {
|
for iter.NextWithContext(ctx, &verificationRequest) {
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := iter.Err()
|
err := iter.Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return verificationRequest, err
|
return verificationRequest, err
|
||||||
@@ -45,14 +41,13 @@ func (p *provider) GetVerificationRequestByToken(ctx context.Context, token stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByEmail to get verification request by email from database
|
// GetVerificationRequestByEmail to get verification request by email from database
|
||||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
collection := p.db.Table(models.Collections.VerificationRequest)
|
collection := p.db.Table(models.Collections.VerificationRequest)
|
||||||
iter := collection.Scan().Filter("'email' = ?", email).Filter("'identifier' = ?", identifier).Iter()
|
iter := collection.Scan().Filter("'email' = ?", email).Filter("'identifier' = ?", identifier).Iter()
|
||||||
for iter.NextWithContext(ctx, &verificationRequest) {
|
for iter.NextWithContext(ctx, &verificationRequest) {
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := iter.Err()
|
err := iter.Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return verificationRequest, err
|
return verificationRequest, err
|
||||||
@@ -61,23 +56,19 @@ func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListVerificationRequests to get list of verification requests from database
|
// ListVerificationRequests to get list of verification requests from database
|
||||||
func (p *provider) ListVerificationRequests(ctx context.Context, pagination model.Pagination) (*model.VerificationRequests, error) {
|
func (p *provider) ListVerificationRequests(ctx context.Context, pagination *model.Pagination) (*model.VerificationRequests, error) {
|
||||||
verificationRequests := []*model.VerificationRequest{}
|
verificationRequests := []*model.VerificationRequest{}
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
var lastEval dynamo.PagingKey
|
var lastEval dynamo.PagingKey
|
||||||
var iter dynamo.PagingIter
|
var iter dynamo.PagingIter
|
||||||
var iteration int64 = 0
|
var iteration int64 = 0
|
||||||
|
|
||||||
collection := p.db.Table(models.Collections.VerificationRequest)
|
collection := p.db.Table(models.Collections.VerificationRequest)
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
|
|
||||||
scanner := collection.Scan()
|
scanner := collection.Scan()
|
||||||
count, err := scanner.Count()
|
count, err := scanner.Count()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for (paginationClone.Offset + paginationClone.Limit) > iteration {
|
for (paginationClone.Offset + paginationClone.Limit) > iteration {
|
||||||
iter = scanner.StartFrom(lastEval).Limit(paginationClone.Limit).Iter()
|
iter = scanner.StartFrom(lastEval).Limit(paginationClone.Limit).Iter()
|
||||||
for iter.NextWithContext(ctx, &verificationRequest) {
|
for iter.NextWithContext(ctx, &verificationRequest) {
|
||||||
@@ -92,20 +83,17 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination mode
|
|||||||
lastEval = iter.LastEvaluatedKey()
|
lastEval = iter.LastEvaluatedKey()
|
||||||
iteration += paginationClone.Limit
|
iteration += paginationClone.Limit
|
||||||
}
|
}
|
||||||
|
|
||||||
paginationClone.Total = count
|
paginationClone.Total = count
|
||||||
|
|
||||||
return &model.VerificationRequests{
|
return &model.VerificationRequests{
|
||||||
VerificationRequests: verificationRequests,
|
VerificationRequests: verificationRequests,
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteVerificationRequest to delete verification request from database
|
// DeleteVerificationRequest to delete verification request from database
|
||||||
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) error {
|
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) error {
|
||||||
collection := p.db.Table(models.Collections.VerificationRequest)
|
collection := p.db.Table(models.Collections.VerificationRequest)
|
||||||
|
if verificationRequest != nil {
|
||||||
if verificationRequest.ID != "" {
|
|
||||||
err := collection.Delete("id", verificationRequest.ID).RunWithContext(ctx)
|
err := collection.Delete("id", verificationRequest.ID).RunWithContext(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhook to add webhook
|
// AddWebhook to add webhook
|
||||||
func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) AddWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
collection := p.db.Table(models.Collections.Webhook)
|
collection := p.db.Table(models.Collections.Webhook)
|
||||||
if webhook.ID == "" {
|
if webhook.ID == "" {
|
||||||
webhook.ID = uuid.New().String()
|
webhook.ID = uuid.New().String()
|
||||||
@@ -33,7 +33,7 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWebhook to update webhook
|
// UpdateWebhook to update webhook
|
||||||
func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) UpdateWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
// Event is changed
|
// Event is changed
|
||||||
if !strings.Contains(webhook.EventName, "-") {
|
if !strings.Contains(webhook.EventName, "-") {
|
||||||
@@ -48,9 +48,9 @@ func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhooks to list webhook
|
// ListWebhooks to list webhook
|
||||||
func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination) (*model.Webhooks, error) {
|
func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination) (*model.Webhooks, error) {
|
||||||
webhooks := []*model.Webhook{}
|
webhooks := []*model.Webhook{}
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
var lastEval dynamo.PagingKey
|
var lastEval dynamo.PagingKey
|
||||||
var iter dynamo.PagingIter
|
var iter dynamo.PagingIter
|
||||||
var iteration int64 = 0
|
var iteration int64 = 0
|
||||||
@@ -77,7 +77,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
|||||||
}
|
}
|
||||||
paginationClone.Total = count
|
paginationClone.Total = count
|
||||||
return &model.Webhooks{
|
return &model.Webhooks{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Webhooks: webhooks,
|
Webhooks: webhooks,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
|||||||
// GetWebhookByID to get webhook by id
|
// GetWebhookByID to get webhook by id
|
||||||
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
||||||
collection := p.db.Table(models.Collections.Webhook)
|
collection := p.db.Table(models.Collections.Webhook)
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
err := collection.Get("id", webhookID).OneWithContext(ctx, &webhook)
|
err := collection.Get("id", webhookID).OneWithContext(ctx, &webhook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -114,14 +114,14 @@ func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string)
|
|||||||
// DeleteWebhook to delete webhook
|
// DeleteWebhook to delete webhook
|
||||||
func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) error {
|
func (p *provider) DeleteWebhook(ctx context.Context, webhook *model.Webhook) error {
|
||||||
// Also delete webhook logs for given webhook id
|
// Also delete webhook logs for given webhook id
|
||||||
if webhook.ID != "" {
|
if webhook != nil {
|
||||||
webhookCollection := p.db.Table(models.Collections.Webhook)
|
webhookCollection := p.db.Table(models.Collections.Webhook)
|
||||||
pagination := model.Pagination{}
|
|
||||||
webhookLogCollection := p.db.Table(models.Collections.WebhookLog)
|
webhookLogCollection := p.db.Table(models.Collections.WebhookLog)
|
||||||
err := webhookCollection.Delete("id", webhook.ID).RunWithContext(ctx)
|
err := webhookCollection.Delete("id", webhook.ID).RunWithContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
pagination := &model.Pagination{}
|
||||||
webhookLogs, errIs := p.ListWebhookLogs(ctx, pagination, webhook.ID)
|
webhookLogs, errIs := p.ListWebhookLogs(ctx, pagination, webhook.ID)
|
||||||
for _, webhookLog := range webhookLogs.WebhookLogs {
|
for _, webhookLog := range webhookLogs.WebhookLogs {
|
||||||
err = webhookLogCollection.Delete("id", webhookLog.ID).RunWithContext(ctx)
|
err = webhookLogCollection.Delete("id", webhookLog.ID).RunWithContext(ctx)
|
||||||
|
@@ -11,18 +11,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhookLog to add webhook log
|
// AddWebhookLog to add webhook log
|
||||||
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookLog) (*model.WebhookLog, error) {
|
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.WebhookLog) (*model.WebhookLog, error) {
|
||||||
collection := p.db.Table(models.Collections.WebhookLog)
|
collection := p.db.Table(models.Collections.WebhookLog)
|
||||||
|
|
||||||
if webhookLog.ID == "" {
|
if webhookLog.ID == "" {
|
||||||
webhookLog.ID = uuid.New().String()
|
webhookLog.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
webhookLog.Key = webhookLog.ID
|
webhookLog.Key = webhookLog.ID
|
||||||
webhookLog.CreatedAt = time.Now().Unix()
|
webhookLog.CreatedAt = time.Now().Unix()
|
||||||
webhookLog.UpdatedAt = time.Now().Unix()
|
webhookLog.UpdatedAt = time.Now().Unix()
|
||||||
err := collection.Put(webhookLog).RunWithContext(ctx)
|
err := collection.Put(webhookLog).RunWithContext(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -30,9 +27,9 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhookLogs to list webhook logs
|
// ListWebhookLogs to list webhook logs
|
||||||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||||
webhookLogs := []*model.WebhookLog{}
|
webhookLogs := []*model.WebhookLog{}
|
||||||
var webhookLog models.WebhookLog
|
var webhookLog *models.WebhookLog
|
||||||
var lastEval dynamo.PagingKey
|
var lastEval dynamo.PagingKey
|
||||||
var iter dynamo.PagingIter
|
var iter dynamo.PagingIter
|
||||||
var iteration int64 = 0
|
var iteration int64 = 0
|
||||||
@@ -42,7 +39,6 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
|||||||
collection := p.db.Table(models.Collections.WebhookLog)
|
collection := p.db.Table(models.Collections.WebhookLog)
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
scanner := collection.Scan()
|
scanner := collection.Scan()
|
||||||
|
|
||||||
if webhookID != "" {
|
if webhookID != "" {
|
||||||
iter = scanner.Index("webhook_id").Filter("'webhook_id' = ?", webhookID).Iter()
|
iter = scanner.Index("webhook_id").Filter("'webhook_id' = ?", webhookID).Iter()
|
||||||
for iter.NextWithContext(ctx, &webhookLog) {
|
for iter.NextWithContext(ctx, &webhookLog) {
|
||||||
@@ -68,11 +64,10 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
|||||||
iteration += paginationClone.Limit
|
iteration += paginationClone.Limit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paginationClone.Total = count
|
paginationClone.Total = count
|
||||||
// paginationClone.Cursor = iter.LastEvaluatedKey()
|
// paginationClone.Cursor = iter.LastEvaluatedKey()
|
||||||
return &model.WebhookLogs{
|
return &model.WebhookLogs{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
WebhookLogs: webhookLogs,
|
WebhookLogs: webhookLogs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -12,15 +12,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEmailTemplate to add EmailTemplate
|
// AddEmailTemplate to add EmailTemplate
|
||||||
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
if emailTemplate.ID == "" {
|
if emailTemplate.ID == "" {
|
||||||
emailTemplate.ID = uuid.New().String()
|
emailTemplate.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
emailTemplate.Key = emailTemplate.ID
|
emailTemplate.Key = emailTemplate.ID
|
||||||
emailTemplate.CreatedAt = time.Now().Unix()
|
emailTemplate.CreatedAt = time.Now().Unix()
|
||||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
||||||
_, err := emailTemplateCollection.InsertOne(ctx, emailTemplate)
|
_, err := emailTemplateCollection.InsertOne(ctx, emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -30,60 +28,52 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.Em
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEmailTemplate to update EmailTemplate
|
// UpdateEmailTemplate to update EmailTemplate
|
||||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
||||||
_, err := emailTemplateCollection.UpdateOne(ctx, bson.M{"_id": bson.M{"$eq": emailTemplate.ID}}, bson.M{"$set": emailTemplate}, options.MergeUpdateOptions())
|
_, err := emailTemplateCollection.UpdateOne(ctx, bson.M{"_id": bson.M{"$eq": emailTemplate.ID}}, bson.M{"$set": emailTemplate}, options.MergeUpdateOptions())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListEmailTemplates to list EmailTemplate
|
// ListEmailTemplates to list EmailTemplate
|
||||||
func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagination) (*model.EmailTemplates, error) {
|
func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagination) (*model.EmailTemplates, error) {
|
||||||
var emailTemplates []*model.EmailTemplate
|
var emailTemplates []*model.EmailTemplate
|
||||||
opts := options.Find()
|
opts := options.Find()
|
||||||
opts.SetLimit(pagination.Limit)
|
opts.SetLimit(pagination.Limit)
|
||||||
opts.SetSkip(pagination.Offset)
|
opts.SetSkip(pagination.Offset)
|
||||||
opts.SetSort(bson.M{"created_at": -1})
|
opts.SetSort(bson.M{"created_at": -1})
|
||||||
|
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
|
|
||||||
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
||||||
count, err := emailTemplateCollection.CountDocuments(ctx, bson.M{}, options.Count())
|
count, err := emailTemplateCollection.CountDocuments(ctx, bson.M{}, options.Count())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
paginationClone.Total = count
|
paginationClone.Total = count
|
||||||
|
|
||||||
cursor, err := emailTemplateCollection.Find(ctx, bson.M{}, opts)
|
cursor, err := emailTemplateCollection.Find(ctx, bson.M{}, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close(ctx)
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
for cursor.Next(ctx) {
|
for cursor.Next(ctx) {
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
err := cursor.Decode(&emailTemplate)
|
err := cursor.Decode(&emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
emailTemplates = append(emailTemplates, emailTemplate.AsAPIEmailTemplate())
|
emailTemplates = append(emailTemplates, emailTemplate.AsAPIEmailTemplate())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.EmailTemplates{
|
return &model.EmailTemplates{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
EmailTemplates: emailTemplates,
|
EmailTemplates: emailTemplates,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEmailTemplateByID to get EmailTemplate by id
|
// GetEmailTemplateByID to get EmailTemplate by id
|
||||||
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
||||||
err := emailTemplateCollection.FindOne(ctx, bson.M{"_id": emailTemplateID}).Decode(&emailTemplate)
|
err := emailTemplateCollection.FindOne(ctx, bson.M{"_id": emailTemplateID}).Decode(&emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -94,7 +84,7 @@ func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID str
|
|||||||
|
|
||||||
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
||||||
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
emailTemplateCollection := p.db.Collection(models.Collections.EmailTemplate, options.Collection())
|
||||||
err := emailTemplateCollection.FindOne(ctx, bson.M{"event_name": eventName}).Decode(&emailTemplate)
|
err := emailTemplateCollection.FindOne(ctx, bson.M{"event_name": eventName}).Decode(&emailTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -110,6 +100,5 @@ func (p *provider) DeleteEmailTemplate(ctx context.Context, emailTemplate *model
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -12,11 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEnv to save environment information in database
|
// AddEnv to save environment information in database
|
||||||
func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
if env.ID == "" {
|
if env.ID == "" {
|
||||||
env.ID = uuid.New().String()
|
env.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
env.CreatedAt = time.Now().Unix()
|
env.CreatedAt = time.Now().Unix()
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
env.Key = env.ID
|
env.Key = env.ID
|
||||||
@@ -29,7 +28,7 @@ func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEnv to update environment information in database
|
// UpdateEnv to update environment information in database
|
||||||
func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
configCollection := p.db.Collection(models.Collections.Env, options.Collection())
|
configCollection := p.db.Collection(models.Collections.Env, options.Collection())
|
||||||
_, err := configCollection.UpdateOne(ctx, bson.M{"_id": bson.M{"$eq": env.ID}}, bson.M{"$set": env}, options.MergeUpdateOptions())
|
_, err := configCollection.UpdateOne(ctx, bson.M{"_id": bson.M{"$eq": env.ID}}, bson.M{"$set": env}, options.MergeUpdateOptions())
|
||||||
@@ -40,25 +39,22 @@ func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEnv to get environment information from database
|
// GetEnv to get environment information from database
|
||||||
func (p *provider) GetEnv(ctx context.Context) (models.Env, error) {
|
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||||
var env models.Env
|
var env *models.Env
|
||||||
configCollection := p.db.Collection(models.Collections.Env, options.Collection())
|
configCollection := p.db.Collection(models.Collections.Env, options.Collection())
|
||||||
cursor, err := configCollection.Find(ctx, bson.M{}, options.Find())
|
cursor, err := configCollection.Find(ctx, bson.M{}, options.Find())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return env, err
|
return env, err
|
||||||
}
|
}
|
||||||
defer cursor.Close(ctx)
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
for cursor.Next(nil) {
|
for cursor.Next(nil) {
|
||||||
err := cursor.Decode(&env)
|
err := cursor.Decode(&env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return env, err
|
return env, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if env == nil {
|
||||||
if env.ID == "" {
|
|
||||||
return env, fmt.Errorf("config not found")
|
return env, fmt.Errorf("config not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddSession to save session information in database
|
// AddSession to save session information in database
|
||||||
func (p *provider) AddSession(ctx context.Context, session models.Session) error {
|
func (p *provider) AddSession(ctx context.Context, session *models.Session) error {
|
||||||
if session.ID == "" {
|
if session.ID == "" {
|
||||||
session.ID = uuid.New().String()
|
session.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -25,3 +25,8 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteSession to delete session information from database
|
||||||
|
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@@ -16,11 +16,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddUser to save user information in database
|
// AddUser to save user information in database
|
||||||
func (p *provider) AddUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) AddUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
if user.ID == "" {
|
if user.ID == "" {
|
||||||
user.ID = uuid.New().String()
|
user.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.Roles == "" {
|
if user.Roles == "" {
|
||||||
defaultRoles, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
defaultRoles, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -36,12 +35,11 @@ func (p *provider) AddUser(ctx context.Context, user models.User) (models.User,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser to update user information in database
|
// UpdateUser to update user information in database
|
||||||
func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) UpdateUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
user.UpdatedAt = time.Now().Unix()
|
user.UpdatedAt = time.Now().Unix()
|
||||||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||||
_, err := userCollection.UpdateOne(ctx, bson.M{"_id": bson.M{"$eq": user.ID}}, bson.M{"$set": user}, options.MergeUpdateOptions())
|
_, err := userCollection.UpdateOne(ctx, bson.M{"_id": bson.M{"$eq": user.ID}}, bson.M{"$set": user}, options.MergeUpdateOptions())
|
||||||
@@ -52,83 +50,72 @@ func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.Use
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUser to delete user information from database
|
// DeleteUser to delete user information from database
|
||||||
func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
||||||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||||
_, err := userCollection.DeleteOne(ctx, bson.M{"_id": user.ID}, options.Delete())
|
_, err := userCollection.DeleteOne(ctx, bson.M{"_id": user.ID}, options.Delete())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
|
sessionCollection := p.db.Collection(models.Collections.Session, options.Collection())
|
||||||
_, err = sessionCollection.DeleteMany(ctx, bson.M{"user_id": user.ID}, options.Delete())
|
_, err = sessionCollection.DeleteMany(ctx, bson.M{"user_id": user.ID}, options.Delete())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListUsers to get list of users from database
|
// ListUsers to get list of users from database
|
||||||
func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (*model.Users, error) {
|
func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination) (*model.Users, error) {
|
||||||
var users []*model.User
|
var users []*model.User
|
||||||
opts := options.Find()
|
opts := options.Find()
|
||||||
opts.SetLimit(pagination.Limit)
|
opts.SetLimit(pagination.Limit)
|
||||||
opts.SetSkip(pagination.Offset)
|
opts.SetSkip(pagination.Offset)
|
||||||
opts.SetSort(bson.M{"created_at": -1})
|
opts.SetSort(bson.M{"created_at": -1})
|
||||||
|
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
|
|
||||||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||||
count, err := userCollection.CountDocuments(ctx, bson.M{}, options.Count())
|
count, err := userCollection.CountDocuments(ctx, bson.M{}, options.Count())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
paginationClone.Total = count
|
paginationClone.Total = count
|
||||||
|
|
||||||
cursor, err := userCollection.Find(ctx, bson.M{}, opts)
|
cursor, err := userCollection.Find(ctx, bson.M{}, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer cursor.Close(ctx)
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
for cursor.Next(ctx) {
|
for cursor.Next(ctx) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
err := cursor.Decode(&user)
|
err := cursor.Decode(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
users = append(users, user.AsAPIUser())
|
users = append(users, user.AsAPIUser())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.Users{
|
return &model.Users{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Users: users,
|
Users: users,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByEmail to get user information from database using email address
|
// GetUserByEmail to get user information from database using email address
|
||||||
func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.User, error) {
|
func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||||
err := userCollection.FindOne(ctx, bson.M{"email": email}).Decode(&user)
|
err := userCollection.FindOne(ctx, bson.M{"email": email}).Decode(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByID to get user information from database using user ID
|
// GetUserByID to get user information from database using user ID
|
||||||
func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, error) {
|
func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||||
err := userCollection.FindOne(ctx, bson.M{"_id": id}).Decode(&user)
|
err := userCollection.FindOne(ctx, bson.M{"_id": id}).Decode(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,17 +124,14 @@ func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, err
|
|||||||
func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error {
|
func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error {
|
||||||
// set updated_at time for all users
|
// set updated_at time for all users
|
||||||
data["updated_at"] = time.Now().Unix()
|
data["updated_at"] = time.Now().Unix()
|
||||||
|
|
||||||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||||
|
|
||||||
var res *mongo.UpdateResult
|
var res *mongo.UpdateResult
|
||||||
var err error
|
var err error
|
||||||
if ids != nil && len(ids) > 0 {
|
if len(ids) > 0 {
|
||||||
res, err = userCollection.UpdateMany(ctx, bson.M{"_id": bson.M{"$in": ids}}, bson.M{"$set": data})
|
res, err = userCollection.UpdateMany(ctx, bson.M{"_id": bson.M{"$in": ids}}, bson.M{"$set": data})
|
||||||
} else {
|
} else {
|
||||||
res, err = userCollection.UpdateMany(ctx, bson.M{}, bson.M{"$set": data})
|
res, err = userCollection.UpdateMany(ctx, bson.M{}, bson.M{"$set": data})
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
@@ -158,13 +142,11 @@ func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{},
|
|||||||
|
|
||||||
// GetUserByPhoneNumber to get user information from database using phone number
|
// GetUserByPhoneNumber to get user information from database using phone number
|
||||||
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
userCollection := p.db.Collection(models.Collections.User, options.Collection())
|
||||||
err := userCollection.FindOne(ctx, bson.M{"phone_number": phoneNumber}).Decode(&user)
|
err := userCollection.FindOne(ctx, bson.M{"phone_number": phoneNumber}).Decode(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return user, nil
|
||||||
return &user, nil
|
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddVerification to save verification request in database
|
// AddVerification to save verification request in database
|
||||||
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) (models.VerificationRequest, error) {
|
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) (*models.VerificationRequest, error) {
|
||||||
if verificationRequest.ID == "" {
|
if verificationRequest.ID == "" {
|
||||||
verificationRequest.ID = uuid.New().String()
|
verificationRequest.ID = uuid.New().String()
|
||||||
|
|
||||||
@@ -30,8 +30,8 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByToken to get verification request from database using token
|
// GetVerificationRequestByToken to get verification request from database using token
|
||||||
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
|
|
||||||
verificationRequestCollection := p.db.Collection(models.Collections.VerificationRequest, options.Collection())
|
verificationRequestCollection := p.db.Collection(models.Collections.VerificationRequest, options.Collection())
|
||||||
err := verificationRequestCollection.FindOne(ctx, bson.M{"token": token}).Decode(&verificationRequest)
|
err := verificationRequestCollection.FindOne(ctx, bson.M{"token": token}).Decode(&verificationRequest)
|
||||||
@@ -43,8 +43,8 @@ func (p *provider) GetVerificationRequestByToken(ctx context.Context, token stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByEmail to get verification request by email from database
|
// GetVerificationRequestByEmail to get verification request by email from database
|
||||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
|
|
||||||
verificationRequestCollection := p.db.Collection(models.Collections.VerificationRequest, options.Collection())
|
verificationRequestCollection := p.db.Collection(models.Collections.VerificationRequest, options.Collection())
|
||||||
err := verificationRequestCollection.FindOne(ctx, bson.M{"email": email, "identifier": identifier}).Decode(&verificationRequest)
|
err := verificationRequestCollection.FindOne(ctx, bson.M{"email": email, "identifier": identifier}).Decode(&verificationRequest)
|
||||||
@@ -56,7 +56,7 @@ func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListVerificationRequests to get list of verification requests from database
|
// ListVerificationRequests to get list of verification requests from database
|
||||||
func (p *provider) ListVerificationRequests(ctx context.Context, pagination model.Pagination) (*model.VerificationRequests, error) {
|
func (p *provider) ListVerificationRequests(ctx context.Context, pagination *model.Pagination) (*model.VerificationRequests, error) {
|
||||||
var verificationRequests []*model.VerificationRequest
|
var verificationRequests []*model.VerificationRequest
|
||||||
|
|
||||||
opts := options.Find()
|
opts := options.Find()
|
||||||
@@ -77,7 +77,7 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination mode
|
|||||||
defer cursor.Close(ctx)
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
for cursor.Next(ctx) {
|
for cursor.Next(ctx) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
err := cursor.Decode(&verificationRequest)
|
err := cursor.Decode(&verificationRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -87,12 +87,12 @@ func (p *provider) ListVerificationRequests(ctx context.Context, pagination mode
|
|||||||
|
|
||||||
return &model.VerificationRequests{
|
return &model.VerificationRequests{
|
||||||
VerificationRequests: verificationRequests,
|
VerificationRequests: verificationRequests,
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteVerificationRequest to delete verification request from database
|
// DeleteVerificationRequest to delete verification request from database
|
||||||
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) error {
|
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) error {
|
||||||
verificationRequestCollection := p.db.Collection(models.Collections.VerificationRequest, options.Collection())
|
verificationRequestCollection := p.db.Collection(models.Collections.VerificationRequest, options.Collection())
|
||||||
_, err := verificationRequestCollection.DeleteOne(ctx, bson.M{"_id": verificationRequest.ID}, options.Delete())
|
_, err := verificationRequestCollection.DeleteOne(ctx, bson.M{"_id": verificationRequest.ID}, options.Delete())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhook to add webhook
|
// AddWebhook to add webhook
|
||||||
func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) AddWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
if webhook.ID == "" {
|
if webhook.ID == "" {
|
||||||
webhook.ID = uuid.New().String()
|
webhook.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWebhook to update webhook
|
// UpdateWebhook to update webhook
|
||||||
func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) UpdateWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
// Event is changed
|
// Event is changed
|
||||||
if !strings.Contains(webhook.EventName, "-") {
|
if !strings.Contains(webhook.EventName, "-") {
|
||||||
@@ -47,7 +47,7 @@ func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhooks to list webhook
|
// ListWebhooks to list webhook
|
||||||
func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination) (*model.Webhooks, error) {
|
func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination) (*model.Webhooks, error) {
|
||||||
webhooks := []*model.Webhook{}
|
webhooks := []*model.Webhook{}
|
||||||
opts := options.Find()
|
opts := options.Find()
|
||||||
opts.SetLimit(pagination.Limit)
|
opts.SetLimit(pagination.Limit)
|
||||||
@@ -66,7 +66,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
|||||||
}
|
}
|
||||||
defer cursor.Close(ctx)
|
defer cursor.Close(ctx)
|
||||||
for cursor.Next(ctx) {
|
for cursor.Next(ctx) {
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
err := cursor.Decode(&webhook)
|
err := cursor.Decode(&webhook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -74,14 +74,14 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
|||||||
webhooks = append(webhooks, webhook.AsAPIWebhook())
|
webhooks = append(webhooks, webhook.AsAPIWebhook())
|
||||||
}
|
}
|
||||||
return &model.Webhooks{
|
return &model.Webhooks{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Webhooks: webhooks,
|
Webhooks: webhooks,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWebhookByID to get webhook by id
|
// GetWebhookByID to get webhook by id
|
||||||
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
webhookCollection := p.db.Collection(models.Collections.Webhook, options.Collection())
|
webhookCollection := p.db.Collection(models.Collections.Webhook, options.Collection())
|
||||||
err := webhookCollection.FindOne(ctx, bson.M{"_id": webhookID}).Decode(&webhook)
|
err := webhookCollection.FindOne(ctx, bson.M{"_id": webhookID}).Decode(&webhook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -104,7 +104,7 @@ func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string)
|
|||||||
}
|
}
|
||||||
defer cursor.Close(ctx)
|
defer cursor.Close(ctx)
|
||||||
for cursor.Next(ctx) {
|
for cursor.Next(ctx) {
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
err := cursor.Decode(&webhook)
|
err := cursor.Decode(&webhook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhookLog to add webhook log
|
// AddWebhookLog to add webhook log
|
||||||
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookLog) (*model.WebhookLog, error) {
|
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.WebhookLog) (*model.WebhookLog, error) {
|
||||||
if webhookLog.ID == "" {
|
if webhookLog.ID == "" {
|
||||||
webhookLog.ID = uuid.New().String()
|
webhookLog.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhookLogs to list webhook logs
|
// ListWebhookLogs to list webhook logs
|
||||||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||||
webhookLogs := []*model.WebhookLog{}
|
webhookLogs := []*model.WebhookLog{}
|
||||||
opts := options.Find()
|
opts := options.Find()
|
||||||
opts.SetLimit(pagination.Limit)
|
opts.SetLimit(pagination.Limit)
|
||||||
@@ -59,7 +59,7 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
|||||||
defer cursor.Close(ctx)
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
for cursor.Next(ctx) {
|
for cursor.Next(ctx) {
|
||||||
var webhookLog models.WebhookLog
|
var webhookLog *models.WebhookLog
|
||||||
err := cursor.Decode(&webhookLog)
|
err := cursor.Decode(&webhookLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -68,7 +68,7 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &model.WebhookLogs{
|
return &model.WebhookLogs{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
WebhookLogs: webhookLogs,
|
WebhookLogs: webhookLogs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEmailTemplate to add EmailTemplate
|
// AddEmailTemplate to add EmailTemplate
|
||||||
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
if emailTemplate.ID == "" {
|
if emailTemplate.ID == "" {
|
||||||
emailTemplate.ID = uuid.New().String()
|
emailTemplate.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -22,13 +22,13 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.Em
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEmailTemplate to update EmailTemplate
|
// UpdateEmailTemplate to update EmailTemplate
|
||||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||||
return emailTemplate.AsAPIEmailTemplate(), nil
|
return emailTemplate.AsAPIEmailTemplate(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListEmailTemplates to list EmailTemplate
|
// ListEmailTemplates to list EmailTemplate
|
||||||
func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagination) (*model.EmailTemplates, error) {
|
func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagination) (*model.EmailTemplates, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEnv to save environment information in database
|
// AddEnv to save environment information in database
|
||||||
func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
if env.ID == "" {
|
if env.ID == "" {
|
||||||
env.ID = uuid.New().String()
|
env.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -20,14 +20,14 @@ func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEnv to update environment information in database
|
// UpdateEnv to update environment information in database
|
||||||
func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEnv to get environment information from database
|
// GetEnv to get environment information from database
|
||||||
func (p *provider) GetEnv(ctx context.Context) (models.Env, error) {
|
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||||
var env models.Env
|
var env *models.Env
|
||||||
|
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
|
@@ -9,11 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddSession to save session information in database
|
// AddSession to save session information in database
|
||||||
func (p *provider) AddSession(ctx context.Context, session models.Session) error {
|
func (p *provider) AddSession(ctx context.Context, session *models.Session) error {
|
||||||
if session.ID == "" {
|
if session.ID == "" {
|
||||||
session.ID = uuid.New().String()
|
session.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
session.CreatedAt = time.Now().Unix()
|
session.CreatedAt = time.Now().Unix()
|
||||||
session.UpdatedAt = time.Now().Unix()
|
session.UpdatedAt = time.Now().Unix()
|
||||||
return nil
|
return nil
|
||||||
|
@@ -12,11 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddUser to save user information in database
|
// AddUser to save user information in database
|
||||||
func (p *provider) AddUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) AddUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
if user.ID == "" {
|
if user.ID == "" {
|
||||||
user.ID = uuid.New().String()
|
user.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.Roles == "" {
|
if user.Roles == "" {
|
||||||
defaultRoles, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
defaultRoles, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyDefaultRoles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -24,40 +23,36 @@ func (p *provider) AddUser(ctx context.Context, user models.User) (models.User,
|
|||||||
}
|
}
|
||||||
user.Roles = defaultRoles
|
user.Roles = defaultRoles
|
||||||
}
|
}
|
||||||
|
|
||||||
user.CreatedAt = time.Now().Unix()
|
user.CreatedAt = time.Now().Unix()
|
||||||
user.UpdatedAt = time.Now().Unix()
|
user.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser to update user information in database
|
// UpdateUser to update user information in database
|
||||||
func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) UpdateUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
user.UpdatedAt = time.Now().Unix()
|
user.UpdatedAt = time.Now().Unix()
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUser to delete user information from database
|
// DeleteUser to delete user information from database
|
||||||
func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListUsers to get list of users from database
|
// ListUsers to get list of users from database
|
||||||
func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (*model.Users, error) {
|
func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination) (*model.Users, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByEmail to get user information from database using email address
|
// GetUserByEmail to get user information from database using email address
|
||||||
func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.User, error) {
|
func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByID to get user information from database using user ID
|
// GetUserByID to get user information from database using user ID
|
||||||
func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, error) {
|
func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,13 +61,11 @@ func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, err
|
|||||||
func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error {
|
func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error {
|
||||||
// set updated_at time for all users
|
// set updated_at time for all users
|
||||||
data["updated_at"] = time.Now().Unix()
|
data["updated_at"] = time.Now().Unix()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByPhoneNumber to get user information from database using phone number
|
// GetUserByPhoneNumber to get user information from database using phone number
|
||||||
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
||||||
var user *models.User
|
var user *models.User
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddVerification to save verification request in database
|
// AddVerification to save verification request in database
|
||||||
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) (models.VerificationRequest, error) {
|
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) (*models.VerificationRequest, error) {
|
||||||
if verificationRequest.ID == "" {
|
if verificationRequest.ID == "" {
|
||||||
verificationRequest.ID = uuid.New().String()
|
verificationRequest.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -22,25 +22,25 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByToken to get verification request from database using token
|
// GetVerificationRequestByToken to get verification request from database using token
|
||||||
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByEmail to get verification request by email from database
|
// GetVerificationRequestByEmail to get verification request by email from database
|
||||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListVerificationRequests to get list of verification requests from database
|
// ListVerificationRequests to get list of verification requests from database
|
||||||
func (p *provider) ListVerificationRequests(ctx context.Context, pagination model.Pagination) (*model.VerificationRequests, error) {
|
func (p *provider) ListVerificationRequests(ctx context.Context, pagination *model.Pagination) (*model.VerificationRequests, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteVerificationRequest to delete verification request from database
|
// DeleteVerificationRequest to delete verification request from database
|
||||||
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) error {
|
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhook to add webhook
|
// AddWebhook to add webhook
|
||||||
func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) AddWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
if webhook.ID == "" {
|
if webhook.ID == "" {
|
||||||
webhook.ID = uuid.New().String()
|
webhook.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWebhook to update webhook
|
// UpdateWebhook to update webhook
|
||||||
func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) UpdateWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
// Event is changed
|
// Event is changed
|
||||||
if !strings.Contains(webhook.EventName, "-") {
|
if !strings.Contains(webhook.EventName, "-") {
|
||||||
@@ -35,7 +35,7 @@ func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhooks to list webhook
|
// ListWebhooks to list webhook
|
||||||
func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination) (*model.Webhooks, error) {
|
func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination) (*model.Webhooks, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhookLog to add webhook log
|
// AddWebhookLog to add webhook log
|
||||||
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookLog) (*model.WebhookLog, error) {
|
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.WebhookLog) (*model.WebhookLog, error) {
|
||||||
if webhookLog.ID == "" {
|
if webhookLog.ID == "" {
|
||||||
webhookLog.ID = uuid.New().String()
|
webhookLog.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,6 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhookLogs to list webhook logs
|
// ListWebhookLogs to list webhook logs
|
||||||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@@ -9,50 +9,52 @@ import (
|
|||||||
|
|
||||||
type Provider interface {
|
type Provider interface {
|
||||||
// AddUser to save user information in database
|
// AddUser to save user information in database
|
||||||
AddUser(ctx context.Context, user models.User) (models.User, error)
|
AddUser(ctx context.Context, user *models.User) (*models.User, error)
|
||||||
// UpdateUser to update user information in database
|
// UpdateUser to update user information in database
|
||||||
UpdateUser(ctx context.Context, user models.User) (models.User, error)
|
UpdateUser(ctx context.Context, user *models.User) (*models.User, error)
|
||||||
// DeleteUser to delete user information from database
|
// DeleteUser to delete user information from database
|
||||||
DeleteUser(ctx context.Context, user models.User) error
|
DeleteUser(ctx context.Context, user *models.User) error
|
||||||
// ListUsers to get list of users from database
|
// ListUsers to get list of users from database
|
||||||
ListUsers(ctx context.Context, pagination model.Pagination) (*model.Users, error)
|
ListUsers(ctx context.Context, pagination *model.Pagination) (*model.Users, error)
|
||||||
// GetUserByEmail to get user information from database using email address
|
// GetUserByEmail to get user information from database using email address
|
||||||
GetUserByEmail(ctx context.Context, email string) (models.User, error)
|
GetUserByEmail(ctx context.Context, email string) (*models.User, error)
|
||||||
// GetUserByPhoneNumber to get user information from database using phone number
|
// GetUserByPhoneNumber to get user information from database using phone number
|
||||||
GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error)
|
GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error)
|
||||||
// GetUserByID to get user information from database using user ID
|
// GetUserByID to get user information from database using user ID
|
||||||
GetUserByID(ctx context.Context, id string) (models.User, error)
|
GetUserByID(ctx context.Context, id string) (*models.User, error)
|
||||||
// UpdateUsers to update multiple users, with parameters of user IDs slice
|
// UpdateUsers to update multiple users, with parameters of user IDs slice
|
||||||
// If ids set to nil / empty all the users will be updated
|
// If ids set to nil / empty all the users will be updated
|
||||||
UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error
|
UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error
|
||||||
|
|
||||||
// AddVerification to save verification request in database
|
// AddVerification to save verification request in database
|
||||||
AddVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) (models.VerificationRequest, error)
|
AddVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) (*models.VerificationRequest, error)
|
||||||
// GetVerificationRequestByToken to get verification request from database using token
|
// GetVerificationRequestByToken to get verification request from database using token
|
||||||
GetVerificationRequestByToken(ctx context.Context, token string) (models.VerificationRequest, error)
|
GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error)
|
||||||
// GetVerificationRequestByEmail to get verification request by email from database
|
// GetVerificationRequestByEmail to get verification request by email from database
|
||||||
GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (models.VerificationRequest, error)
|
GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error)
|
||||||
// ListVerificationRequests to get list of verification requests from database
|
// ListVerificationRequests to get list of verification requests from database
|
||||||
ListVerificationRequests(ctx context.Context, pagination model.Pagination) (*model.VerificationRequests, error)
|
ListVerificationRequests(ctx context.Context, pagination *model.Pagination) (*model.VerificationRequests, error)
|
||||||
// DeleteVerificationRequest to delete verification request from database
|
// DeleteVerificationRequest to delete verification request from database
|
||||||
DeleteVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) error
|
DeleteVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) error
|
||||||
|
|
||||||
// AddSession to save session information in database
|
// AddSession to save session information in database
|
||||||
AddSession(ctx context.Context, session models.Session) error
|
AddSession(ctx context.Context, session *models.Session) error
|
||||||
|
// DeleteSession to delete session information from database
|
||||||
|
DeleteSession(ctx context.Context, userId string) error
|
||||||
|
|
||||||
// AddEnv to save environment information in database
|
// AddEnv to save environment information in database
|
||||||
AddEnv(ctx context.Context, env models.Env) (models.Env, error)
|
AddEnv(ctx context.Context, env *models.Env) (*models.Env, error)
|
||||||
// UpdateEnv to update environment information in database
|
// UpdateEnv to update environment information in database
|
||||||
UpdateEnv(ctx context.Context, env models.Env) (models.Env, error)
|
UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error)
|
||||||
// GetEnv to get environment information from database
|
// GetEnv to get environment information from database
|
||||||
GetEnv(ctx context.Context) (models.Env, error)
|
GetEnv(ctx context.Context) (*models.Env, error)
|
||||||
|
|
||||||
// AddWebhook to add webhook
|
// AddWebhook to add webhook
|
||||||
AddWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error)
|
AddWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error)
|
||||||
// UpdateWebhook to update webhook
|
// UpdateWebhook to update webhook
|
||||||
UpdateWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error)
|
UpdateWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error)
|
||||||
// ListWebhooks to list webhook
|
// ListWebhooks to list webhook
|
||||||
ListWebhook(ctx context.Context, pagination model.Pagination) (*model.Webhooks, error)
|
ListWebhook(ctx context.Context, pagination *model.Pagination) (*model.Webhooks, error)
|
||||||
// GetWebhookByID to get webhook by id
|
// GetWebhookByID to get webhook by id
|
||||||
GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error)
|
GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error)
|
||||||
// GetWebhookByEventName to get webhook by event_name
|
// GetWebhookByEventName to get webhook by event_name
|
||||||
@@ -61,16 +63,16 @@ type Provider interface {
|
|||||||
DeleteWebhook(ctx context.Context, webhook *model.Webhook) error
|
DeleteWebhook(ctx context.Context, webhook *model.Webhook) error
|
||||||
|
|
||||||
// AddWebhookLog to add webhook log
|
// AddWebhookLog to add webhook log
|
||||||
AddWebhookLog(ctx context.Context, webhookLog models.WebhookLog) (*model.WebhookLog, error)
|
AddWebhookLog(ctx context.Context, webhookLog *models.WebhookLog) (*model.WebhookLog, error)
|
||||||
// ListWebhookLogs to list webhook logs
|
// ListWebhookLogs to list webhook logs
|
||||||
ListWebhookLogs(ctx context.Context, pagination model.Pagination, webhookID string) (*model.WebhookLogs, error)
|
ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error)
|
||||||
|
|
||||||
// AddEmailTemplate to add EmailTemplate
|
// AddEmailTemplate to add EmailTemplate
|
||||||
AddEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error)
|
AddEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error)
|
||||||
// UpdateEmailTemplate to update EmailTemplate
|
// UpdateEmailTemplate to update EmailTemplate
|
||||||
UpdateEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error)
|
UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error)
|
||||||
// ListEmailTemplates to list EmailTemplate
|
// ListEmailTemplates to list EmailTemplate
|
||||||
ListEmailTemplate(ctx context.Context, pagination model.Pagination) (*model.EmailTemplates, error)
|
ListEmailTemplate(ctx context.Context, pagination *model.Pagination) (*model.EmailTemplates, error)
|
||||||
// GetEmailTemplateByID to get EmailTemplate by id
|
// GetEmailTemplateByID to get EmailTemplate by id
|
||||||
GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error)
|
GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error)
|
||||||
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEmailTemplate to add EmailTemplate
|
// AddEmailTemplate to add EmailTemplate
|
||||||
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
if emailTemplate.ID == "" {
|
if emailTemplate.ID == "" {
|
||||||
emailTemplate.ID = uuid.New().String()
|
emailTemplate.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate models.Em
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEmailTemplate to update EmailTemplate
|
// UpdateEmailTemplate to update EmailTemplate
|
||||||
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models.EmailTemplate) (*model.EmailTemplate, error) {
|
func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate *models.EmailTemplate) (*model.EmailTemplate, error) {
|
||||||
emailTemplate.UpdatedAt = time.Now().Unix()
|
emailTemplate.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
res := p.db.Save(&emailTemplate)
|
res := p.db.Save(&emailTemplate)
|
||||||
@@ -38,9 +38,8 @@ func (p *provider) UpdateEmailTemplate(ctx context.Context, emailTemplate models
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListEmailTemplates to list EmailTemplate
|
// ListEmailTemplates to list EmailTemplate
|
||||||
func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagination) (*model.EmailTemplates, error) {
|
func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagination) (*model.EmailTemplates, error) {
|
||||||
var emailTemplates []models.EmailTemplate
|
var emailTemplates []*models.EmailTemplate
|
||||||
|
|
||||||
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&emailTemplates)
|
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&emailTemplates)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return nil, result.Error
|
return nil, result.Error
|
||||||
@@ -60,14 +59,14 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination model.Pagin
|
|||||||
responseEmailTemplates = append(responseEmailTemplates, w.AsAPIEmailTemplate())
|
responseEmailTemplates = append(responseEmailTemplates, w.AsAPIEmailTemplate())
|
||||||
}
|
}
|
||||||
return &model.EmailTemplates{
|
return &model.EmailTemplates{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
EmailTemplates: responseEmailTemplates,
|
EmailTemplates: responseEmailTemplates,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEmailTemplateByID to get EmailTemplate by id
|
// GetEmailTemplateByID to get EmailTemplate by id
|
||||||
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID string) (*model.EmailTemplate, error) {
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
|
|
||||||
result := p.db.Where("id = ?", emailTemplateID).First(&emailTemplate)
|
result := p.db.Where("id = ?", emailTemplateID).First(&emailTemplate)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
@@ -78,7 +77,7 @@ func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID str
|
|||||||
|
|
||||||
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
// GetEmailTemplateByEventName to get EmailTemplate by event_name
|
||||||
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName string) (*model.EmailTemplate, error) {
|
||||||
var emailTemplate models.EmailTemplate
|
var emailTemplate *models.EmailTemplate
|
||||||
|
|
||||||
result := p.db.Where("event_name = ?", eventName).First(&emailTemplate)
|
result := p.db.Where("event_name = ?", eventName).First(&emailTemplate)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
@@ -95,6 +94,5 @@ func (p *provider) DeleteEmailTemplate(ctx context.Context, emailTemplate *model
|
|||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddEnv to save environment information in database
|
// AddEnv to save environment information in database
|
||||||
func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) AddEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
if env.ID == "" {
|
if env.ID == "" {
|
||||||
env.ID = uuid.New().String()
|
env.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -26,10 +26,9 @@ func (p *provider) AddEnv(ctx context.Context, env models.Env) (models.Env, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateEnv to update environment information in database
|
// UpdateEnv to update environment information in database
|
||||||
func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, error) {
|
func (p *provider) UpdateEnv(ctx context.Context, env *models.Env) (*models.Env, error) {
|
||||||
env.UpdatedAt = time.Now().Unix()
|
env.UpdatedAt = time.Now().Unix()
|
||||||
result := p.db.Save(&env)
|
result := p.db.Save(&env)
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return env, result.Error
|
return env, result.Error
|
||||||
}
|
}
|
||||||
@@ -37,13 +36,11 @@ func (p *provider) UpdateEnv(ctx context.Context, env models.Env) (models.Env, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEnv to get environment information from database
|
// GetEnv to get environment information from database
|
||||||
func (p *provider) GetEnv(ctx context.Context) (models.Env, error) {
|
func (p *provider) GetEnv(ctx context.Context) (*models.Env, error) {
|
||||||
var env models.Env
|
var env *models.Env
|
||||||
result := p.db.First(&env)
|
result := p.db.First(&env)
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return env, result.Error
|
return env, result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
return env, nil
|
return env, nil
|
||||||
}
|
}
|
||||||
|
@@ -77,7 +77,7 @@ func NewProvider() (*provider, error) {
|
|||||||
logrus.Debug("Failed to drop phone number constraint:", err)
|
logrus.Debug("Failed to drop phone number constraint:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sqlDB.AutoMigrate(&models.User{}, &models.VerificationRequest{}, &models.Session{}, &models.Env{}, &models.Webhook{}, models.WebhookLog{}, models.EmailTemplate{}, &models.OTP{})
|
err = sqlDB.AutoMigrate(&models.User{}, &models.VerificationRequest{}, &models.Session{}, &models.Env{}, &models.Webhook{}, &models.WebhookLog{}, &models.EmailTemplate{}, &models.OTP{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddSession to save session information in database
|
// AddSession to save session information in database
|
||||||
func (p *provider) AddSession(ctx context.Context, session models.Session) error {
|
func (p *provider) AddSession(ctx context.Context, session *models.Session) error {
|
||||||
if session.ID == "" {
|
if session.ID == "" {
|
||||||
session.ID = uuid.New().String()
|
session.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -27,3 +27,8 @@ func (p *provider) AddSession(ctx context.Context, session models.Session) error
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteSession to delete session information from database
|
||||||
|
func (p *provider) DeleteSession(ctx context.Context, userId string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@@ -17,7 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddUser to save user information in database
|
// AddUser to save user information in database
|
||||||
func (p *provider) AddUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) AddUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
if user.ID == "" {
|
if user.ID == "" {
|
||||||
user.ID = uuid.New().String()
|
user.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ func (p *provider) AddUser(ctx context.Context, user models.User) (models.User,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser to update user information in database
|
// UpdateUser to update user information in database
|
||||||
func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.User, error) {
|
func (p *provider) UpdateUser(ctx context.Context, user *models.User) (*models.User, error) {
|
||||||
user.UpdatedAt = time.Now().Unix()
|
user.UpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
result := p.db.Save(&user)
|
result := p.db.Save(&user)
|
||||||
@@ -66,7 +66,7 @@ func (p *provider) UpdateUser(ctx context.Context, user models.User) (models.Use
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUser to delete user information from database
|
// DeleteUser to delete user information from database
|
||||||
func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
func (p *provider) DeleteUser(ctx context.Context, user *models.User) error {
|
||||||
result := p.db.Where("user_id = ?", user.ID).Delete(&models.Session{})
|
result := p.db.Where("user_id = ?", user.ID).Delete(&models.Session{})
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result.Error
|
return result.Error
|
||||||
@@ -81,7 +81,7 @@ func (p *provider) DeleteUser(ctx context.Context, user models.User) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListUsers to get list of users from database
|
// ListUsers to get list of users from database
|
||||||
func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (*model.Users, error) {
|
func (p *provider) ListUsers(ctx context.Context, pagination *model.Pagination) (*model.Users, error) {
|
||||||
var users []models.User
|
var users []models.User
|
||||||
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&users)
|
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&users)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
@@ -103,31 +103,28 @@ func (p *provider) ListUsers(ctx context.Context, pagination model.Pagination) (
|
|||||||
paginationClone.Total = total
|
paginationClone.Total = total
|
||||||
|
|
||||||
return &model.Users{
|
return &model.Users{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Users: responseUsers,
|
Users: responseUsers,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByEmail to get user information from database using email address
|
// GetUserByEmail to get user information from database using email address
|
||||||
func (p *provider) GetUserByEmail(ctx context.Context, email string) (models.User, error) {
|
func (p *provider) GetUserByEmail(ctx context.Context, email string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
result := p.db.Where("email = ?", email).First(&user)
|
result := p.db.Where("email = ?", email).First(&user)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return user, result.Error
|
return user, result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByID to get user information from database using user ID
|
// GetUserByID to get user information from database using user ID
|
||||||
func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, error) {
|
func (p *provider) GetUserByID(ctx context.Context, id string) (*models.User, error) {
|
||||||
var user models.User
|
var user *models.User
|
||||||
|
|
||||||
result := p.db.Where("id = ?", id).First(&user)
|
result := p.db.Where("id = ?", id).First(&user)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return user, result.Error
|
return user, result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,14 +133,12 @@ func (p *provider) GetUserByID(ctx context.Context, id string) (models.User, err
|
|||||||
func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error {
|
func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{}, ids []string) error {
|
||||||
// set updated_at time for all users
|
// set updated_at time for all users
|
||||||
data["updated_at"] = time.Now().Unix()
|
data["updated_at"] = time.Now().Unix()
|
||||||
|
|
||||||
var res *gorm.DB
|
var res *gorm.DB
|
||||||
if ids != nil && len(ids) > 0 {
|
if len(ids) > 0 {
|
||||||
res = p.db.Model(&models.User{}).Where("id in ?", ids).Updates(data)
|
res = p.db.Model(&models.User{}).Where("id in ?", ids).Updates(data)
|
||||||
} else {
|
} else {
|
||||||
res = p.db.Model(&models.User{}).Updates(data)
|
res = p.db.Model(&models.User{}).Updates(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
return res.Error
|
return res.Error
|
||||||
}
|
}
|
||||||
@@ -154,10 +149,8 @@ func (p *provider) UpdateUsers(ctx context.Context, data map[string]interface{},
|
|||||||
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
func (p *provider) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*models.User, error) {
|
||||||
var user *models.User
|
var user *models.User
|
||||||
result := p.db.Where("phone_number = ?", phoneNumber).First(&user)
|
result := p.db.Where("phone_number = ?", phoneNumber).First(&user)
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return nil, result.Error
|
return nil, result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
@@ -11,11 +11,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddVerification to save verification request in database
|
// AddVerification to save verification request in database
|
||||||
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) (models.VerificationRequest, error) {
|
func (p *provider) AddVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) (*models.VerificationRequest, error) {
|
||||||
if verificationRequest.ID == "" {
|
if verificationRequest.ID == "" {
|
||||||
verificationRequest.ID = uuid.New().String()
|
verificationRequest.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest.Key = verificationRequest.ID
|
verificationRequest.Key = verificationRequest.ID
|
||||||
verificationRequest.CreatedAt = time.Now().Unix()
|
verificationRequest.CreatedAt = time.Now().Unix()
|
||||||
verificationRequest.UpdatedAt = time.Now().Unix()
|
verificationRequest.UpdatedAt = time.Now().Unix()
|
||||||
@@ -23,75 +22,61 @@ func (p *provider) AddVerificationRequest(ctx context.Context, verificationReque
|
|||||||
Columns: []clause.Column{{Name: "email"}, {Name: "identifier"}},
|
Columns: []clause.Column{{Name: "email"}, {Name: "identifier"}},
|
||||||
DoUpdates: clause.AssignmentColumns([]string{"token", "expires_at", "nonce", "redirect_uri"}),
|
DoUpdates: clause.AssignmentColumns([]string{"token", "expires_at", "nonce", "redirect_uri"}),
|
||||||
}).Create(&verificationRequest)
|
}).Create(&verificationRequest)
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return verificationRequest, result.Error
|
return verificationRequest, result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByToken to get verification request from database using token
|
// GetVerificationRequestByToken to get verification request from database using token
|
||||||
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByToken(ctx context.Context, token string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
result := p.db.Where("token = ?", token).First(&verificationRequest)
|
result := p.db.Where("token = ?", token).First(&verificationRequest)
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return verificationRequest, result.Error
|
return verificationRequest, result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVerificationRequestByEmail to get verification request by email from database
|
// GetVerificationRequestByEmail to get verification request by email from database
|
||||||
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (models.VerificationRequest, error) {
|
func (p *provider) GetVerificationRequestByEmail(ctx context.Context, email string, identifier string) (*models.VerificationRequest, error) {
|
||||||
var verificationRequest models.VerificationRequest
|
var verificationRequest *models.VerificationRequest
|
||||||
|
|
||||||
result := p.db.Where("email = ? AND identifier = ?", email, identifier).First(&verificationRequest)
|
result := p.db.Where("email = ? AND identifier = ?", email, identifier).First(&verificationRequest)
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return verificationRequest, result.Error
|
return verificationRequest, result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
return verificationRequest, nil
|
return verificationRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListVerificationRequests to get list of verification requests from database
|
// ListVerificationRequests to get list of verification requests from database
|
||||||
func (p *provider) ListVerificationRequests(ctx context.Context, pagination model.Pagination) (*model.VerificationRequests, error) {
|
func (p *provider) ListVerificationRequests(ctx context.Context, pagination *model.Pagination) (*model.VerificationRequests, error) {
|
||||||
var verificationRequests []models.VerificationRequest
|
var verificationRequests []models.VerificationRequest
|
||||||
|
|
||||||
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&verificationRequests)
|
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&verificationRequests)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return nil, result.Error
|
return nil, result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
responseVerificationRequests := []*model.VerificationRequest{}
|
responseVerificationRequests := []*model.VerificationRequest{}
|
||||||
for _, v := range verificationRequests {
|
for _, v := range verificationRequests {
|
||||||
responseVerificationRequests = append(responseVerificationRequests, v.AsAPIVerificationRequest())
|
responseVerificationRequests = append(responseVerificationRequests, v.AsAPIVerificationRequest())
|
||||||
}
|
}
|
||||||
|
|
||||||
var total int64
|
var total int64
|
||||||
totalRes := p.db.Model(&models.VerificationRequest{}).Count(&total)
|
totalRes := p.db.Model(&models.VerificationRequest{}).Count(&total)
|
||||||
if totalRes.Error != nil {
|
if totalRes.Error != nil {
|
||||||
return nil, totalRes.Error
|
return nil, totalRes.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
paginationClone := pagination
|
paginationClone := pagination
|
||||||
paginationClone.Total = total
|
paginationClone.Total = total
|
||||||
|
|
||||||
return &model.VerificationRequests{
|
return &model.VerificationRequests{
|
||||||
VerificationRequests: responseVerificationRequests,
|
VerificationRequests: responseVerificationRequests,
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteVerificationRequest to delete verification request from database
|
// DeleteVerificationRequest to delete verification request from database
|
||||||
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest models.VerificationRequest) error {
|
func (p *provider) DeleteVerificationRequest(ctx context.Context, verificationRequest *models.VerificationRequest) error {
|
||||||
result := p.db.Delete(&verificationRequest)
|
result := p.db.Delete(&verificationRequest)
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhook to add webhook
|
// AddWebhook to add webhook
|
||||||
func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) AddWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
if webhook.ID == "" {
|
if webhook.ID == "" {
|
||||||
webhook.ID = uuid.New().String()
|
webhook.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWebhook to update webhook
|
// UpdateWebhook to update webhook
|
||||||
func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*model.Webhook, error) {
|
func (p *provider) UpdateWebhook(ctx context.Context, webhook *models.Webhook) (*model.Webhook, error) {
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
// Event is changed
|
// Event is changed
|
||||||
if !strings.Contains(webhook.EventName, "-") {
|
if !strings.Contains(webhook.EventName, "-") {
|
||||||
@@ -43,7 +43,7 @@ func (p *provider) UpdateWebhook(ctx context.Context, webhook models.Webhook) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhooks to list webhook
|
// ListWebhooks to list webhook
|
||||||
func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination) (*model.Webhooks, error) {
|
func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination) (*model.Webhooks, error) {
|
||||||
var webhooks []models.Webhook
|
var webhooks []models.Webhook
|
||||||
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&webhooks)
|
result := p.db.Limit(int(pagination.Limit)).Offset(int(pagination.Offset)).Order("created_at DESC").Find(&webhooks)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
@@ -61,14 +61,14 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
|||||||
responseWebhooks = append(responseWebhooks, w.AsAPIWebhook())
|
responseWebhooks = append(responseWebhooks, w.AsAPIWebhook())
|
||||||
}
|
}
|
||||||
return &model.Webhooks{
|
return &model.Webhooks{
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
Webhooks: responseWebhooks,
|
Webhooks: responseWebhooks,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWebhookByID to get webhook by id
|
// GetWebhookByID to get webhook by id
|
||||||
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
||||||
var webhook models.Webhook
|
var webhook *models.Webhook
|
||||||
|
|
||||||
result := p.db.Where("id = ?", webhookID).First(&webhook)
|
result := p.db.Where("id = ?", webhookID).First(&webhook)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AddWebhookLog to add webhook log
|
// AddWebhookLog to add webhook log
|
||||||
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookLog) (*model.WebhookLog, error) {
|
func (p *provider) AddWebhookLog(ctx context.Context, webhookLog *models.WebhookLog) (*model.WebhookLog, error) {
|
||||||
if webhookLog.ID == "" {
|
if webhookLog.ID == "" {
|
||||||
webhookLog.ID = uuid.New().String()
|
webhookLog.ID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func (p *provider) AddWebhookLog(ctx context.Context, webhookLog models.WebhookL
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListWebhookLogs to list webhook logs
|
// ListWebhookLogs to list webhook logs
|
||||||
func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
func (p *provider) ListWebhookLogs(ctx context.Context, pagination *model.Pagination, webhookID string) (*model.WebhookLogs, error) {
|
||||||
var webhookLogs []models.WebhookLog
|
var webhookLogs []models.WebhookLog
|
||||||
var result *gorm.DB
|
var result *gorm.DB
|
||||||
var totalRes *gorm.DB
|
var totalRes *gorm.DB
|
||||||
@@ -63,6 +63,6 @@ func (p *provider) ListWebhookLogs(ctx context.Context, pagination model.Paginat
|
|||||||
}
|
}
|
||||||
return &model.WebhookLogs{
|
return &model.WebhookLogs{
|
||||||
WebhookLogs: responseWebhookLogs,
|
WebhookLogs: responseWebhookLogs,
|
||||||
Pagination: &paginationClone,
|
Pagination: paginationClone,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
2
server/env/env.go
vendored
2
server/env/env.go
vendored
@@ -19,7 +19,7 @@ import (
|
|||||||
// InitEnv to initialize EnvData and through error if required env are not present
|
// InitEnv to initialize EnvData and through error if required env are not present
|
||||||
func InitAllEnv() error {
|
func InitAllEnv() error {
|
||||||
envData, err := GetEnvData()
|
envData, err := GetEnvData()
|
||||||
if err != nil {
|
if err != nil || envData == nil {
|
||||||
log.Info("No env data found in db, using local clone of env data")
|
log.Info("No env data found in db, using local clone of env data")
|
||||||
// get clone of current store
|
// get clone of current store
|
||||||
envData, err = memorystore.Provider.GetEnvStore()
|
envData, err = memorystore.Provider.GetEnvStore()
|
||||||
|
12
server/env/persist_env.go
vendored
12
server/env/persist_env.go
vendored
@@ -62,7 +62,7 @@ func GetEnvData() (map[string]interface{}, error) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
env, err := db.Provider.GetEnv(ctx)
|
env, err := db.Provider.GetEnv(ctx)
|
||||||
// config not found in db
|
// config not found in db
|
||||||
if err != nil {
|
if err != nil || env == nil {
|
||||||
log.Debug("Error while getting env data from db: ", err)
|
log.Debug("Error while getting env data from db: ", err)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ func PersistEnv() error {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
env, err := db.Provider.GetEnv(ctx)
|
env, err := db.Provider.GetEnv(ctx)
|
||||||
// config not found in db
|
// config not found in db
|
||||||
if err != nil || env.EnvData == "" {
|
if err != nil || env == nil {
|
||||||
// AES encryption needs 32 bit key only, so we chop off last 4 characters from 36 bit uuid
|
// AES encryption needs 32 bit key only, so we chop off last 4 characters from 36 bit uuid
|
||||||
hash := uuid.New().String()[:36-4]
|
hash := uuid.New().String()[:36-4]
|
||||||
err := memorystore.Provider.UpdateEnvVariable(constants.EnvKeyEncryptionKey, hash)
|
err := memorystore.Provider.UpdateEnvVariable(constants.EnvKeyEncryptionKey, hash)
|
||||||
@@ -121,25 +121,21 @@ func PersistEnv() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
encodedHash := crypto.EncryptB64(hash)
|
encodedHash := crypto.EncryptB64(hash)
|
||||||
|
|
||||||
res, err := memorystore.Provider.GetEnvStore()
|
res, err := memorystore.Provider.GetEnvStore()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Error while getting env store: ", err)
|
log.Debug("Error while getting env store: ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
encryptedConfig, err := crypto.EncryptEnvData(res)
|
encryptedConfig, err := crypto.EncryptEnvData(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Error while encrypting env data: ", err)
|
log.Debug("Error while encrypting env data: ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
env = &models.Env{
|
||||||
env = models.Env{
|
|
||||||
Hash: encodedHash,
|
Hash: encodedHash,
|
||||||
EnvData: encryptedConfig,
|
EnvData: encryptedConfig,
|
||||||
}
|
}
|
||||||
|
_, err = db.Provider.AddEnv(ctx, env)
|
||||||
env, err = db.Provider.AddEnv(ctx, env)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Error while persisting env data to db: ", err)
|
log.Debug("Error while persisting env data to db: ", err)
|
||||||
return err
|
return err
|
||||||
|
@@ -50,7 +50,8 @@ type ComplexityRoot struct {
|
|||||||
IDToken func(childComplexity int) int
|
IDToken func(childComplexity int) int
|
||||||
Message func(childComplexity int) int
|
Message func(childComplexity int) int
|
||||||
RefreshToken func(childComplexity int) int
|
RefreshToken func(childComplexity int) int
|
||||||
ShouldShowOtpScreen func(childComplexity int) int
|
ShouldShowEmailOtpScreen func(childComplexity int) int
|
||||||
|
ShouldShowMobileOtpScreen func(childComplexity int) int
|
||||||
User func(childComplexity int) int
|
User func(childComplexity int) int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,12 +429,19 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||||||
|
|
||||||
return e.complexity.AuthResponse.RefreshToken(childComplexity), true
|
return e.complexity.AuthResponse.RefreshToken(childComplexity), true
|
||||||
|
|
||||||
case "AuthResponse.should_show_otp_screen":
|
case "AuthResponse.should_show_email_otp_screen":
|
||||||
if e.complexity.AuthResponse.ShouldShowOtpScreen == nil {
|
if e.complexity.AuthResponse.ShouldShowEmailOtpScreen == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
return e.complexity.AuthResponse.ShouldShowOtpScreen(childComplexity), true
|
return e.complexity.AuthResponse.ShouldShowEmailOtpScreen(childComplexity), true
|
||||||
|
|
||||||
|
case "AuthResponse.should_show_mobile_otp_screen":
|
||||||
|
if e.complexity.AuthResponse.ShouldShowMobileOtpScreen == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.complexity.AuthResponse.ShouldShowMobileOtpScreen(childComplexity), true
|
||||||
|
|
||||||
case "AuthResponse.user":
|
case "AuthResponse.user":
|
||||||
if e.complexity.AuthResponse.User == nil {
|
if e.complexity.AuthResponse.User == nil {
|
||||||
@@ -2261,7 +2269,8 @@ type Error {
|
|||||||
|
|
||||||
type AuthResponse {
|
type AuthResponse {
|
||||||
message: String!
|
message: String!
|
||||||
should_show_otp_screen: Boolean
|
should_show_email_otp_screen: Boolean
|
||||||
|
should_show_mobile_otp_screen: Boolean
|
||||||
access_token: String
|
access_token: String
|
||||||
id_token: String
|
id_token: String
|
||||||
refresh_token: String
|
refresh_token: String
|
||||||
@@ -2681,6 +2690,7 @@ input WebhookRequest {
|
|||||||
input TestEndpointRequest {
|
input TestEndpointRequest {
|
||||||
endpoint: String!
|
endpoint: String!
|
||||||
event_name: String!
|
event_name: String!
|
||||||
|
event_description: String
|
||||||
headers: Map
|
headers: Map
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3474,8 +3484,8 @@ func (ec *executionContext) fieldContext_AuthResponse_message(ctx context.Contex
|
|||||||
return fc, nil
|
return fc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _AuthResponse_should_show_otp_screen(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
|
func (ec *executionContext) _AuthResponse_should_show_email_otp_screen(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
|
||||||
fc, err := ec.fieldContext_AuthResponse_should_show_otp_screen(ctx, field)
|
fc, err := ec.fieldContext_AuthResponse_should_show_email_otp_screen(ctx, field)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
@@ -3488,7 +3498,7 @@ func (ec *executionContext) _AuthResponse_should_show_otp_screen(ctx context.Con
|
|||||||
}()
|
}()
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
ctx = rctx // use context from middleware stack in children
|
ctx = rctx // use context from middleware stack in children
|
||||||
return obj.ShouldShowOtpScreen, nil
|
return obj.ShouldShowEmailOtpScreen, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec.Error(ctx, err)
|
ec.Error(ctx, err)
|
||||||
@@ -3502,7 +3512,48 @@ func (ec *executionContext) _AuthResponse_should_show_otp_screen(ctx context.Con
|
|||||||
return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res)
|
return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) fieldContext_AuthResponse_should_show_otp_screen(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
func (ec *executionContext) fieldContext_AuthResponse_should_show_email_otp_screen(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||||
|
fc = &graphql.FieldContext{
|
||||||
|
Object: "AuthResponse",
|
||||||
|
Field: field,
|
||||||
|
IsMethod: false,
|
||||||
|
IsResolver: false,
|
||||||
|
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||||
|
return nil, errors.New("field of type Boolean does not have child fields")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return fc, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) _AuthResponse_should_show_mobile_otp_screen(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
|
||||||
|
fc, err := ec.fieldContext_AuthResponse_should_show_mobile_otp_screen(ctx, field)
|
||||||
|
if err != nil {
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
ctx = graphql.WithFieldContext(ctx, fc)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
|
ret = graphql.Null
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
|
ctx = rctx // use context from middleware stack in children
|
||||||
|
return obj.ShouldShowMobileOtpScreen, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ec.Error(ctx, err)
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
if resTmp == nil {
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
res := resTmp.(*bool)
|
||||||
|
fc.Result = res
|
||||||
|
return ec.marshalOBoolean2ᚖbool(ctx, field.Selections, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) fieldContext_AuthResponse_should_show_mobile_otp_screen(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||||
fc = &graphql.FieldContext{
|
fc = &graphql.FieldContext{
|
||||||
Object: "AuthResponse",
|
Object: "AuthResponse",
|
||||||
Field: field,
|
Field: field,
|
||||||
@@ -7756,8 +7807,10 @@ func (ec *executionContext) fieldContext_Mutation_signup(ctx context.Context, fi
|
|||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "message":
|
case "message":
|
||||||
return ec.fieldContext_AuthResponse_message(ctx, field)
|
return ec.fieldContext_AuthResponse_message(ctx, field)
|
||||||
case "should_show_otp_screen":
|
case "should_show_email_otp_screen":
|
||||||
return ec.fieldContext_AuthResponse_should_show_otp_screen(ctx, field)
|
return ec.fieldContext_AuthResponse_should_show_email_otp_screen(ctx, field)
|
||||||
|
case "should_show_mobile_otp_screen":
|
||||||
|
return ec.fieldContext_AuthResponse_should_show_mobile_otp_screen(ctx, field)
|
||||||
case "access_token":
|
case "access_token":
|
||||||
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
||||||
case "id_token":
|
case "id_token":
|
||||||
@@ -7827,8 +7880,10 @@ func (ec *executionContext) fieldContext_Mutation_mobile_signup(ctx context.Cont
|
|||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "message":
|
case "message":
|
||||||
return ec.fieldContext_AuthResponse_message(ctx, field)
|
return ec.fieldContext_AuthResponse_message(ctx, field)
|
||||||
case "should_show_otp_screen":
|
case "should_show_email_otp_screen":
|
||||||
return ec.fieldContext_AuthResponse_should_show_otp_screen(ctx, field)
|
return ec.fieldContext_AuthResponse_should_show_email_otp_screen(ctx, field)
|
||||||
|
case "should_show_mobile_otp_screen":
|
||||||
|
return ec.fieldContext_AuthResponse_should_show_mobile_otp_screen(ctx, field)
|
||||||
case "access_token":
|
case "access_token":
|
||||||
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
||||||
case "id_token":
|
case "id_token":
|
||||||
@@ -7898,8 +7953,10 @@ func (ec *executionContext) fieldContext_Mutation_login(ctx context.Context, fie
|
|||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "message":
|
case "message":
|
||||||
return ec.fieldContext_AuthResponse_message(ctx, field)
|
return ec.fieldContext_AuthResponse_message(ctx, field)
|
||||||
case "should_show_otp_screen":
|
case "should_show_email_otp_screen":
|
||||||
return ec.fieldContext_AuthResponse_should_show_otp_screen(ctx, field)
|
return ec.fieldContext_AuthResponse_should_show_email_otp_screen(ctx, field)
|
||||||
|
case "should_show_mobile_otp_screen":
|
||||||
|
return ec.fieldContext_AuthResponse_should_show_mobile_otp_screen(ctx, field)
|
||||||
case "access_token":
|
case "access_token":
|
||||||
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
||||||
case "id_token":
|
case "id_token":
|
||||||
@@ -7969,8 +8026,10 @@ func (ec *executionContext) fieldContext_Mutation_mobile_login(ctx context.Conte
|
|||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "message":
|
case "message":
|
||||||
return ec.fieldContext_AuthResponse_message(ctx, field)
|
return ec.fieldContext_AuthResponse_message(ctx, field)
|
||||||
case "should_show_otp_screen":
|
case "should_show_email_otp_screen":
|
||||||
return ec.fieldContext_AuthResponse_should_show_otp_screen(ctx, field)
|
return ec.fieldContext_AuthResponse_should_show_email_otp_screen(ctx, field)
|
||||||
|
case "should_show_mobile_otp_screen":
|
||||||
|
return ec.fieldContext_AuthResponse_should_show_mobile_otp_screen(ctx, field)
|
||||||
case "access_token":
|
case "access_token":
|
||||||
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
||||||
case "id_token":
|
case "id_token":
|
||||||
@@ -8206,8 +8265,10 @@ func (ec *executionContext) fieldContext_Mutation_verify_email(ctx context.Conte
|
|||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "message":
|
case "message":
|
||||||
return ec.fieldContext_AuthResponse_message(ctx, field)
|
return ec.fieldContext_AuthResponse_message(ctx, field)
|
||||||
case "should_show_otp_screen":
|
case "should_show_email_otp_screen":
|
||||||
return ec.fieldContext_AuthResponse_should_show_otp_screen(ctx, field)
|
return ec.fieldContext_AuthResponse_should_show_email_otp_screen(ctx, field)
|
||||||
|
case "should_show_mobile_otp_screen":
|
||||||
|
return ec.fieldContext_AuthResponse_should_show_mobile_otp_screen(ctx, field)
|
||||||
case "access_token":
|
case "access_token":
|
||||||
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
||||||
case "id_token":
|
case "id_token":
|
||||||
@@ -8513,8 +8574,10 @@ func (ec *executionContext) fieldContext_Mutation_verify_otp(ctx context.Context
|
|||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "message":
|
case "message":
|
||||||
return ec.fieldContext_AuthResponse_message(ctx, field)
|
return ec.fieldContext_AuthResponse_message(ctx, field)
|
||||||
case "should_show_otp_screen":
|
case "should_show_email_otp_screen":
|
||||||
return ec.fieldContext_AuthResponse_should_show_otp_screen(ctx, field)
|
return ec.fieldContext_AuthResponse_should_show_email_otp_screen(ctx, field)
|
||||||
|
case "should_show_mobile_otp_screen":
|
||||||
|
return ec.fieldContext_AuthResponse_should_show_mobile_otp_screen(ctx, field)
|
||||||
case "access_token":
|
case "access_token":
|
||||||
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
||||||
case "id_token":
|
case "id_token":
|
||||||
@@ -9931,8 +9994,10 @@ func (ec *executionContext) fieldContext_Query_session(ctx context.Context, fiel
|
|||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "message":
|
case "message":
|
||||||
return ec.fieldContext_AuthResponse_message(ctx, field)
|
return ec.fieldContext_AuthResponse_message(ctx, field)
|
||||||
case "should_show_otp_screen":
|
case "should_show_email_otp_screen":
|
||||||
return ec.fieldContext_AuthResponse_should_show_otp_screen(ctx, field)
|
return ec.fieldContext_AuthResponse_should_show_email_otp_screen(ctx, field)
|
||||||
|
case "should_show_mobile_otp_screen":
|
||||||
|
return ec.fieldContext_AuthResponse_should_show_mobile_otp_screen(ctx, field)
|
||||||
case "access_token":
|
case "access_token":
|
||||||
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
return ec.fieldContext_AuthResponse_access_token(ctx, field)
|
||||||
case "id_token":
|
case "id_token":
|
||||||
@@ -16692,7 +16757,7 @@ func (ec *executionContext) unmarshalInputTestEndpointRequest(ctx context.Contex
|
|||||||
asMap[k] = v
|
asMap[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldsInOrder := [...]string{"endpoint", "event_name", "headers"}
|
fieldsInOrder := [...]string{"endpoint", "event_name", "event_description", "headers"}
|
||||||
for _, k := range fieldsInOrder {
|
for _, k := range fieldsInOrder {
|
||||||
v, ok := asMap[k]
|
v, ok := asMap[k]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -16715,6 +16780,14 @@ func (ec *executionContext) unmarshalInputTestEndpointRequest(ctx context.Contex
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return it, err
|
return it, err
|
||||||
}
|
}
|
||||||
|
case "event_description":
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("event_description"))
|
||||||
|
it.EventDescription, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return it, err
|
||||||
|
}
|
||||||
case "headers":
|
case "headers":
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -17790,9 +17863,13 @@ func (ec *executionContext) _AuthResponse(ctx context.Context, sel ast.Selection
|
|||||||
if out.Values[i] == graphql.Null {
|
if out.Values[i] == graphql.Null {
|
||||||
invalids++
|
invalids++
|
||||||
}
|
}
|
||||||
case "should_show_otp_screen":
|
case "should_show_email_otp_screen":
|
||||||
|
|
||||||
out.Values[i] = ec._AuthResponse_should_show_otp_screen(ctx, field, obj)
|
out.Values[i] = ec._AuthResponse_should_show_email_otp_screen(ctx, field, obj)
|
||||||
|
|
||||||
|
case "should_show_mobile_otp_screen":
|
||||||
|
|
||||||
|
out.Values[i] = ec._AuthResponse_should_show_mobile_otp_screen(ctx, field, obj)
|
||||||
|
|
||||||
case "access_token":
|
case "access_token":
|
||||||
|
|
||||||
|
@@ -27,7 +27,8 @@ type AdminSignupInput struct {
|
|||||||
|
|
||||||
type AuthResponse struct {
|
type AuthResponse struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
ShouldShowOtpScreen *bool `json:"should_show_otp_screen"`
|
ShouldShowEmailOtpScreen *bool `json:"should_show_email_otp_screen"`
|
||||||
|
ShouldShowMobileOtpScreen *bool `json:"should_show_mobile_otp_screen"`
|
||||||
AccessToken *string `json:"access_token"`
|
AccessToken *string `json:"access_token"`
|
||||||
IDToken *string `json:"id_token"`
|
IDToken *string `json:"id_token"`
|
||||||
RefreshToken *string `json:"refresh_token"`
|
RefreshToken *string `json:"refresh_token"`
|
||||||
@@ -302,6 +303,7 @@ type SignUpInput struct {
|
|||||||
type TestEndpointRequest struct {
|
type TestEndpointRequest struct {
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
EventName string `json:"event_name"`
|
EventName string `json:"event_name"`
|
||||||
|
EventDescription *string `json:"event_description"`
|
||||||
Headers map[string]interface{} `json:"headers"`
|
Headers map[string]interface{} `json:"headers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -91,7 +91,8 @@ type Error {
|
|||||||
|
|
||||||
type AuthResponse {
|
type AuthResponse {
|
||||||
message: String!
|
message: String!
|
||||||
should_show_otp_screen: Boolean
|
should_show_email_otp_screen: Boolean
|
||||||
|
should_show_mobile_otp_screen: Boolean
|
||||||
access_token: String
|
access_token: String
|
||||||
id_token: String
|
id_token: String
|
||||||
refresh_token: String
|
refresh_token: String
|
||||||
@@ -511,6 +512,7 @@ input WebhookRequest {
|
|||||||
input TestEndpointRequest {
|
input TestEndpointRequest {
|
||||||
endpoint: String!
|
endpoint: String!
|
||||||
event_name: String!
|
event_name: String!
|
||||||
|
event_description: String
|
||||||
headers: Map
|
headers: Map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -55,7 +55,7 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
|||||||
inputRoles := strings.Split(sessionSplit[2], ",")
|
inputRoles := strings.Split(sessionSplit[2], ",")
|
||||||
scopes := strings.Split(sessionSplit[3], ",")
|
scopes := strings.Split(sessionSplit[3], ",")
|
||||||
|
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
oauthCode := ctx.Request.FormValue("code")
|
oauthCode := ctx.Request.FormValue("code")
|
||||||
switch provider {
|
switch provider {
|
||||||
case constants.AuthRecipeMethodGoogle:
|
case constants.AuthRecipeMethodGoogle:
|
||||||
@@ -260,10 +260,12 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
|||||||
go func() {
|
go func() {
|
||||||
if isSignUp {
|
if isSignUp {
|
||||||
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, provider, user)
|
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, provider, user)
|
||||||
|
// User is also logged in with signup
|
||||||
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, provider, user)
|
||||||
} else {
|
} else {
|
||||||
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, provider, user)
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, provider, user)
|
||||||
}
|
}
|
||||||
db.Provider.AddSession(ctx, models.Session{
|
db.Provider.AddSession(ctx, &models.Session{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
UserAgent: utils.GetUserAgent(ctx.Request),
|
UserAgent: utils.GetUserAgent(ctx.Request),
|
||||||
IP: utils.GetIP(ctx.Request),
|
IP: utils.GetIP(ctx.Request),
|
||||||
@@ -279,15 +281,14 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func processGoogleUserInfo(code string) (models.User, error) {
|
func processGoogleUserInfo(code string) (*models.User, error) {
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
oauth2Token, err := oauth.OAuthProviders.GoogleConfig.Exchange(ctx, code)
|
oauth2Token, err := oauth.OAuthProviders.GoogleConfig.Exchange(ctx, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to exchange code for token: ", err)
|
log.Debug("Failed to exchange code for token: ", err)
|
||||||
return user, fmt.Errorf("invalid google exchange code: %s", err.Error())
|
return user, fmt.Errorf("invalid google exchange code: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
verifier := oauth.OIDCProviders.GoogleOIDC.Verifier(&oidc.Config{ClientID: oauth.OAuthProviders.GoogleConfig.ClientID})
|
verifier := oauth.OIDCProviders.GoogleOIDC.Verifier(&oidc.Config{ClientID: oauth.OAuthProviders.GoogleConfig.ClientID})
|
||||||
|
|
||||||
// Extract the ID Token from OAuth2 token.
|
// Extract the ID Token from OAuth2 token.
|
||||||
@@ -312,8 +313,8 @@ func processGoogleUserInfo(code string) (models.User, error) {
|
|||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processGithubUserInfo(code string) (models.User, error) {
|
func processGithubUserInfo(code string) (*models.User, error) {
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
oauth2Token, err := oauth.OAuthProviders.GithubConfig.Exchange(context.TODO(), code)
|
oauth2Token, err := oauth.OAuthProviders.GithubConfig.Exchange(context.TODO(), code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to exchange code for token: ", err)
|
log.Debug("Failed to exchange code for token: ", err)
|
||||||
@@ -409,7 +410,7 @@ func processGithubUserInfo(code string) (models.User, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user = models.User{
|
user = &models.User{
|
||||||
GivenName: &firstName,
|
GivenName: &firstName,
|
||||||
FamilyName: &lastName,
|
FamilyName: &lastName,
|
||||||
Picture: &picture,
|
Picture: &picture,
|
||||||
@@ -419,8 +420,8 @@ func processGithubUserInfo(code string) (models.User, error) {
|
|||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processFacebookUserInfo(code string) (models.User, error) {
|
func processFacebookUserInfo(code string) (*models.User, error) {
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
oauth2Token, err := oauth.OAuthProviders.FacebookConfig.Exchange(context.TODO(), code)
|
oauth2Token, err := oauth.OAuthProviders.FacebookConfig.Exchange(context.TODO(), code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Invalid facebook exchange code: ", err)
|
log.Debug("Invalid facebook exchange code: ", err)
|
||||||
@@ -460,7 +461,7 @@ func processFacebookUserInfo(code string) (models.User, error) {
|
|||||||
lastName := fmt.Sprintf("%v", userRawData["last_name"])
|
lastName := fmt.Sprintf("%v", userRawData["last_name"])
|
||||||
picture := fmt.Sprintf("%v", picDataObject["url"])
|
picture := fmt.Sprintf("%v", picDataObject["url"])
|
||||||
|
|
||||||
user = models.User{
|
user = &models.User{
|
||||||
GivenName: &firstName,
|
GivenName: &firstName,
|
||||||
FamilyName: &lastName,
|
FamilyName: &lastName,
|
||||||
Picture: &picture,
|
Picture: &picture,
|
||||||
@@ -470,8 +471,8 @@ func processFacebookUserInfo(code string) (models.User, error) {
|
|||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processLinkedInUserInfo(code string) (models.User, error) {
|
func processLinkedInUserInfo(code string) (*models.User, error) {
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
oauth2Token, err := oauth.OAuthProviders.LinkedInConfig.Exchange(context.TODO(), code)
|
oauth2Token, err := oauth.OAuthProviders.LinkedInConfig.Exchange(context.TODO(), code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to exchange code for token: ", err)
|
log.Debug("Failed to exchange code for token: ", err)
|
||||||
@@ -542,7 +543,7 @@ func processLinkedInUserInfo(code string) (models.User, error) {
|
|||||||
profilePicture := userRawData["profilePicture"].(map[string]interface{})["displayImage~"].(map[string]interface{})["elements"].([]interface{})[0].(map[string]interface{})["identifiers"].([]interface{})[0].(map[string]interface{})["identifier"].(string)
|
profilePicture := userRawData["profilePicture"].(map[string]interface{})["displayImage~"].(map[string]interface{})["elements"].([]interface{})[0].(map[string]interface{})["identifiers"].([]interface{})[0].(map[string]interface{})["identifier"].(string)
|
||||||
emailAddress := emailRawData["elements"].([]interface{})[0].(map[string]interface{})["handle~"].(map[string]interface{})["emailAddress"].(string)
|
emailAddress := emailRawData["elements"].([]interface{})[0].(map[string]interface{})["handle~"].(map[string]interface{})["emailAddress"].(string)
|
||||||
|
|
||||||
user = models.User{
|
user = &models.User{
|
||||||
GivenName: &firstName,
|
GivenName: &firstName,
|
||||||
FamilyName: &lastName,
|
FamilyName: &lastName,
|
||||||
Picture: &profilePicture,
|
Picture: &profilePicture,
|
||||||
@@ -552,8 +553,8 @@ func processLinkedInUserInfo(code string) (models.User, error) {
|
|||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processAppleUserInfo(code string) (models.User, error) {
|
func processAppleUserInfo(code string) (*models.User, error) {
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
oauth2Token, err := oauth.OAuthProviders.AppleConfig.Exchange(context.TODO(), code)
|
oauth2Token, err := oauth.OAuthProviders.AppleConfig.Exchange(context.TODO(), code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to exchange code for token: ", err)
|
log.Debug("Failed to exchange code for token: ", err)
|
||||||
@@ -605,8 +606,8 @@ func processAppleUserInfo(code string) (models.User, error) {
|
|||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func processTwitterUserInfo(code, verifier string) (models.User, error) {
|
func processTwitterUserInfo(code, verifier string) (*models.User, error) {
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
oauth2Token, err := oauth.OAuthProviders.TwitterConfig.Exchange(context.TODO(), code, oauth2.SetAuthURLParam("code_verifier", verifier))
|
oauth2Token, err := oauth.OAuthProviders.TwitterConfig.Exchange(context.TODO(), code, oauth2.SetAuthURLParam("code_verifier", verifier))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to exchange code for token: ", err)
|
log.Debug("Failed to exchange code for token: ", err)
|
||||||
@@ -662,7 +663,7 @@ func processTwitterUserInfo(code, verifier string) (models.User, error) {
|
|||||||
nickname := userRawData["username"].(string)
|
nickname := userRawData["username"].(string)
|
||||||
profilePicture := userRawData["profile_image_url"].(string)
|
profilePicture := userRawData["profile_image_url"].(string)
|
||||||
|
|
||||||
user = models.User{
|
user = &models.User{
|
||||||
GivenName: &firstName,
|
GivenName: &firstName,
|
||||||
FamilyName: &lastName,
|
FamilyName: &lastName,
|
||||||
Picture: &profilePicture,
|
Picture: &profilePicture,
|
||||||
@@ -673,8 +674,8 @@ func processTwitterUserInfo(code, verifier string) (models.User, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// process microsoft user information
|
// process microsoft user information
|
||||||
func processMicrosoftUserInfo(code string) (models.User, error) {
|
func processMicrosoftUserInfo(code string) (*models.User, error) {
|
||||||
user := models.User{}
|
var user *models.User
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
oauth2Token, err := oauth.OAuthProviders.MicrosoftConfig.Exchange(ctx, code)
|
oauth2Token, err := oauth.OAuthProviders.MicrosoftConfig.Exchange(ctx, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -175,11 +175,12 @@ func VerifyEmailHandler() gin.HandlerFunc {
|
|||||||
go func() {
|
go func() {
|
||||||
if isSignUp {
|
if isSignUp {
|
||||||
utils.RegisterEvent(c, constants.UserSignUpWebhookEvent, loginMethod, user)
|
utils.RegisterEvent(c, constants.UserSignUpWebhookEvent, loginMethod, user)
|
||||||
|
// User is also logged in with signup
|
||||||
|
utils.RegisterEvent(c, constants.UserLoginWebhookEvent, loginMethod, user)
|
||||||
} else {
|
} else {
|
||||||
utils.RegisterEvent(c, constants.UserLoginWebhookEvent, loginMethod, user)
|
utils.RegisterEvent(c, constants.UserLoginWebhookEvent, loginMethod, user)
|
||||||
}
|
}
|
||||||
|
db.Provider.AddSession(c, &models.Session{
|
||||||
db.Provider.AddSession(c, models.Session{
|
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
UserAgent: utils.GetUserAgent(c.Request),
|
UserAgent: utils.GetUserAgent(c.Request),
|
||||||
IP: utils.GetIP(c.Request),
|
IP: utils.GetIP(c.Request),
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
type provider struct {
|
type provider struct {
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
sessionStore *stores.SessionStore
|
sessionStore *stores.SessionStore
|
||||||
|
mfasessionStore *stores.SessionStore
|
||||||
stateStore *stores.StateStore
|
stateStore *stores.StateStore
|
||||||
envStore *stores.EnvStore
|
envStore *stores.EnvStore
|
||||||
}
|
}
|
||||||
@@ -19,6 +20,7 @@ func NewInMemoryProvider() (*provider, error) {
|
|||||||
mutex: sync.Mutex{},
|
mutex: sync.Mutex{},
|
||||||
envStore: stores.NewEnvStore(),
|
envStore: stores.NewEnvStore(),
|
||||||
sessionStore: stores.NewSessionStore(),
|
sessionStore: stores.NewSessionStore(),
|
||||||
|
mfasessionStore: stores.NewSessionStore(),
|
||||||
stateStore: stores.NewStateStore(),
|
stateStore: stores.NewStateStore(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,27 @@ func (c *provider) DeleteSessionForNamespace(namespace string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMfaSession sets the mfa session with key and value of userId
|
||||||
|
func (c *provider) SetMfaSession(userId, key string, expiration int64) error {
|
||||||
|
c.mfasessionStore.Set(userId, key, userId, expiration)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMfaSession returns value of given mfa session
|
||||||
|
func (c *provider) GetMfaSession(userId, key string) (string, error) {
|
||||||
|
val := c.mfasessionStore.Get(userId, key)
|
||||||
|
if val == "" {
|
||||||
|
return "", fmt.Errorf("Not found")
|
||||||
|
}
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteMfaSession deletes given mfa session from in-memory store.
|
||||||
|
func (c *provider) DeleteMfaSession(userId, key string) error {
|
||||||
|
c.mfasessionStore.Remove(userId, key)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SetState sets the state in the in-memory store.
|
// SetState sets the state in the in-memory store.
|
||||||
func (c *provider) SetState(key, state string) error {
|
func (c *provider) SetState(key, state string) error {
|
||||||
if os.Getenv("ENV") != constants.TestEnv {
|
if os.Getenv("ENV") != constants.TestEnv {
|
||||||
|
@@ -112,4 +112,15 @@ func ProviderTests(t *testing.T, p Provider) {
|
|||||||
key, err = p.GetUserSession("auth_provider1:124", "access_token_key")
|
key, err = p.GetUserSession("auth_provider1:124", "access_token_key")
|
||||||
assert.Empty(t, key)
|
assert.Empty(t, key)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
err = p.SetMfaSession("auth_provider:123", "session123", time.Now().Add(60*time.Second).Unix())
|
||||||
|
assert.NoError(t, err)
|
||||||
|
key, err = p.GetMfaSession("auth_provider:123", "session123")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "auth_provider:123", key)
|
||||||
|
err = p.DeleteMfaSession("auth_provider:123", "session123")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
key, err = p.GetMfaSession("auth_provider:123", "session123")
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Empty(t, key)
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,12 @@ type Provider interface {
|
|||||||
DeleteAllUserSessions(userId string) error
|
DeleteAllUserSessions(userId string) error
|
||||||
// DeleteSessionForNamespace deletes the session for a given namespace
|
// DeleteSessionForNamespace deletes the session for a given namespace
|
||||||
DeleteSessionForNamespace(namespace string) error
|
DeleteSessionForNamespace(namespace string) error
|
||||||
|
// SetMfaSession sets the mfa session with key and value of userId
|
||||||
|
SetMfaSession(userId, key string, expiration int64) error
|
||||||
|
// GetMfaSession returns value of given mfa session
|
||||||
|
GetMfaSession(userId, key string) (string, error)
|
||||||
|
// DeleteMfaSession deletes given mfa session from in-memory store.
|
||||||
|
DeleteMfaSession(userId, key string) error
|
||||||
|
|
||||||
// SetState sets the login state (key, value form) in the session store
|
// SetState sets the login state (key, value form) in the session store
|
||||||
SetState(key, state string) error
|
SetState(key, state string) error
|
||||||
|
@@ -16,6 +16,8 @@ var (
|
|||||||
envStorePrefix = "authorizer_env"
|
envStorePrefix = "authorizer_env"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const mfaSessionPrefix = "mfa_sess_"
|
||||||
|
|
||||||
// SetUserSession sets the user session for given user identifier in form recipe:user_id
|
// SetUserSession sets the user session for given user identifier in form recipe:user_id
|
||||||
func (c *provider) SetUserSession(userId, key, token string, expiration int64) error {
|
func (c *provider) SetUserSession(userId, key, token string, expiration int64) error {
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
@@ -91,6 +93,37 @@ func (c *provider) DeleteSessionForNamespace(namespace string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMfaSession sets the mfa session with key and value of userId
|
||||||
|
func (c *provider) SetMfaSession(userId, key string, expiration int64) error {
|
||||||
|
currentTime := time.Now()
|
||||||
|
expireTime := time.Unix(expiration, 0)
|
||||||
|
duration := expireTime.Sub(currentTime)
|
||||||
|
err := c.store.Set(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, userId, key), userId, duration).Err()
|
||||||
|
if err != nil {
|
||||||
|
log.Debug("Error saving user session to redis: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMfaSession returns value of given mfa session
|
||||||
|
func (c *provider) GetMfaSession(userId, key string) (string, error) {
|
||||||
|
data, err := c.store.Get(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, userId, key)).Result()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteMfaSession deletes given mfa session from in-memory store.
|
||||||
|
func (c *provider) DeleteMfaSession(userId, key string) error {
|
||||||
|
if err := c.store.Del(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, userId, key)).Err(); err != nil {
|
||||||
|
log.Debug("Error deleting user session from redis: ", err)
|
||||||
|
// continue
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SetState sets the state in redis store.
|
// SetState sets the state in redis store.
|
||||||
func (c *provider) SetState(key, value string) error {
|
func (c *provider) SetState(key, value string) error {
|
||||||
err := c.store.Set(c.ctx, stateStorePrefix+key, value, 0).Err()
|
err := c.store.Set(c.ctx, stateStorePrefix+key, value, 0).Err()
|
||||||
|
@@ -10,11 +10,16 @@ import (
|
|||||||
githubOAuth2 "golang.org/x/oauth2/github"
|
githubOAuth2 "golang.org/x/oauth2/github"
|
||||||
linkedInOAuth2 "golang.org/x/oauth2/linkedin"
|
linkedInOAuth2 "golang.org/x/oauth2/linkedin"
|
||||||
microsoftOAuth2 "golang.org/x/oauth2/microsoft"
|
microsoftOAuth2 "golang.org/x/oauth2/microsoft"
|
||||||
|
"google.golang.org/appengine/log"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/memorystore"
|
"github.com/authorizerdev/authorizer/server/memorystore"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
microsoftCommonTenant = "common"
|
||||||
|
)
|
||||||
|
|
||||||
// OAuthProviders is a struct that contains reference all the OAuth providers
|
// OAuthProviders is a struct that contains reference all the OAuth providers
|
||||||
type OAuthProvider struct {
|
type OAuthProvider struct {
|
||||||
GoogleConfig *oauth2.Config
|
GoogleConfig *oauth2.Config
|
||||||
@@ -171,12 +176,16 @@ func InitOAuth() error {
|
|||||||
microsoftClientSecret = ""
|
microsoftClientSecret = ""
|
||||||
}
|
}
|
||||||
microsoftActiveDirTenantID, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyMicrosoftActiveDirectoryTenantID)
|
microsoftActiveDirTenantID, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyMicrosoftActiveDirectoryTenantID)
|
||||||
if err != nil {
|
if err != nil || microsoftActiveDirTenantID == "" {
|
||||||
microsoftActiveDirTenantID = ""
|
microsoftActiveDirTenantID = microsoftCommonTenant
|
||||||
|
}
|
||||||
|
if microsoftClientID != "" && microsoftClientSecret != "" {
|
||||||
|
if microsoftActiveDirTenantID == microsoftCommonTenant {
|
||||||
|
ctx = oidc.InsecureIssuerURLContext(ctx, fmt.Sprintf("https://login.microsoftonline.com/%s/v2.0", microsoftActiveDirTenantID))
|
||||||
}
|
}
|
||||||
if microsoftClientID != "" && microsoftClientSecret != "" && microsoftActiveDirTenantID != "" {
|
|
||||||
p, err := oidc.NewProvider(ctx, fmt.Sprintf("https://login.microsoftonline.com/%s/v2.0", microsoftActiveDirTenantID))
|
p, err := oidc.NewProvider(ctx, fmt.Sprintf("https://login.microsoftonline.com/%s/v2.0", microsoftActiveDirTenantID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debugf(ctx, "Error while creating OIDC provider for Microsoft: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
OIDCProviders.MicrosoftOIDC = p
|
OIDCProviders.MicrosoftOIDC = p
|
||||||
|
@@ -47,7 +47,7 @@ func AddEmailTemplateResolver(ctx context.Context, params model.AddEmailTemplate
|
|||||||
design = ""
|
design = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.Provider.AddEmailTemplate(ctx, models.EmailTemplate{
|
_, err = db.Provider.AddEmailTemplate(ctx, &models.EmailTemplate{
|
||||||
EventName: params.EventName,
|
EventName: params.EventName,
|
||||||
Template: params.Template,
|
Template: params.Template,
|
||||||
Subject: params.Subject,
|
Subject: params.Subject,
|
||||||
|
@@ -43,7 +43,7 @@ func AddWebhookResolver(ctx context.Context, params model.AddWebhookRequest) (*m
|
|||||||
if params.EventDescription == nil {
|
if params.EventDescription == nil {
|
||||||
params.EventDescription = refs.NewStringRef(strings.Join(strings.Split(params.EventName, "."), " "))
|
params.EventDescription = refs.NewStringRef(strings.Join(strings.Split(params.EventName, "."), " "))
|
||||||
}
|
}
|
||||||
_, err = db.Provider.AddWebhook(ctx, models.Webhook{
|
_, err = db.Provider.AddWebhook(ctx, &models.Webhook{
|
||||||
EventDescription: refs.StringValue(params.EventDescription),
|
EventDescription: refs.StringValue(params.EventDescription),
|
||||||
EventName: params.EventName,
|
EventName: params.EventName,
|
||||||
EndPoint: params.Endpoint,
|
EndPoint: params.Endpoint,
|
||||||
|
@@ -25,7 +25,6 @@ func EmailTemplatesResolver(ctx context.Context, params *model.PaginatedInput) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
pagination := utils.GetPagination(params)
|
pagination := utils.GetPagination(params)
|
||||||
|
|
||||||
emailTemplates, err := db.Provider.ListEmailTemplate(ctx, pagination)
|
emailTemplates, err := db.Provider.ListEmailTemplate(ctx, pagination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("failed to get email templates: ", err)
|
log.Debug("failed to get email templates: ", err)
|
||||||
|
@@ -81,7 +81,7 @@ func ForgotPasswordResolver(ctx context.Context, params model.ForgotPasswordInpu
|
|||||||
log.Debug("Failed to create verification token", err)
|
log.Debug("Failed to create verification token", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
_, err = db.Provider.AddVerificationRequest(ctx, models.VerificationRequest{
|
_, err = db.Provider.AddVerificationRequest(ctx, &models.VerificationRequest{
|
||||||
Token: verificationToken,
|
Token: verificationToken,
|
||||||
Identifier: constants.VerificationTypeForgotPassword,
|
Identifier: constants.VerificationTypeForgotPassword,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
@@ -105,7 +105,7 @@ func InviteMembersResolver(ctx context.Context, params model.InviteMemberInput)
|
|||||||
defaultRoles = strings.Split(defaultRolesString, ",")
|
defaultRoles = strings.Split(defaultRolesString, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
user := models.User{
|
user := &models.User{
|
||||||
Email: email,
|
Email: email,
|
||||||
Roles: strings.Join(defaultRoles, ","),
|
Roles: strings.Join(defaultRoles, ","),
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ func InviteMembersResolver(ctx context.Context, params model.InviteMemberInput)
|
|||||||
log.Debug("Failed to create verification token: ", err)
|
log.Debug("Failed to create verification token: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
verificationRequest := models.VerificationRequest{
|
verificationRequest := &models.VerificationRequest{
|
||||||
Token: verificationToken,
|
Token: verificationToken,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
Email: email,
|
Email: email,
|
||||||
|
@@ -113,16 +113,25 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
|
|||||||
// If email service is not enabled continue the process in any way
|
// If email service is not enabled continue the process in any way
|
||||||
if refs.BoolValue(user.IsMultiFactorAuthEnabled) && isEmailServiceEnabled && !isMFADisabled {
|
if refs.BoolValue(user.IsMultiFactorAuthEnabled) && isEmailServiceEnabled && !isMFADisabled {
|
||||||
otp := utils.GenerateOTP()
|
otp := utils.GenerateOTP()
|
||||||
|
expires := time.Now().Add(1 * time.Minute).Unix()
|
||||||
otpData, err := db.Provider.UpsertOTP(ctx, &models.OTP{
|
otpData, err := db.Provider.UpsertOTP(ctx, &models.OTP{
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Otp: otp,
|
Otp: otp,
|
||||||
ExpiresAt: time.Now().Add(1 * time.Minute).Unix(),
|
ExpiresAt: expires,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to add otp: ", err)
|
log.Debug("Failed to add otp: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mfaSession := uuid.NewString()
|
||||||
|
err = memorystore.Provider.SetMfaSession(user.ID, mfaSession, expires)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug("Failed to add mfasession: ", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cookie.SetMfaSession(gc, mfaSession)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// exec it as go routine so that we can reduce the api latency
|
// exec it as go routine so that we can reduce the api latency
|
||||||
go email.SendEmail([]string{params.Email}, constants.VerificationTypeOTP, map[string]interface{}{
|
go email.SendEmail([]string{params.Email}, constants.VerificationTypeOTP, map[string]interface{}{
|
||||||
@@ -137,7 +146,7 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
|
|||||||
|
|
||||||
return &model.AuthResponse{
|
return &model.AuthResponse{
|
||||||
Message: "Please check the OTP in your inbox",
|
Message: "Please check the OTP in your inbox",
|
||||||
ShouldShowOtpScreen: refs.NewBoolRef(true),
|
ShouldShowEmailOtpScreen: refs.NewBoolRef(true),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +212,7 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, constants.AuthRecipeMethodBasicAuth, user)
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, constants.AuthRecipeMethodBasicAuth, user)
|
||||||
db.Provider.AddSession(ctx, models.Session{
|
db.Provider.AddSession(ctx, &models.Session{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
UserAgent: utils.GetUserAgent(gc.Request),
|
UserAgent: utils.GetUserAgent(gc.Request),
|
||||||
IP: utils.GetIP(gc.Request),
|
IP: utils.GetIP(gc.Request),
|
||||||
|
@@ -55,7 +55,7 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
|||||||
|
|
||||||
inputRoles := []string{}
|
inputRoles := []string{}
|
||||||
|
|
||||||
user := models.User{
|
user := &models.User{
|
||||||
Email: params.Email,
|
Email: params.Email,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ func MagicLinkLoginResolver(ctx context.Context, params model.MagicLinkLoginInpu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to create verification token: ", err)
|
log.Debug("Failed to create verification token: ", err)
|
||||||
}
|
}
|
||||||
_, err = db.Provider.AddVerificationRequest(ctx, models.VerificationRequest{
|
_, err = db.Provider.AddVerificationRequest(ctx, &models.VerificationRequest{
|
||||||
Token: verificationToken,
|
Token: verificationToken,
|
||||||
Identifier: verificationType,
|
Identifier: verificationType,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
@@ -101,12 +101,6 @@ func MetaResolver(ctx context.Context) (*model.Meta, error) {
|
|||||||
microsoftClientSecret = ""
|
microsoftClientSecret = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
microsoftActiveDirTenantID, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeyMicrosoftActiveDirectoryTenantID)
|
|
||||||
if err != nil {
|
|
||||||
log.Debug("Failed to get Microsoft Active Directory Tenant ID from environment variable", err)
|
|
||||||
microsoftActiveDirTenantID = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
isBasicAuthDisabled, err := memorystore.Provider.GetBoolStoreEnvVariable(constants.EnvKeyDisableBasicAuthentication)
|
isBasicAuthDisabled, err := memorystore.Provider.GetBoolStoreEnvVariable(constants.EnvKeyDisableBasicAuthentication)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to get Disable Basic Authentication from environment variable", err)
|
log.Debug("Failed to get Disable Basic Authentication from environment variable", err)
|
||||||
@@ -152,7 +146,7 @@ func MetaResolver(ctx context.Context) (*model.Meta, error) {
|
|||||||
IsLinkedinLoginEnabled: linkedClientID != "" && linkedInClientSecret != "",
|
IsLinkedinLoginEnabled: linkedClientID != "" && linkedInClientSecret != "",
|
||||||
IsAppleLoginEnabled: appleClientID != "" && appleClientSecret != "",
|
IsAppleLoginEnabled: appleClientID != "" && appleClientSecret != "",
|
||||||
IsTwitterLoginEnabled: twitterClientID != "" && twitterClientSecret != "",
|
IsTwitterLoginEnabled: twitterClientID != "" && twitterClientSecret != "",
|
||||||
IsMicrosoftLoginEnabled: microsoftClientID != "" && microsoftClientSecret != "" && microsoftActiveDirTenantID != "",
|
IsMicrosoftLoginEnabled: microsoftClientID != "" && microsoftClientSecret != "",
|
||||||
IsBasicAuthenticationEnabled: !isBasicAuthDisabled,
|
IsBasicAuthenticationEnabled: !isBasicAuthDisabled,
|
||||||
IsEmailVerificationEnabled: !isEmailVerificationDisabled,
|
IsEmailVerificationEnabled: !isEmailVerificationDisabled,
|
||||||
IsMagicLinkLoginEnabled: !isMagicLinkLoginDisabled,
|
IsMagicLinkLoginEnabled: !isMagicLinkLoginDisabled,
|
||||||
|
@@ -122,22 +122,32 @@ func MobileLoginResolver(ctx context.Context, params model.MobileLoginInput) (*m
|
|||||||
smsBody := strings.Builder{}
|
smsBody := strings.Builder{}
|
||||||
smsBody.WriteString("Your verification code is: ")
|
smsBody.WriteString("Your verification code is: ")
|
||||||
smsBody.WriteString(smsCode)
|
smsBody.WriteString(smsCode)
|
||||||
|
expires := time.Now().Add(duration).Unix()
|
||||||
_, err := db.Provider.UpsertOTP(ctx, &models.OTP{
|
_, err := db.Provider.UpsertOTP(ctx, &models.OTP{
|
||||||
PhoneNumber: params.PhoneNumber,
|
PhoneNumber: params.PhoneNumber,
|
||||||
Otp: smsCode,
|
Otp: smsCode,
|
||||||
ExpiresAt: time.Now().Add(duration).Unix(),
|
ExpiresAt: expires,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("error while upserting OTP: ", err.Error())
|
log.Debug("error while upserting OTP: ", err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mfaSession := uuid.NewString()
|
||||||
|
err = memorystore.Provider.SetMfaSession(user.ID, mfaSession, expires)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug("Failed to add mfasession: ", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cookie.SetMfaSession(gc, mfaSession)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, constants.AuthRecipeMethodMobileBasicAuth, *user)
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, constants.AuthRecipeMethodMobileBasicAuth, user)
|
||||||
smsproviders.SendSMS(params.PhoneNumber, smsBody.String())
|
smsproviders.SendSMS(params.PhoneNumber, smsBody.String())
|
||||||
}()
|
}()
|
||||||
return &model.AuthResponse{
|
return &model.AuthResponse{
|
||||||
Message: "Please check the OTP",
|
Message: "Please check the OTP",
|
||||||
ShouldShowOtpScreen: refs.NewBoolRef(true),
|
ShouldShowMobileOtpScreen: refs.NewBoolRef(true),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +178,7 @@ func MobileLoginResolver(ctx context.Context, params model.MobileLoginInput) (*m
|
|||||||
nonce = uuid.New().String()
|
nonce = uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
authToken, err := token.CreateAuthToken(gc, *user, roles, scope, constants.AuthRecipeMethodMobileBasicAuth, nonce, code)
|
authToken, err := token.CreateAuthToken(gc, user, roles, scope, constants.AuthRecipeMethodMobileBasicAuth, nonce, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to create auth token", err)
|
log.Debug("Failed to create auth token", err)
|
||||||
return res, err
|
return res, err
|
||||||
@@ -207,8 +217,8 @@ func MobileLoginResolver(ctx context.Context, params model.MobileLoginInput) (*m
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, constants.AuthRecipeMethodMobileBasicAuth, *user)
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, constants.AuthRecipeMethodMobileBasicAuth, user)
|
||||||
db.Provider.AddSession(ctx, models.Session{
|
db.Provider.AddSession(ctx, &models.Session{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
UserAgent: utils.GetUserAgent(gc.Request),
|
UserAgent: utils.GetUserAgent(gc.Request),
|
||||||
IP: utils.GetIP(gc.Request),
|
IP: utils.GetIP(gc.Request),
|
||||||
|
@@ -130,7 +130,7 @@ func MobileSignupResolver(ctx context.Context, params *model.MobileSignUpInput)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user := models.User{
|
user := &models.User{
|
||||||
Email: emailInput,
|
Email: emailInput,
|
||||||
PhoneNumber: &mobile,
|
PhoneNumber: &mobile,
|
||||||
}
|
}
|
||||||
@@ -223,10 +223,11 @@ func MobileSignupResolver(ctx context.Context, params *model.MobileSignUpInput)
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
smsproviders.SendSMS(mobile, smsBody.String())
|
smsproviders.SendSMS(mobile, smsBody.String())
|
||||||
|
utils.RegisterEvent(ctx, constants.UserCreatedWebhookEvent, constants.AuthRecipeMethodBasicAuth, user)
|
||||||
}()
|
}()
|
||||||
return &model.AuthResponse{
|
return &model.AuthResponse{
|
||||||
Message: "Please check the OTP in your inbox",
|
Message: "Please check the OTP in your inbox",
|
||||||
ShouldShowOtpScreen: refs.NewBoolRef(true),
|
ShouldShowMobileOtpScreen: refs.NewBoolRef(true),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +299,9 @@ func MobileSignupResolver(ctx context.Context, params *model.MobileSignUpInput)
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, constants.AuthRecipeMethodMobileBasicAuth, user)
|
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, constants.AuthRecipeMethodMobileBasicAuth, user)
|
||||||
db.Provider.AddSession(ctx, models.Session{
|
// User is also logged in with signup
|
||||||
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, constants.AuthRecipeMethodMobileBasicAuth, user)
|
||||||
|
db.Provider.AddSession(ctx, &models.Session{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
UserAgent: utils.GetUserAgent(gc.Request),
|
UserAgent: utils.GetUserAgent(gc.Request),
|
||||||
IP: utils.GetIP(gc.Request),
|
IP: utils.GetIP(gc.Request),
|
||||||
|
@@ -32,7 +32,7 @@ func ResendOTPResolver(ctx context.Context, params model.ResendOTPRequest) (*mod
|
|||||||
log.Debug("Email or phone number is required")
|
log.Debug("Email or phone number is required")
|
||||||
return nil, errors.New("email or phone number is required")
|
return nil, errors.New("email or phone number is required")
|
||||||
}
|
}
|
||||||
var user models.User
|
var user *models.User
|
||||||
var err error
|
var err error
|
||||||
if email != "" {
|
if email != "" {
|
||||||
isEmailServiceEnabled, err := memorystore.Provider.GetBoolStoreEnvVariable(constants.EnvKeyIsEmailServiceEnabled)
|
isEmailServiceEnabled, err := memorystore.Provider.GetBoolStoreEnvVariable(constants.EnvKeyIsEmailServiceEnabled)
|
||||||
@@ -47,10 +47,7 @@ func ResendOTPResolver(ctx context.Context, params model.ResendOTPRequest) (*mod
|
|||||||
log.Debug("Email service not enabled: ", err)
|
log.Debug("Email service not enabled: ", err)
|
||||||
return nil, errors.New("email service not enabled")
|
return nil, errors.New("email service not enabled")
|
||||||
}
|
}
|
||||||
// TODO fix after refs fixes
|
user, err = db.Provider.GetUserByPhoneNumber(ctx, phoneNumber)
|
||||||
var u *models.User
|
|
||||||
u, err = db.Provider.GetUserByPhoneNumber(ctx, phoneNumber)
|
|
||||||
user = *u
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to get user by email: ", err)
|
log.Debug("Failed to get user by email: ", err)
|
||||||
|
@@ -67,7 +67,7 @@ func ResendVerifyEmailResolver(ctx context.Context, params model.ResendVerifyEma
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to create verification token: ", err)
|
log.Debug("Failed to create verification token: ", err)
|
||||||
}
|
}
|
||||||
_, err = db.Provider.AddVerificationRequest(ctx, models.VerificationRequest{
|
_, err = db.Provider.AddVerificationRequest(ctx, &models.VerificationRequest{
|
||||||
Token: verificationToken,
|
Token: verificationToken,
|
||||||
Identifier: params.Identifier,
|
Identifier: params.Identifier,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
@@ -81,6 +81,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
|||||||
log.Debug("Failed to get user by email: ", err)
|
log.Debug("Failed to get user by email: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if existingUser != nil {
|
||||||
if existingUser.EmailVerifiedAt != nil {
|
if existingUser.EmailVerifiedAt != nil {
|
||||||
// email is verified
|
// email is verified
|
||||||
log.Debug("Email is already verified and signed up.")
|
log.Debug("Email is already verified and signed up.")
|
||||||
@@ -89,6 +90,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
|||||||
log.Debug("Email is already signed up. Verification pending...")
|
log.Debug("Email is already signed up. Verification pending...")
|
||||||
return res, fmt.Errorf("%s has already signed up. please complete the email verification process or reset the password", params.Email)
|
return res, fmt.Errorf("%s has already signed up. please complete the email verification process or reset the password", params.Email)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inputRoles := []string{}
|
inputRoles := []string{}
|
||||||
if len(params.Roles) > 0 {
|
if len(params.Roles) > 0 {
|
||||||
@@ -116,13 +118,10 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
|||||||
inputRoles = strings.Split(inputRolesString, ",")
|
inputRoles = strings.Split(inputRolesString, ",")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
user := &models.User{
|
||||||
user := models.User{
|
|
||||||
Email: params.Email,
|
Email: params.Email,
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Roles = strings.Join(inputRoles, ",")
|
user.Roles = strings.Join(inputRoles, ",")
|
||||||
|
|
||||||
password, _ := crypto.EncryptPassword(params.Password)
|
password, _ := crypto.EncryptPassword(params.Password)
|
||||||
user.Password = &password
|
user.Password = &password
|
||||||
|
|
||||||
@@ -208,7 +207,7 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
|||||||
log.Debug("Failed to create verification token: ", err)
|
log.Debug("Failed to create verification token: ", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
_, err = db.Provider.AddVerificationRequest(ctx, models.VerificationRequest{
|
_, err = db.Provider.AddVerificationRequest(ctx, &models.VerificationRequest{
|
||||||
Token: verificationToken,
|
Token: verificationToken,
|
||||||
Identifier: verificationType,
|
Identifier: verificationType,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
@@ -302,7 +301,9 @@ func SignupResolver(ctx context.Context, params model.SignUpInput) (*model.AuthR
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, constants.AuthRecipeMethodBasicAuth, user)
|
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, constants.AuthRecipeMethodBasicAuth, user)
|
||||||
db.Provider.AddSession(ctx, models.Session{
|
// User is also logged in with signup
|
||||||
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, constants.AuthRecipeMethodBasicAuth, user)
|
||||||
|
db.Provider.AddSession(ctx, &models.Session{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
UserAgent: utils.GetUserAgent(gc.Request),
|
UserAgent: utils.GetUserAgent(gc.Request),
|
||||||
IP: utils.GetIP(gc.Request),
|
IP: utils.GetIP(gc.Request),
|
||||||
|
@@ -34,7 +34,7 @@ func UpdateEmailTemplateResolver(ctx context.Context, params model.UpdateEmailTe
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
emailTemplateDetails := models.EmailTemplate{
|
emailTemplateDetails := &models.EmailTemplate{
|
||||||
ID: emailTemplate.ID,
|
ID: emailTemplate.ID,
|
||||||
Key: emailTemplate.ID,
|
Key: emailTemplate.ID,
|
||||||
EventName: emailTemplate.EventName,
|
EventName: emailTemplate.EventName,
|
||||||
|
@@ -33,7 +33,7 @@ func clearSessionIfRequired(currentData, updatedData map[string]interface{}) {
|
|||||||
isCurrentGithubLoginEnabled := currentData[constants.EnvKeyGithubClientID] != nil && currentData[constants.EnvKeyGithubClientSecret] != nil && currentData[constants.EnvKeyGithubClientID].(string) != "" && currentData[constants.EnvKeyGithubClientSecret].(string) != ""
|
isCurrentGithubLoginEnabled := currentData[constants.EnvKeyGithubClientID] != nil && currentData[constants.EnvKeyGithubClientSecret] != nil && currentData[constants.EnvKeyGithubClientID].(string) != "" && currentData[constants.EnvKeyGithubClientSecret].(string) != ""
|
||||||
isCurrentLinkedInLoginEnabled := currentData[constants.EnvKeyLinkedInClientID] != nil && currentData[constants.EnvKeyLinkedInClientSecret] != nil && currentData[constants.EnvKeyLinkedInClientID].(string) != "" && currentData[constants.EnvKeyLinkedInClientSecret].(string) != ""
|
isCurrentLinkedInLoginEnabled := currentData[constants.EnvKeyLinkedInClientID] != nil && currentData[constants.EnvKeyLinkedInClientSecret] != nil && currentData[constants.EnvKeyLinkedInClientID].(string) != "" && currentData[constants.EnvKeyLinkedInClientSecret].(string) != ""
|
||||||
isCurrentTwitterLoginEnabled := currentData[constants.EnvKeyTwitterClientID] != nil && currentData[constants.EnvKeyTwitterClientSecret] != nil && currentData[constants.EnvKeyTwitterClientID].(string) != "" && currentData[constants.EnvKeyTwitterClientSecret].(string) != ""
|
isCurrentTwitterLoginEnabled := currentData[constants.EnvKeyTwitterClientID] != nil && currentData[constants.EnvKeyTwitterClientSecret] != nil && currentData[constants.EnvKeyTwitterClientID].(string) != "" && currentData[constants.EnvKeyTwitterClientSecret].(string) != ""
|
||||||
isCurrentMicrosoftLoginEnabled := currentData[constants.EnvKeyMicrosoftClientID] != nil && currentData[constants.EnvKeyMicrosoftClientSecret] != nil && currentData[constants.EnvKeyMicrosoftActiveDirectoryTenantID] != nil && currentData[constants.EnvKeyMicrosoftClientID].(string) != "" && currentData[constants.EnvKeyMicrosoftClientSecret].(string) != "" && currentData[constants.EnvKeyMicrosoftActiveDirectoryTenantID].(string) != ""
|
isCurrentMicrosoftLoginEnabled := currentData[constants.EnvKeyMicrosoftClientID] != nil && currentData[constants.EnvKeyMicrosoftClientSecret] != nil && currentData[constants.EnvKeyMicrosoftClientID].(string) != "" && currentData[constants.EnvKeyMicrosoftClientSecret].(string) != ""
|
||||||
|
|
||||||
isUpdatedBasicAuthEnabled := !updatedData[constants.EnvKeyDisableBasicAuthentication].(bool)
|
isUpdatedBasicAuthEnabled := !updatedData[constants.EnvKeyDisableBasicAuthentication].(bool)
|
||||||
isUpdatedMobileBasicAuthEnabled := !updatedData[constants.EnvKeyDisableMobileBasicAuthentication].(bool)
|
isUpdatedMobileBasicAuthEnabled := !updatedData[constants.EnvKeyDisableMobileBasicAuthentication].(bool)
|
||||||
@@ -44,7 +44,7 @@ func clearSessionIfRequired(currentData, updatedData map[string]interface{}) {
|
|||||||
isUpdatedGithubLoginEnabled := updatedData[constants.EnvKeyGithubClientID] != nil && updatedData[constants.EnvKeyGithubClientSecret] != nil && updatedData[constants.EnvKeyGithubClientID].(string) != "" && updatedData[constants.EnvKeyGithubClientSecret].(string) != ""
|
isUpdatedGithubLoginEnabled := updatedData[constants.EnvKeyGithubClientID] != nil && updatedData[constants.EnvKeyGithubClientSecret] != nil && updatedData[constants.EnvKeyGithubClientID].(string) != "" && updatedData[constants.EnvKeyGithubClientSecret].(string) != ""
|
||||||
isUpdatedLinkedInLoginEnabled := updatedData[constants.EnvKeyLinkedInClientID] != nil && updatedData[constants.EnvKeyLinkedInClientSecret] != nil && updatedData[constants.EnvKeyLinkedInClientID].(string) != "" && updatedData[constants.EnvKeyLinkedInClientSecret].(string) != ""
|
isUpdatedLinkedInLoginEnabled := updatedData[constants.EnvKeyLinkedInClientID] != nil && updatedData[constants.EnvKeyLinkedInClientSecret] != nil && updatedData[constants.EnvKeyLinkedInClientID].(string) != "" && updatedData[constants.EnvKeyLinkedInClientSecret].(string) != ""
|
||||||
isUpdatedTwitterLoginEnabled := updatedData[constants.EnvKeyTwitterClientID] != nil && updatedData[constants.EnvKeyTwitterClientSecret] != nil && updatedData[constants.EnvKeyTwitterClientID].(string) != "" && updatedData[constants.EnvKeyTwitterClientSecret].(string) != ""
|
isUpdatedTwitterLoginEnabled := updatedData[constants.EnvKeyTwitterClientID] != nil && updatedData[constants.EnvKeyTwitterClientSecret] != nil && updatedData[constants.EnvKeyTwitterClientID].(string) != "" && updatedData[constants.EnvKeyTwitterClientSecret].(string) != ""
|
||||||
isUpdatedMicrosoftLoginEnabled := updatedData[constants.EnvKeyMicrosoftClientID] != nil && updatedData[constants.EnvKeyMicrosoftClientSecret] != nil && updatedData[constants.EnvKeyMicrosoftActiveDirectoryTenantID] != nil && updatedData[constants.EnvKeyMicrosoftClientID].(string) != "" && updatedData[constants.EnvKeyMicrosoftClientSecret].(string) != "" && updatedData[constants.EnvKeyMicrosoftActiveDirectoryTenantID].(string) != ""
|
isUpdatedMicrosoftLoginEnabled := updatedData[constants.EnvKeyMicrosoftClientID] != nil && updatedData[constants.EnvKeyMicrosoftClientSecret] != nil && updatedData[constants.EnvKeyMicrosoftClientID].(string) != "" && updatedData[constants.EnvKeyMicrosoftClientSecret].(string) != ""
|
||||||
|
|
||||||
if isCurrentBasicAuthEnabled && !isUpdatedBasicAuthEnabled {
|
if isCurrentBasicAuthEnabled && !isUpdatedBasicAuthEnabled {
|
||||||
memorystore.Provider.DeleteSessionForNamespace(constants.AuthRecipeMethodBasicAuth)
|
memorystore.Provider.DeleteSessionForNamespace(constants.AuthRecipeMethodBasicAuth)
|
||||||
|
@@ -242,7 +242,7 @@ func UpdateProfileResolver(ctx context.Context, params model.UpdateProfileInput)
|
|||||||
log.Debug("Failed to create verification token: ", err)
|
log.Debug("Failed to create verification token: ", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
_, err = db.Provider.AddVerificationRequest(ctx, models.VerificationRequest{
|
_, err = db.Provider.AddVerificationRequest(ctx, &models.VerificationRequest{
|
||||||
Token: verificationToken,
|
Token: verificationToken,
|
||||||
Identifier: verificationType,
|
Identifier: verificationType,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
@@ -147,7 +147,7 @@ func UpdateUserResolver(ctx context.Context, params model.UpdateUserInput) (*mod
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to create verification token: ", err)
|
log.Debug("Failed to create verification token: ", err)
|
||||||
}
|
}
|
||||||
_, err = db.Provider.AddVerificationRequest(ctx, models.VerificationRequest{
|
_, err = db.Provider.AddVerificationRequest(ctx, &models.VerificationRequest{
|
||||||
Token: verificationToken,
|
Token: verificationToken,
|
||||||
Identifier: verificationType,
|
Identifier: verificationType,
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
@@ -41,7 +41,7 @@ func UpdateWebhookResolver(ctx context.Context, params model.UpdateWebhookReques
|
|||||||
}
|
}
|
||||||
headersString = string(headerBytes)
|
headersString = string(headerBytes)
|
||||||
}
|
}
|
||||||
webhookDetails := models.Webhook{
|
webhookDetails := &models.Webhook{
|
||||||
ID: webhook.ID,
|
ID: webhook.ID,
|
||||||
Key: webhook.ID,
|
Key: webhook.ID,
|
||||||
EventName: refs.StringValue(webhook.EventName),
|
EventName: refs.StringValue(webhook.EventName),
|
||||||
|
@@ -27,7 +27,6 @@ func VerificationRequestsResolver(ctx context.Context, params *model.PaginatedIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
pagination := utils.GetPagination(params)
|
pagination := utils.GetPagination(params)
|
||||||
|
|
||||||
res, err := db.Provider.ListVerificationRequests(ctx, pagination)
|
res, err := db.Provider.ListVerificationRequests(ctx, pagination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to get verification requests: ", err)
|
log.Debug("Failed to get verification requests: ", err)
|
||||||
|
@@ -125,11 +125,13 @@ func VerifyEmailResolver(ctx context.Context, params model.VerifyEmailInput) (*m
|
|||||||
go func() {
|
go func() {
|
||||||
if isSignUp {
|
if isSignUp {
|
||||||
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, loginMethod, user)
|
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, loginMethod, user)
|
||||||
|
// User is also logged in with signup
|
||||||
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, loginMethod, user)
|
||||||
} else {
|
} else {
|
||||||
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, loginMethod, user)
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, loginMethod, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Provider.AddSession(ctx, models.Session{
|
db.Provider.AddSession(ctx, &models.Session{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
UserAgent: utils.GetUserAgent(gc.Request),
|
UserAgent: utils.GetUserAgent(gc.Request),
|
||||||
IP: utils.GetIP(gc.Request),
|
IP: utils.GetIP(gc.Request),
|
||||||
|
@@ -27,6 +27,13 @@ func VerifyOtpResolver(ctx context.Context, params model.VerifyOTPRequest) (*mod
|
|||||||
log.Debug("Failed to get GinContext: ", err)
|
log.Debug("Failed to get GinContext: ", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mfaSession, err := cookie.GetMfaSession(gc)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug("Failed to get otp request by email: ", err)
|
||||||
|
return res, fmt.Errorf(`invalid session: %s`, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
if refs.StringValue(params.Email) == "" && refs.StringValue(params.PhoneNumber) == "" {
|
if refs.StringValue(params.Email) == "" && refs.StringValue(params.PhoneNumber) == "" {
|
||||||
log.Debug("Email or phone number is required")
|
log.Debug("Email or phone number is required")
|
||||||
return res, fmt.Errorf(`email or phone_number is required`)
|
return res, fmt.Errorf(`email or phone_number is required`)
|
||||||
@@ -55,19 +62,23 @@ func VerifyOtpResolver(ctx context.Context, params model.VerifyOTPRequest) (*mod
|
|||||||
log.Debug("Failed to verify otp request: Timeout")
|
log.Debug("Failed to verify otp request: Timeout")
|
||||||
return res, fmt.Errorf("otp expired")
|
return res, fmt.Errorf("otp expired")
|
||||||
}
|
}
|
||||||
var user models.User
|
var user *models.User
|
||||||
if currentField == models.FieldNameEmail {
|
if currentField == models.FieldNameEmail {
|
||||||
user, err = db.Provider.GetUserByEmail(ctx, refs.StringValue(params.Email))
|
user, err = db.Provider.GetUserByEmail(ctx, refs.StringValue(params.Email))
|
||||||
} else {
|
} else {
|
||||||
// TODO fix after refs of db providers are fixed
|
user, err = db.Provider.GetUserByPhoneNumber(ctx, refs.StringValue(params.PhoneNumber))
|
||||||
var u *models.User
|
|
||||||
u, err = db.Provider.GetUserByPhoneNumber(ctx, refs.StringValue(params.PhoneNumber))
|
|
||||||
user = *u
|
|
||||||
}
|
}
|
||||||
if user.ID == "" && err != nil {
|
if user == nil || err != nil {
|
||||||
log.Debug("Failed to get user by email: ", err)
|
fmt.Println("=> failing here....", err)
|
||||||
|
log.Debug("Failed to get user by email or phone number: ", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := memorystore.Provider.GetMfaSession(user.ID, mfaSession); err != nil {
|
||||||
|
log.Debug("Failed to get mfa session: ", err)
|
||||||
|
return res, fmt.Errorf(`invalid session: %s`, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
isSignUp := user.EmailVerifiedAt == nil && user.PhoneNumberVerifiedAt == nil
|
isSignUp := user.EmailVerifiedAt == nil && user.PhoneNumberVerifiedAt == nil
|
||||||
// TODO - Add Login method in DB when we introduce OTP for social media login
|
// TODO - Add Login method in DB when we introduce OTP for social media login
|
||||||
loginMethod := constants.AuthRecipeMethodBasicAuth
|
loginMethod := constants.AuthRecipeMethodBasicAuth
|
||||||
@@ -114,11 +125,13 @@ func VerifyOtpResolver(ctx context.Context, params model.VerifyOTPRequest) (*mod
|
|||||||
db.Provider.DeleteOTP(gc, otp)
|
db.Provider.DeleteOTP(gc, otp)
|
||||||
if isSignUp {
|
if isSignUp {
|
||||||
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, loginMethod, user)
|
utils.RegisterEvent(ctx, constants.UserSignUpWebhookEvent, loginMethod, user)
|
||||||
|
// User is also logged in with signup
|
||||||
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, loginMethod, user)
|
||||||
} else {
|
} else {
|
||||||
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, loginMethod, user)
|
utils.RegisterEvent(ctx, constants.UserLoginWebhookEvent, loginMethod, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Provider.AddSession(ctx, models.Session{
|
db.Provider.AddSession(ctx, &models.Session{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
UserAgent: utils.GetUserAgent(gc.Request),
|
UserAgent: utils.GetUserAgent(gc.Request),
|
||||||
IP: utils.GetIP(gc.Request),
|
IP: utils.GetIP(gc.Request),
|
||||||
|
@@ -25,7 +25,7 @@ func WebhookLogsResolver(ctx context.Context, params *model.ListWebhookLogReques
|
|||||||
return nil, fmt.Errorf("unauthorized")
|
return nil, fmt.Errorf("unauthorized")
|
||||||
}
|
}
|
||||||
|
|
||||||
var pagination model.Pagination
|
var pagination *model.Pagination
|
||||||
var webhookID string
|
var webhookID string
|
||||||
|
|
||||||
if params != nil {
|
if params != nil {
|
||||||
@@ -37,7 +37,7 @@ func WebhookLogsResolver(ctx context.Context, params *model.ListWebhookLogReques
|
|||||||
pagination = utils.GetPagination(nil)
|
pagination = utils.GetPagination(nil)
|
||||||
webhookID = ""
|
webhookID = ""
|
||||||
}
|
}
|
||||||
|
// TODO fix
|
||||||
webhookLogs, err := db.Provider.ListWebhookLogs(ctx, pagination, webhookID)
|
webhookLogs, err := db.Provider.ListWebhookLogs(ctx, pagination, webhookID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("failed to get webhook logs: ", err)
|
log.Debug("failed to get webhook logs: ", err)
|
||||||
|
@@ -25,7 +25,6 @@ func WebhooksResolver(ctx context.Context, params *model.PaginatedInput) (*model
|
|||||||
}
|
}
|
||||||
|
|
||||||
pagination := utils.GetPagination(params)
|
pagination := utils.GetPagination(params)
|
||||||
|
|
||||||
webhooks, err := db.Provider.ListWebhook(ctx, pagination)
|
webhooks, err := db.Provider.ListWebhook(ctx, pagination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("failed to get webhooks: ", err)
|
log.Debug("failed to get webhooks: ", err)
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user