-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from P4-Games/feature/change-email
merge feature/change-email into develop
- Loading branch information
Showing
21 changed files
with
651 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { BOT_API_TOKEN } from 'src/config-global' | ||
|
||
import { post, endpoints } from '../../_hooks/api-resolver' | ||
|
||
// ---------------------------------------------------------------------- | ||
|
||
export async function send2FACode(phone: string, code: number, codeMsg: string) { | ||
const botSendMsgEndpoint = endpoints.backend.sendMessage() | ||
const botSendMsgData = { | ||
data_token: BOT_API_TOKEN, | ||
channel_user_id: phone, | ||
message: codeMsg.replace('{2FA_CODE}', code.toString()) | ||
} | ||
console.info('botSendMsgData', botSendMsgData) | ||
const botSendMsgResult = await post(botSendMsgEndpoint, botSendMsgData) | ||
console.info('botSendMsgResult', botSendMsgResult) | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { NextRequest, NextResponse } from 'next/server' | ||
|
||
import { getUserByPhone, updateUserCode } from 'src/app/api/_data/data-service' | ||
import { BOT_API_URL, BOT_API_TOKEN, botApiWappEnabled } from 'src/config-global' | ||
|
||
import { IAccount } from 'src/types/account' | ||
|
||
import { send2FACode } from '../../../_common/common' | ||
|
||
// ---------------------------------------------------------------------- | ||
|
||
export async function POST(req: NextRequest) { | ||
try { | ||
const { phone, codeMsg }: { phone: string; codeMsg: string; recaptchaToken: string } = | ||
await req.json() | ||
|
||
if (!phone || !codeMsg) { | ||
return new NextResponse( | ||
JSON.stringify({ | ||
code: 'INVALID_REQUEST_PARAMS', | ||
error: 'Missing phone number or codeMsg in request body' | ||
}), | ||
{ | ||
status: 400, | ||
headers: { 'Content-Type': 'application/json' } | ||
} | ||
) | ||
} | ||
|
||
if (!BOT_API_URL || !BOT_API_TOKEN) { | ||
return new NextResponse(JSON.stringify({ error: `Backend API or Token not set.` }), { | ||
status: 404, | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
} | ||
|
||
const user: IAccount | undefined = await getUserByPhone(phone) | ||
if (!user) { | ||
return new NextResponse( | ||
JSON.stringify({ code: 'USER_NOT_FOUND', error: 'user not found with that phone number' }), | ||
{ | ||
status: 404, | ||
headers: { 'Content-Type': 'application/json' } | ||
} | ||
) | ||
} | ||
|
||
// Generate and store 2FA code | ||
const code: number = Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000 | ||
await updateUserCode(user.id, code) | ||
|
||
// Send 2FA code to user'whatsapp | ||
let botSentCodeResult: boolean = true | ||
if (botApiWappEnabled) { | ||
console.info('calling send2FACode SYNC', phone, code) | ||
botSentCodeResult = await send2FACode(phone, code, codeMsg) | ||
|
||
if (!botSentCodeResult) { | ||
return new NextResponse( | ||
JSON.stringify({ | ||
code: 'USER_NOT_FOUND', | ||
error: 'user not found with that phone number' | ||
}), | ||
{ | ||
status: 404, | ||
headers: { 'Content-Type': 'application/json' } | ||
} | ||
) | ||
} | ||
} | ||
|
||
const finalResult: { phone: string; sent: boolean } = { | ||
phone, | ||
sent: botSentCodeResult | ||
} | ||
|
||
return NextResponse.json(finalResult) | ||
} catch (ex) { | ||
console.error(ex) | ||
return new NextResponse(JSON.stringify({ error: 'Error in authentication' }), { | ||
status: 400, | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { NextRequest, NextResponse } from 'next/server' | ||
|
||
import { getUserById, updateUserCode, updateUserEmail } from 'src/app/api/_data/data-service' | ||
|
||
import { IAccount } from 'src/types/account' | ||
|
||
// ---------------------------------------------------------------------- | ||
|
||
type IParams = { | ||
id: string | ||
} | ||
|
||
type IBody = { | ||
phone: string | ||
code: string | ||
recaptchaToken: string | ||
email: string | ||
} | ||
export async function POST(req: NextRequest, { params }: { params: IParams }) { | ||
try { | ||
const { id } = params | ||
const { phone, code, email }: IBody = await req.json() | ||
|
||
if (!id) { | ||
return new NextResponse( | ||
JSON.stringify({ | ||
code: 'INVALID_REQUEST_PARAMS', | ||
error: 'Missing parameters in path params' | ||
}), | ||
{ | ||
status: 400, | ||
headers: { 'Content-Type': 'application/json' } | ||
} | ||
) | ||
} | ||
|
||
if (!email || !code || !phone) { | ||
return new NextResponse( | ||
JSON.stringify({ | ||
code: 'INVALID_REQUEST_PARAMS', | ||
error: 'Missing email, code and phone in request body' | ||
}), | ||
{ | ||
status: 400, | ||
headers: { 'Content-Type': 'application/json' } | ||
} | ||
) | ||
} | ||
|
||
const user: IAccount | undefined = await getUserById(id) | ||
if (!user) { | ||
return new NextResponse( | ||
JSON.stringify({ code: 'USER_NOT_FOUND', error: 'user not found with that id' }), | ||
{ | ||
status: 404, | ||
headers: { 'Content-Type': 'application/json' } | ||
} | ||
) | ||
} | ||
|
||
if (!user.code || code.toString() !== user.code.toString()) { | ||
return new NextResponse(JSON.stringify({ code: 'INVALID_CODE', error: 'invalid code' }), { | ||
status: 400, | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
} | ||
|
||
user.email = email | ||
const reult: boolean = await updateUserEmail(user) | ||
|
||
if (!reult) { | ||
return new NextResponse( | ||
JSON.stringify({ | ||
code: 'USER_UPDATE_ERROR', | ||
error: 'user update error' | ||
}), | ||
{ | ||
status: 400, | ||
headers: { 'Content-Type': 'application/json' } | ||
} | ||
) | ||
} | ||
|
||
updateUserCode(user.id, undefined) | ||
|
||
return NextResponse.json({ reult }) | ||
} catch (ex) { | ||
console.error(ex) | ||
return new NextResponse(JSON.stringify({ error: 'Error in update user' }), { | ||
status: 400, | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { EmailEditView } from 'src/sections/account/view' | ||
|
||
// ---------------------------------------------------------------------- | ||
|
||
export const metadata = { | ||
title: 'Account - Email' | ||
} | ||
|
||
export default function AccountEmailPage() { | ||
return <EmailEditView /> | ||
} |
25 changes: 0 additions & 25 deletions
25
src/app/dashboard/user/wallet/[walletId]/nfts/[nftId]/page_
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.