File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -211,6 +211,13 @@ class UsersController {
211211 }
212212
213213 try {
214+ const emailExists =
215+ await this . userService . checkSubscriptionEmailExists ( email ) ;
216+ if ( ! emailExists ) {
217+ console . warn ( 'Linking attempted with non-existent email' ) ;
218+ return res . status ( 400 ) . json ( { message : 'Failed to link email.' } ) ;
219+ }
220+
214221 await this . userService . updateSubscriptionLinkedEmail ( owner , email ) ;
215222 return res . status ( 200 ) . json ( { } ) ;
216223 } catch ( error ) {
Original file line number Diff line number Diff line change @@ -106,6 +106,13 @@ class UsersRepository {
106106 updatePatreonByEmail ( email : string , patreon : boolean ) {
107107 return this . database ( this . table ) . where ( { email } ) . update ( { patreon } ) ;
108108 }
109+
110+ async checkSubscriptionEmailExists ( email : string ) : Promise < boolean > {
111+ const subscription = await this . database ( 'subscriptions' )
112+ . where ( { email : email . toLowerCase ( ) } )
113+ . first ( ) ;
114+ return ! ! subscription ;
115+ }
109116}
110117
111118export default UsersRepository ;
Original file line number Diff line number Diff line change @@ -69,6 +69,12 @@ class UsersService {
6969 return this . repository . getSubscriptionLinkedEmail ( owner ) ;
7070 }
7171
72+ async checkSubscriptionEmailExists ( email : string ) : Promise < boolean > {
73+ const subscription =
74+ await this . repository . checkSubscriptionEmailExists ( email ) ;
75+ return ! ! subscription ;
76+ }
77+
7278 getUserById ( owner : string ) : Promise < Users > {
7379 return this . repository . getById ( owner ) ;
7480 }
You can’t perform that action at this time.
0 commit comments