1+ "use strict" ;
2+
3+ // requires newsletter.js
4+ const VERIFY_EMAIL_URL = API_BASE_URL + '/connect/email/verify' ;
5+ const REFRESH_LICENSE_URL = API_BASE_URL + '/licenses/hub/refresh' ;
6+
7+ class HubCE {
8+
9+ constructor ( form , feedbackData , submitData , searchParams ) {
10+ this . _form = form ;
11+ this . _feedbackData = feedbackData ;
12+ this . _submitData = submitData ;
13+ this . _searchParams = searchParams ;
14+ this . _submitData . oldLicense = searchParams . get ( 'oldLicense' ) ;
15+ this . _submitData . returnUrl = searchParams . get ( 'returnUrl' ) ;
16+
17+ // continue after email verified:
18+ if ( searchParams . get ( 'verifiedEmail' ) ) {
19+ feedbackData . currentStep = 1 ;
20+ feedbackData . emailVerified = true ;
21+ }
22+ }
23+
24+ submit ( ) {
25+ if ( this . _feedbackData . currentStep === 0 ) {
26+ this . validateEmail ( ) ;
27+ } else if ( this . _feedbackData . currentStep === 1 ) {
28+ this . sendConfirmationEmail ( ) ;
29+ } else if ( this . _feedbackData . currentStep === 2 ) {
30+ this . getHubLicense ( ) ;
31+ }
32+ }
33+
34+ validateEmail ( ) {
35+ if ( ! $ ( this . _form ) [ 0 ] . checkValidity ( ) ) {
36+ $ ( this . _form ) . find ( ':input' ) . addClass ( 'show-invalid' ) ;
37+ this . _feedbackData . errorMessage = 'Please fill in all required fields.' ;
38+ return ;
39+ }
40+ this . onValidationSucceeded ( ) ;
41+ }
42+
43+ onValidationFailed ( error ) {
44+ this . _feedbackData . inProgress = false ;
45+ this . _feedbackData . errorMessage = error ;
46+ }
47+
48+ onValidationSucceeded ( ) {
49+ this . _feedbackData . currentStep ++ ;
50+ this . _feedbackData . inProgress = false ;
51+ this . _feedbackData . errorMessage = '' ;
52+ }
53+
54+ sendConfirmationEmail ( ) {
55+ if ( ! $ ( this . _form ) [ 0 ] . checkValidity ( ) ) {
56+ $ ( this . _form ) . find ( ':input' ) . addClass ( 'show-invalid' ) ;
57+ this . _feedbackData . errorMessage = 'Please fill in all required fields.' ;
58+ return ;
59+ }
60+
61+ this . _feedbackData . success = false ;
62+ this . _feedbackData . inProgress = true ;
63+ this . _feedbackData . errorMessage = '' ;
64+ $ . ajax ( {
65+ url : VERIFY_EMAIL_URL ,
66+ type : 'POST' ,
67+ data : {
68+ email : this . _submitData . email ,
69+ oldLicense : this . _submitData . oldLicense ,
70+ returnUrl : this . _submitData . returnUrl ,
71+ verifyCaptcha : this . _submitData . captcha ,
72+ verifyEmail : this . _submitData . email ,
73+ verifyTarget : 'registerhubce'
74+ }
75+ } ) . done ( _ => {
76+ this . onRequestSucceeded ( ) ;
77+ if ( this . _submitData . acceptNewsletter ) {
78+ subscribeToNewsletter ( this . _submitData . email , 7 ) ; // FIXME move to backend
79+ }
80+ } ) . fail ( xhr => {
81+ this . onRequestFailed ( xhr . responseJSON ?. message || 'Sending confirmation email failed.' ) ;
82+ } ) ;
83+ }
84+
85+ getHubLicense ( ) {
86+ this . _feedbackData . inProgress = true ;
87+ this . _feedbackData . errorMessage = '' ;
88+ $ . ajax ( {
89+ url : REFRESH_LICENSE_URL ,
90+ type : 'POST' ,
91+ data : {
92+ token : this . _submitData . oldLicense ,
93+ captcha : this . _submitData . captcha
94+ }
95+ } ) . done ( response => {
96+ this . _feedbackData . licenseText = response ;
97+ this . _feedbackData . inProgress = false ;
98+ } ) . fail ( xhr => {
99+ this . onRequestFailed ( xhr . responseJSON ?. message || 'Fetching license failed.' ) ;
100+ } ) ;
101+ }
102+
103+ onRequestFailed ( error ) {
104+ this . _feedbackData . inProgress = false ;
105+ this . _feedbackData . errorMessage = error ;
106+ }
107+
108+ onRequestSucceeded ( ) {
109+ this . _feedbackData . emailSent = true ;
110+ this . _feedbackData . inProgress = false ;
111+ this . _feedbackData . errorMessage = '' ;
112+ }
113+
114+ }
0 commit comments