22
33namespace Webkul \UVDesk \SupportCenterBundle \Controller ;
44
5- use Webkul \UVDesk \CoreFrameworkBundle \Entity \User ;
65use Symfony \Component \HttpFoundation \Request ;
76use Symfony \Component \Security \Core \Security ;
8- use Webkul \UVDesk \CoreFrameworkBundle \Form \UserProfile ;
9- use Webkul \UVDesk \CoreFrameworkBundle \Utils \TokenGenerator ;
7+ use Webkul \UVDesk \CoreFrameworkBundle \Entity \User ;
108use Symfony \Component \EventDispatcher \GenericEvent ;
9+ use Webkul \UVDesk \CoreFrameworkBundle \Form \UserProfile ;
1110use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
12- use Webkul \UVDesk \CoreFrameworkBundle \Workflow \Events as CoreWorkflowEvents ;
11+ use Webkul \UVDesk \CoreFrameworkBundle \Utils \TokenGenerator ;
12+ use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
13+ use Webkul \UVDesk \SupportCenterBundle \Entity \KnowledgebaseWebsite ;
14+ use Webkul \UVDesk \CoreFrameworkBundle \Entity \Website as CoreWebsite ;
1315
1416Class Customer extends Controller
1517{
@@ -22,22 +24,25 @@ protected function redirectUserToLogin()
2224
2325 protected function isWebsiteActive ()
2426 {
25- $ error = false ;
27+ $ entityManager = $ this ->getDoctrine ()->getManager ();
28+ $ website = $ entityManager ->getRepository (CoreWebsite::class)->findOneByCode ('knowledgebase ' );
29+
30+ if (!empty ($ website )) {
31+ $ knowledgebaseWebsite = $ entityManager ->getRepository (KnowledgebaseWebsite::class)->findOneBy (['website ' => $ website ->getId (), 'status ' => 1 ]);
32+
33+ if (!empty ($ knowledgebaseWebsite ) && true == $ knowledgebaseWebsite ->getIsActive ()) {
34+ return true ;
35+ }
36+ }
2637
27- if ($ error )
28- $ this ->noResultFound ();
38+ $ this ->noResultFound ();
2939 }
3040
3141 protected function noResultFound ()
3242 {
3343 throw new NotFoundHttpException ('Permission Denied ! ' );
3444 }
3545
36- protected function encodePassword (User $ user , $ plainPassword )
37- {
38- return $ encodedPassword = $ this ->container ->get ('security.password_encoder ' )->encodePassword ($ user , $ plainPassword );
39- }
40-
4146 protected function isLoginDisabled ()
4247 {
4348 $ entityManager = $ this ->getDoctrine ()->getManager ();
@@ -59,8 +64,11 @@ protected function isLoginDisabled()
5964
6065 public function login (Request $ request )
6166 {
62- if ($ this ->redirectUserToLogin ())
67+ $ this ->isWebsiteActive ();
68+
69+ if ($ this ->redirectUserToLogin ()) {
6370 return $ this ->redirect ($ this ->generateUrl ('helpdesk_customer_ticket_collection ' )); // Replace with Dashboard route
71+ }
6472
6573 /** check disabled customer login **/
6674 if ($ this ->isLoginDisabled ()) {
@@ -89,108 +97,6 @@ public function login(Request $request)
8997 ]);
9098 }
9199
92- public function forgotPassword (Request $ request )
93- {
94- if ($ this ->isLoginDisabled ()) {
95- $ this ->addFlash ('warning ' , $ this ->get ('translator ' )->trans ('Warning ! Customer Login disabled by admin. ' ));
96- return $ this ->redirect ($ this ->generateUrl ('webkul_support_center_front_solutions ' ));
97- }
98-
99- if ($ request ->getMethod () == 'POST ' ) {
100- $ entityManager = $ this ->getDoctrine ()->getManager ();
101- $ user = new User ();
102- $ data = $ request ->request ->all ();
103- $ repository = $ this ->getDoctrine ()->getRepository ('UVDeskCoreFrameworkBundle:User ' );
104- $ user = $ entityManager ->getRepository ('UVDeskCoreFrameworkBundle:User ' )->findOneBy (array ('email ' => $ data ['email ' ]));
105-
106- if ($ user ) {
107- $ key = time ();
108-
109- // Trigger agent forgot event
110- $ event = new GenericEvent (CoreWorkflowEvents \Customer \ForgotPassword::getId (), [
111- 'entity ' => $ user ,
112- ]);
113-
114- $ this ->get ('event_dispatcher ' )->dispatch ('uvdesk.automation.workflow.execute ' , $ event );
115-
116- $ request ->getSession ()->getFlashBag ()->set (
117- 'success ' ,
118- $ this ->get ('translator ' )->trans ('Please check your mail for password update. ' )
119- );
120-
121- return $ this ->redirect ($ this ->generateUrl ('helpdesk_customer_login ' ));
122- //@TODO: NEEDS TO SEND EMAIL FOR CHANGE PASSWORD URL.
123- } else {
124- $ request ->getSession ()->getFlashBag ()->set (
125- 'warning ' ,
126- $ this ->get ('translator ' )->trans ('This Email is not registered with us. ' )
127- );
128- }
129- }
130-
131- return $ this ->render ('@UVDeskSupportCenter/Knowledgebase/forgotPassword.html.twig ' , [
132- 'searchDisable ' => true ,
133- 'breadcrumbs ' => [
134- [
135- 'label ' => $ this ->get ('translator ' )->trans ('Support Center ' ),
136- 'url ' => $ this ->generateUrl ('helpdesk_knowledgebase ' )
137- ],
138- ['label ' => $ this ->get ('translator ' )->trans ('Forgot Password ' ), 'url ' => '# ' ]
139- ]
140- ]);
141- }
142-
143-
144- public function updateCredentials ($ email , $ verificationCode )
145- {
146- if ($ this ->isLoginDisabled () || (empty ($ email ) || empty ($ verificationCode ))) {
147- return $ this ->redirect ($ this ->generateUrl ('helpdesk_knowledgebase ' ));
148- }
149-
150- $ entityManager = $ this ->getDoctrine ()->getManager ();
151- $ request = $ this ->get ('request_stack ' )->getCurrentRequest ();
152-
153- // Validate request
154- $ user = $ entityManager ->getRepository ('UVDeskCoreFrameworkBundle:User ' )->findOneByEmail ($ email );
155-
156- if (empty ($ user ) || null == $ user ->getCustomerInstance () || $ user ->getVerificationCode () != $ verificationCode ) {
157- return $ this ->redirect ($ this ->generateUrl ('helpdesk_knowledgebase ' ));
158- }
159-
160- if ($ request ->getMethod () == 'POST ' ) {
161- $ updatedCredentials = $ request ->request ->all ();
162-
163- if ($ updatedCredentials ['password ' ] === $ updatedCredentials ['confirmPassword ' ]) {
164- $ user ->setPassword ($ this ->encodePassword ($ user , $ updatedCredentials ['password ' ]));
165- $ user ->setVerificationCode (TokenGenerator::generateToken ());
166-
167- $ entityManager ->persist ($ user );
168- $ entityManager ->flush ();
169-
170- $ request ->getSession ()->getFlashBag ()->set ('success ' , 'Your password has been updated successfully. ' );
171- return $ this ->redirect ($ this ->generateUrl ('helpdesk_customer_login ' ));
172- } else {
173- $ request ->getSession ()->getFlashBag ()->set (
174- 'warning ' ,
175- $ this ->get ('translator ' )->trans ('Password don \'t match. ' )
176- );
177- }
178- }
179-
180- return $ this ->render ('@UVDeskSupportCenter/Knowledgebase/resetPassword.html.twig ' , [
181- 'searchDisable ' => true ,
182- 'breadcrumbs ' => [
183- [
184- 'label ' => $ this ->get ('translator ' )->trans ('Support Center ' ),
185- 'url ' => 'helpdesk_knowledgebase '
186- ], [
187- 'label ' => $ this ->get ('translator ' )->trans ('Account Validation ' ),
188- 'url ' => '# '
189- ]
190- ]
191- ]);
192- }
193-
194100 public function Account (Request $ request )
195101 {
196102 $ this ->isWebsiteActive ();
0 commit comments