@@ -11,7 +11,7 @@ use serde_json;
11
11
use app:: RequestApp ;
12
12
use db:: RequestTransaction ;
13
13
use controllers:: helpers:: Paginate ;
14
- use util:: { bad_request, human, CargoResult , RequestUtils } ;
14
+ use util:: { bad_request, human, CargoError , CargoResult , RequestUtils } ;
15
15
use github;
16
16
use email;
17
17
@@ -89,7 +89,6 @@ impl<'a> NewUser<'a> {
89
89
use diesel:: dsl:: sql;
90
90
use diesel:: sql_types:: Integer ;
91
91
use diesel:: pg:: upsert:: excluded;
92
- use diesel:: NotFound ;
93
92
use schema:: users:: dsl:: * ;
94
93
95
94
conn. transaction ( || {
@@ -128,8 +127,7 @@ impl<'a> NewUser<'a> {
128
127
. optional ( ) ?;
129
128
130
129
if let Some ( token) = token {
131
- send_user_confirm_email ( user_email, & user. gh_login , & token)
132
- . map_err ( |_| NotFound ) ?;
130
+ send_user_confirm_email ( user_email, & user. gh_login , & token) ;
133
131
}
134
132
}
135
133
@@ -541,7 +539,7 @@ pub fn update_user(req: &mut Request) -> CargoResult<Response> {
541
539
return Err ( human ( "empty email rejected" ) ) ;
542
540
}
543
541
544
- conn. transaction ( || {
542
+ conn. transaction :: < _ , Box < CargoError > , _ > ( || {
545
543
update ( users. filter ( gh_login. eq ( & user. gh_login ) ) )
546
544
. set ( email. eq ( user_email) )
547
545
. execute ( & * conn) ?;
@@ -560,8 +558,9 @@ pub fn update_user(req: &mut Request) -> CargoResult<Response> {
560
558
. get_result :: < String > ( & * conn)
561
559
. map_err ( |_| human ( "Error in creating token" ) ) ?;
562
560
563
- send_user_confirm_email ( user_email, & user. gh_login , & token)
564
- . map_err ( |_| bad_request ( "Email could not be sent" ) )
561
+ send_user_confirm_email ( user_email, & user. gh_login , & token) ;
562
+
563
+ Ok ( ( ) )
565
564
} ) ?;
566
565
567
566
#[ derive( Serialize ) ]
@@ -571,7 +570,17 @@ pub fn update_user(req: &mut Request) -> CargoResult<Response> {
571
570
Ok ( req. json ( & R { ok : true } ) )
572
571
}
573
572
574
- fn send_user_confirm_email ( email : & str , user_name : & str , token : & str ) -> CargoResult < ( ) > {
573
+ /// Attempts to send a confirmation email. Swallows all errors.
574
+ ///
575
+ /// This function swallows any errors that occur while attempting to send the
576
+ /// email. Some users do not have any valid email set in their GitHub profile.
577
+ /// We cannot force them to give us an email address, and that should not stop
578
+ /// them from signing in.
579
+ fn send_user_confirm_email ( email : & str , user_name : & str , token : & str ) {
580
+ let _ = try_send_user_confirm_email ( email, user_name, token) ;
581
+ }
582
+
583
+ fn try_send_user_confirm_email ( email : & str , user_name : & str , token : & str ) -> CargoResult < ( ) > {
575
584
// Create a URL with token string as path to send to user
576
585
// If user clicks on path, look email/user up in database,
577
586
// make sure tokens match
@@ -629,7 +638,7 @@ pub fn regenerate_token_and_send(req: &mut Request) -> CargoResult<Response> {
629
638
. get_result :: < Email > ( & * conn)
630
639
. map_err ( |_| bad_request ( "Email could not be found" ) ) ?;
631
640
632
- send_user_confirm_email ( & email. email , & user. gh_login , & email. token )
641
+ try_send_user_confirm_email ( & email. email , & user. gh_login , & email. token )
633
642
. map_err ( |_| bad_request ( "Error in sending email" ) )
634
643
} ) ?;
635
644
0 commit comments