1- import { Request } from "express"
1+ import { CookieOptions , Request } from "express"
22import { findUser , findUsersByid , getUsersByid , registerUser } from "../services/user.service"
33import { OAuth2Client } from 'google-auth-library'
44import userModel from '../Models/user.model'
@@ -18,7 +18,7 @@ interface User {
1818
1919export const register = async ( request : Request , response : any ) => {
2020 const file = request . file as Express . Multer . File ;
21- const { name, email, password, picture} = request . body
21+ const { name, email, password, picture, type } = request . body
2222 if ( ! name || ! email || ! password ) {
2323 return response . status ( 400 ) . json ( {
2424 message : 'Require all fields' ,
@@ -28,60 +28,72 @@ export const register = async (request: Request, response: any) => {
2828 try {
2929 const existingUsers = await findUser ( { email} )
3030 if ( existingUsers ) {
31- const job = {
32- type : "sendEmail" ,
33- to : email ,
34- subject : `👋 Welcome Back ${ existingUsers . name } ` ,
35- html :`<table cellpadding="0" cellspacing="0" width="100%" style="max-width:600px;margin:auto;font-family:Arial,sans-serif:padding:40px;">
36-
37- <tr>
38- <td style="vertical-align:middle;padding:0 6px 0 0;width:60px;">
39- <img src="https://res.cloudinary.com/deweuhoti/image/upload/v1770377099/Logo_y1ovdx.png"
40- alt="ByteBox Logo"
41- width="60"
42- style="display:block;">
43- </td>
44- <td style="vertical-align:middle;padding:0;">
45- <h1 style="margin:0;font-size:22px;font-weight:700;line-height:1.2;">
46- ByteBox ☁️
47- </h1>
48- </td>
49- </tr>
50- </table>
51- <h2>Welcome back ${ name } 👋</h2>
52- <p>We’re glad to see you again ☁️</p>
53- <p>
54- Your files are safe and right where you left them.<br>
55- Jump back in to upload, organize, and share anytime 🚀
56- </p>
57- <p><strong>✨ What you can do now:</strong></p>
58- <p>
59- • Access your saved files instantly 📂<br>
60- • Upload new photos, videos, or documents ⬆️<br>
61- • Share securely with anyone 🔐<br>
62- • Enjoy fast and smooth cloud storage
63- </p>
64- <p style="margin:24px 0;">
65- <a href="https://bytebox.app"
66- style="display:inline-block;padding:12px 22px;background:#4F46E5;color:#ffffff;text-decoration:none;border-radius:8px;font-weight:600;">
67- Open ByteBox
68- </a>
69- </p>
70- <p>
71- Need help? Just reply to this email — we’re here for you 😊
72- </p>
73- <p>
74- <strong>— Team ByteBox</strong><br>
75- Secure • Fast • Simple ☁️
76- </p>
77- `
78- } ;
79- await redis . lpush ( "jobs" , JSON . stringify ( job ) )
80- return response . status ( 202 ) . json ( {
81- message : "email already exists, Please Sign-in" ,
82- user : existingUsers ,
83- success : false ,
84- } ) }
31+ if ( type === 'google' ) {
32+ const token = request . headers . authorization
33+ let accessToken = token ?. split ( ' ' ) [ 1 ] ;
34+ if ( accessToken === 'undefined' ) {
35+ return response . status ( 409 ) . json ( {
36+ message : "Error Occure" ,
37+ success : false ,
38+ } )
39+ }
40+ const job = {
41+ type : "sendEmail" ,
42+ to : email ,
43+ subject : `👋 Welcome Back ${ existingUsers . name } ` ,
44+ html :`<table cellpadding="0" cellspacing="0" width="100%" style="max-width:600px;margin:auto;font-family:Arial,sans-serif:padding:40px;">
45+
46+ <tr>
47+ <td style="vertical-align:middle;padding:0 6px 0 0;width:60px;">
48+ <img src="https://res.cloudinary.com/deweuhoti/image/upload/v1770377099/Logo_y1ovdx.png"
49+ alt="ByteBox Logo"
50+ width="60"
51+ style="display:block;">
52+ </td>
53+ <td style="vertical-align:middle;padding:0;">
54+ <h1 style="margin:0;font-size:22px;font-weight:700;line-height:1.2;">
55+ ByteBox ☁️
56+ </h1>
57+ </td>
58+ </tr>
59+ </table>
60+ <h2>Welcome back ${ name } 👋</h2>
61+ <p>We’re glad to see you again ☁️</p>
62+ <p>
63+ Your files are safe and right where you left them.<br>
64+ Jump back in to upload, organize, and share anytime 🚀
65+ </p>
66+ <p><strong>✨ What you can do now:</strong></p>
67+ <p>
68+ • Access your saved files instantly 📂<br>
69+ • Upload new photos, videos, or documents ⬆️<br>
70+ • Share securely with anyone 🔐<br>
71+ • Enjoy fast and smooth cloud storage
72+ </p>
73+ <p style="margin:24px 0;">
74+ <a href="https://bytebox.app"
75+ style="display:inline-block;padding:12px 22px;background:#4F46E5;color:#ffffff;text-decoration:none;border-radius:8px;font-weight:600;">
76+ Open ByteBox
77+ </a>
78+ </p>
79+ <p>
80+ Need help? Just reply to this email — we’re here for you 😊
81+ </p>
82+ <p>
83+ <strong>— Team ByteBox</strong><br>
84+ Secure • Fast • Simple ☁️
85+ </p>
86+ `
87+ } ;
88+ await redis . lpush ( "jobs" , JSON . stringify ( job ) )
89+ return response . status ( 202 ) . json ( {
90+ message : "email already exists, Please Sign-in" ,
91+ user : existingUsers ,
92+ token :accessToken ,
93+ success : false ,
94+ } )
95+ }
96+ }
8597
8698 let publicUrlData ;
8799 let user ;
0 commit comments