1
1
/*
2
2
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3
3
Copyright (C) 2023 Spacebar and Spacebar Contributors
4
-
4
+
5
5
This program is free software: you can redistribute it and/or modify
6
6
it under the terms of the GNU Affero General Public License as published
7
7
by the Free Software Foundation, either version 3 of the License, or
8
8
(at your option) any later version.
9
-
9
+
10
10
This program is distributed in the hope that it will be useful,
11
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
GNU Affero General Public License for more details.
14
-
14
+
15
15
You should have received a copy of the GNU Affero General Public License
16
16
along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
*/
18
18
19
19
import { getIpAdress , route , verifyCaptcha } from "@spacebar/api" ;
20
- import {
21
- Config ,
22
- Email ,
23
- FieldErrors ,
24
- ForgotPasswordSchema ,
25
- User ,
26
- } from "@spacebar/util" ;
20
+ import { Config , Email , ForgotPasswordSchema , User } from "@spacebar/util" ;
27
21
import { Request , Response , Router } from "express" ;
28
- import { HTTPError } from "lambert-server" ;
29
22
const router = Router ( ) ;
30
23
31
24
router . post (
@@ -37,9 +30,6 @@ router.post(
37
30
400 : {
38
31
body : "APIErrorOrCaptchaResponse" ,
39
32
} ,
40
- 500 : {
41
- body : "APIErrorResponse" ,
42
- } ,
43
33
} ,
44
34
} ) ,
45
35
async ( req : Request , res : Response ) => {
@@ -71,50 +61,20 @@ router.post(
71
61
}
72
62
}
73
63
74
- const user = await User . findOneOrFail ( {
75
- where : [ { phone : login } , { email : login } ] ,
76
- select : [ "username" , "id" , "disabled" , "deleted" , "email" ] ,
77
- relations : [ "security_keys" ] ,
78
- } ) . catch ( ( ) => {
79
- throw FieldErrors ( {
80
- login : {
81
- message : req . t ( "auth:password_reset.EMAIL_DOES_NOT_EXIST" ) ,
82
- code : "EMAIL_DOES_NOT_EXIST" ,
83
- } ,
84
- } ) ;
85
- } ) ;
64
+ res . sendStatus ( 204 ) ;
86
65
87
- if ( ! user . email )
88
- throw FieldErrors ( {
89
- login : {
90
- message :
91
- "This account does not have an email address associated with it." ,
92
- code : "NO_EMAIL" ,
93
- } ,
94
- } ) ;
95
-
96
- if ( user . deleted )
97
- return res . status ( 400 ) . json ( {
98
- message : "This account is scheduled for deletion." ,
99
- code : 20011 ,
100
- } ) ;
101
-
102
- if ( user . disabled )
103
- return res . status ( 400 ) . json ( {
104
- message : req . t ( "auth:login.ACCOUNT_DISABLED" ) ,
105
- code : 20013 ,
106
- } ) ;
66
+ const user = await User . findOne ( {
67
+ where : [ { phone : login } , { email : login } ] ,
68
+ select : [ "username" , "id" , "email" ] ,
69
+ } ) . catch ( ( ) => { } ) ;
107
70
108
- return await Email . sendResetPassword ( user , user . email )
109
- . then ( ( ) => {
110
- return res . sendStatus ( 204 ) ;
111
- } )
112
- . catch ( ( e ) => {
71
+ if ( user && user . email ) {
72
+ Email . sendResetPassword ( user , user . email ) . catch ( ( e ) => {
113
73
console . error (
114
- `Failed to send password reset email to ${ user . username } #${ user . discriminator } : ${ e } ` ,
74
+ `Failed to send password reset email to ${ user . username } #${ user . discriminator } ( ${ user . id } ) : ${ e } ` ,
115
75
) ;
116
- throw new HTTPError ( "Failed to send password reset email" , 500 ) ;
117
76
} ) ;
77
+ }
118
78
} ,
119
79
) ;
120
80
0 commit comments