5
5
namespace Shopsys \FrontendApiBundle \Model \Mutation \Login ;
6
6
7
7
use Overblog \GraphQLBundle \Definition \Argument ;
8
- use Ramsey \Uuid \Uuid ;
9
8
use Shopsys \FrameworkBundle \Model \Customer \User \FrontendCustomerUserProvider ;
10
9
use Shopsys \FrameworkBundle \Model \Product \List \ProductListFacade ;
11
10
use Shopsys \FrontendApiBundle \Model \Cart \MergeCartFacade ;
15
14
use Shopsys \FrontendApiBundle \Model \Mutation \AbstractMutation ;
16
15
use Shopsys \FrontendApiBundle \Model \Mutation \Customer \User \Exception \InvalidCredentialsUserError ;
17
16
use Shopsys \FrontendApiBundle \Model \Mutation \Customer \User \Exception \TooManyLoginAttemptsUserError ;
17
+ use Shopsys \FrontendApiBundle \Model \Security \LoginAsUserFacade ;
18
18
use Shopsys \FrontendApiBundle \Model \Security \LoginResultData ;
19
19
use Shopsys \FrontendApiBundle \Model \Security \LoginResultDataFactory ;
20
20
use Shopsys \FrontendApiBundle \Model \Security \TokensDataFactory ;
@@ -38,6 +38,7 @@ class LoginMutation extends AbstractMutation
38
38
* @param \Shopsys\FrontendApiBundle\Model\Security\LoginResultDataFactory $loginResultDataFactory
39
39
* @param \Shopsys\FrontendApiBundle\Model\Customer\User\LoginType\CustomerUserLoginTypeFacade $customerUserLoginTypeFacade
40
40
* @param \Shopsys\FrontendApiBundle\Model\Customer\User\LoginType\CustomerUserLoginTypeDataFactory $customerUserLoginTypeDataFactory
41
+ * @param \Shopsys\FrontendApiBundle\Model\Security\LoginAsUserFacade $loginAsUserFacade
41
42
*/
42
43
public function __construct (
43
44
protected readonly FrontendCustomerUserProvider $ frontendCustomerUserProvider ,
@@ -51,6 +52,7 @@ public function __construct(
51
52
protected readonly LoginResultDataFactory $ loginResultDataFactory ,
52
53
protected readonly CustomerUserLoginTypeFacade $ customerUserLoginTypeFacade ,
53
54
protected readonly CustomerUserLoginTypeDataFactory $ customerUserLoginTypeDataFactory ,
55
+ protected readonly LoginAsUserFacade $ loginAsUserFacade ,
54
56
) {
55
57
}
56
58
@@ -71,41 +73,25 @@ public function loginMutation(Argument $argument): LoginResultData
71
73
}
72
74
73
75
try {
74
- $ user = $ this ->frontendCustomerUserProvider ->loadUserByUsername ($ input ['email ' ]);
75
- } catch (UserNotFoundException $ e ) {
76
+ $ customerUser = $ this ->frontendCustomerUserProvider ->loadUserByUsername ($ input ['email ' ]);
77
+ } catch (UserNotFoundException ) {
76
78
throw new InvalidCredentialsUserError ('Log in failed. ' );
77
79
}
78
80
79
- if (!$ this ->userPasswordHasher ->isPasswordValid ($ user , $ input ['password ' ])) {
81
+ if (!$ this ->userPasswordHasher ->isPasswordValid ($ customerUser , $ input ['password ' ])) {
80
82
throw new InvalidCredentialsUserError ('Log in failed. ' );
81
83
}
82
84
83
- if (array_key_exists ('cartUuid ' , $ input ) && $ input ['cartUuid ' ] !== null ) {
84
- if (array_key_exists ('shouldOverwriteCustomerUserCart ' , $ input ) && $ input ['shouldOverwriteCustomerUserCart ' ]) {
85
- $ this ->mergeCartFacade ->overwriteCustomerCartWithCartByUuid ($ input ['cartUuid ' ], $ user );
86
- } else {
87
- $ this ->mergeCartFacade ->mergeCartByUuidToCustomerCart ($ input ['cartUuid ' ], $ user );
88
- }
89
- }
90
-
91
- $ deviceId = Uuid::uuid4 ()->toString ();
92
-
93
85
$ this ->loginRateLimiter ->reset ($ this ->requestStack ->getCurrentRequest ());
94
86
95
- if (array_key_exists ('productListsUuids ' , $ input ) && $ input ['productListsUuids ' ]) {
96
- $ this ->productListFacade ->mergeProductListsToCustomerUser ($ input ['productListsUuids ' ], $ user );
97
- }
98
-
99
- $ this ->customerUserLoginTypeFacade ->updateCustomerUserLoginTypes (
100
- $ this ->customerUserLoginTypeDataFactory ->create ($ user , LoginTypeEnum::WEB ),
101
- );
102
-
103
- return $ this ->loginResultDataFactory ->create (
104
- $ this ->tokensDataFactory ->create (
105
- $ this ->tokenFacade ->createAccessTokenAsString ($ user , $ deviceId ),
106
- $ this ->tokenFacade ->createRefreshTokenAsString ($ user , $ deviceId ),
107
- ),
108
- $ this ->mergeCartFacade ->shouldShowCartMergeInfo (),
87
+ return $ this ->loginAsUserFacade ->runLoginSteps (
88
+ $ customerUser ,
89
+ LoginTypeEnum::WEB ,
90
+ false ,
91
+ $ input ['productListsUuids ' ] ?? [],
92
+ $ input ['shouldOverwriteCustomerUserCart ' ] ?? false ,
93
+ $ input ['cartUuid ' ] ?? null ,
94
+ null ,
109
95
);
110
96
}
111
97
}
0 commit comments