99
1010namespace OCA \Provisioning_API \Controller ;
1111
12- use InvalidArgumentException ;
1312use OC \Security \Crypto ;
1413use OCP \Accounts \IAccountManager ;
1514use OCP \AppFramework \Controller ;
1817use OCP \AppFramework \Http \Attribute \NoCSRFRequired ;
1918use OCP \AppFramework \Http \Attribute \OpenAPI ;
2019use OCP \AppFramework \Http \TemplateResponse ;
20+ use OCP \HintException ;
2121use OCP \IL10N ;
2222use OCP \IRequest ;
2323use OCP \IUserManager ;
@@ -51,11 +51,21 @@ public function __construct(
5151 #[NoAdminRequired]
5252 #[NoCSRFRequired]
5353 public function showVerifyMail (string $ token , string $ userId , string $ key ): TemplateResponse {
54- if ($ this ->userSession ->getUser ()->getUID () !== $ userId ) {
55- // not a public page, hence getUser() must return an IUser
56- throw new InvalidArgumentException ('Logged in account is not mail address owner ' );
54+ try {
55+ if ($ this ->userSession ->getUser ()?->getUID() !== $ userId ) {
56+ // not a public page, hence getUser() must return an IUser
57+ throw new HintException (
58+ 'Logged in account is not mail address owner ' ,
59+ $ this ->l10n ->t ('Logged in account is not mail address owner ' ),
60+ );
61+ }
62+ $ email = $ this ->crypto ->decrypt ($ key );
63+ } catch (HintException $ e ) {
64+ return new TemplateResponse (
65+ 'core ' , 'error ' , [
66+ 'errors ' => [['error ' => $ e ->getHint ()]]
67+ ], TemplateResponse::RENDER_AS_GUEST );
5768 }
58- $ email = $ this ->crypto ->decrypt ($ key );
5969
6070 return new TemplateResponse (
6171 'core ' , 'confirmation ' , [
@@ -73,8 +83,11 @@ public function showVerifyMail(string $token, string $userId, string $key): Temp
7383 public function verifyMail (string $ token , string $ userId , string $ key ): TemplateResponse {
7484 $ throttle = false ;
7585 try {
76- if ($ this ->userSession ->getUser ()->getUID () !== $ userId ) {
77- throw new InvalidArgumentException ('Logged in account is not mail address owner ' );
86+ if ($ this ->userSession ->getUser ()?->getUID() !== $ userId ) {
87+ throw new HintException (
88+ 'Logged in account is not mail address owner ' ,
89+ $ this ->l10n ->t ('Logged in account is not mail address owner ' ),
90+ );
7891 }
7992 $ email = $ this ->crypto ->decrypt ($ key );
8093 $ ref = \substr (hash ('sha256 ' , $ email ), 0 , 8 );
@@ -87,7 +100,10 @@ public function verifyMail(string $token, string $userId, string $key): Template
87100 ->getPropertyByValue ($ email );
88101
89102 if ($ emailProperty === null ) {
90- throw new InvalidArgumentException ($ this ->l10n ->t ('Email was already removed from account and cannot be confirmed anymore. ' ));
103+ throw new HintException (
104+ 'Email was already removed from account and cannot be confirmed anymore. ' ,
105+ $ this ->l10n ->t ('Email was already removed from account and cannot be confirmed anymore. ' ),
106+ );
91107 }
92108 $ emailProperty ->setLocallyVerified (IAccountManager::VERIFIED );
93109 $ this ->accountManager ->updateAccount ($ userAccount );
@@ -99,8 +115,8 @@ public function verifyMail(string $token, string $userId, string $key): Template
99115 $ throttle = true ;
100116 $ error = $ this ->l10n ->t ('Could not verify mail because the token is invalid. ' );
101117 }
102- } catch (InvalidArgumentException $ e ) {
103- $ error = $ e ->getMessage ();
118+ } catch (HintException $ e ) {
119+ $ error = $ e ->getHint ();
104120 } catch (\Exception $ e ) {
105121 $ error = $ this ->l10n ->t ('An unexpected error occurred. Please contact your admin. ' );
106122 }
0 commit comments