Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add api verifylink for external users #373

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions controllers/external.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,188 @@ exports.externalDeleteTwitterChannel = async (req, res) => {
err.message ? err.message : err.error
)
}
}



module.exports.externalVerifyLink = async (req, response) => {
try {
const user = await UserExternalWallet.findOne({walletId: req.address})
var userId = user.UserId
var { typeSN, idUser, idPost } = req.params
let profileLinedin = null
if (!typeSN || !idUser || !idPost) {
return makeResponseError(response, 400, 'please provide all fields')
}

var linked = false
var deactivate = false
var res = false
switch (typeSN) {
case '1':
let fbProfile = await FbProfile.findOne(
{ UserId: userId },
{ accessToken: 1 }
).lean()
await updateFacebookPages(userId, fbProfile.accessToken, false)
let fbPage = await FbPage.findOne(
{
UserId: userId,
username: idUser,
},
{ token: 1, id: 1 }
).lean()
if (fbProfile && fbPage) {
linked = true
res = await verifyFacebook(idPost, fbPage)

if (res && res.deactivate === true) {
deactivate = true
}
}
break
case '2':
var googleProfile = await GoogleProfile.findOne(
{
UserId: userId,
},
{ refreshToken: 1 }
).lean()

if (googleProfile) {
const data = await rp.post(
'https://oauth2.googleapis.com/token',
{
client_id: oauth.google.googleClientId,
client_secret: oauth.google.googleClientSecret,
refresh_token: googleProfile.refreshToken,
grant_type: 'refresh_token',
}
)
const access_token = data.data.access_token
await GoogleProfile.updateOne(
{ UserId: userId },
{ $set: { accessToken: access_token } }
)
linked = true
res = await verifyYoutube(userId, idPost, access_token)
if (res && res.deactivate === true) deactivate = true
}

break
case '3':
var page = await FbPage.findOne({
$and: [
{ UserId: userId },
{ instagram_id: { $exists: true } },
],
})
if (page) {
linked = true
res = await verifyInsta(userId, idPost)
if (res === 'deactivate') deactivate = true
}

break
case '4':
var twitterProfile = await TwitterProfile.findOne(
{
UserId: userId,
},
{ access_token_key: 1, access_token_secret: 1 }
).lean()
if (twitterProfile) {
linked = true
res = await verifyTwitter(twitterProfile, userId, idPost)
if (res === 'deactivate') deactivate = true
}

break
case '5':
var linkedinProfile = await LinkedinProfile.find(
{ userId },
{ accessToken: 1, pages: 1, linkedinId: 1 }
)
if (linkedinProfile.length) {
linked = true
for (let profile of linkedinProfile) {
res = await verifyLinkedin(profile, idPost)
if (res === true) {
profileLinedin = profile
break
}
if (res === 'deactivate') deactivate = true
}
}

break
case '6':
var tiktokProfile = await TikTokProfile.findOne({
userId,
}).lean()
if (tiktokProfile) {
linked = true
res = await verifytiktok(tiktokProfile, idPost)
if (res === 'deactivate') deactivate = true
}

break
case '7':
var threads = await FbPage.findOne(
{
UserId: userId,
instagram_id: { $exists: true },
threads_id: { $exists: true },
},
{ threads_id: 1, instagram_username: 1 }
).lean()

if (threads) {
linked = true
res = await verifyThread(
idPost,
threads.threads_id,
threads.instagram_username
)

if (res === 'deactivate') deactivate = true
}

break
default:
}

if (!linked)
return makeResponseError(response, 406, 'account not linked')
else if (res === 'lien_invalid')
return makeResponseError(response, 406, 'invalid link')
else if (deactivate)
return makeResponseError(response, 405, 'account deactivated')
else if (res === 'link_not_found')
return makeResponseError(response, 406, 'link not found')
else {
if (typeSN == '7')
return makeResponseData(
response,
200,
'success',
res ? 'true' : 'false',
threads.instagram_username
)
else
return makeResponseData(
response,
200,
'success',
res ? 'true' : 'false',
res === true && typeSN == '5' && profileLinedin?.linkedinId
)
}
} catch (err) {
return makeResponseError(
response,
500,
err.message ? err.message : err.error
)
}
}
6 changes: 5 additions & 1 deletion routes/external.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
externalDeleteLinkedinChannels,
externalDeleteLinkedinChannel,
externalDeleteTwitterChannels,
externalDeleteTwitterChannel
externalDeleteTwitterChannel,
externalVerifyLink
} = require('../controllers/external.controller');

const verifySignatureMiddleware = require('./../middleware/verifySignature.middleware')
Expand Down Expand Up @@ -57,5 +58,8 @@
router.delete('/RemoveTwitterChannel/:id', verifySignatureMiddleware, externalDeleteTwitterChannel)


router.get('/link/verify/:typeSN/:idUser/:idPost', verifySignatureMiddleware, externalVerifyLink)

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs authorization, but is not rate-limited.



module.exports = router;