Add limit for retrying to confirm mail

pull/7995/head
Inga Mai 5 years ago committed by Henriette Dinger
parent 5f3c3fda70
commit a24040faf4
  1. 4
      app/controllers/enterprises_controller.rb
  2. 7
      app/helpers/augur_helper.rb
  3. 15
      app/helpers/enterprise_trial_helper.rb
  4. 11
      app/views/enterprises/_info.html.erb
  5. 4
      frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.html
  6. 79
      frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.ts
  7. 7
      frontend/src/app/components/enterprise/enterprise.component.html

@ -26,9 +26,13 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
class EnterprisesController < ApplicationController
include EnterpriseTrialHelper
layout 'admin'
menu_item :enterprise
before_action :augur_content_security_policy
before_action :chargebee_content_security_policy
before_action :require_admin
before_action :check_user_limit, only: [:show]

@ -1,7 +0,0 @@
module AugurHelper
def augur_content_security_policy
controller.append_content_security_policy_directives(
connect_src: %w(augur.openproject-edge.com)
)
end
end

@ -0,0 +1,15 @@
module EnterpriseTrialHelper
def augur_content_security_policy
append_content_security_policy_directives(
connect_src: %w(augur.openproject-edge.com)
)
end
def chargebee_content_security_policy
append_content_security_policy_directives(
script_src: %w(js.chargebee.com),
style_src: %w(js.chargebee.com openproject-enterprise-test.chargebee.com),
frame_src: %w(js.chargebee.com openproject-enterprise-test.chargebee.com)
)
end
end

@ -26,16 +26,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See docs/COPYRIGHT.rdoc for more details.
++#%>
<span hidden><%= augur_content_security_policy %></span>
<% content_for :header_tags do %>
<script src="https://js.chargebee.com/v2/chargebee.js"
data-cb-site="openproject-enterprise-test">
</script>
<% end %>
<p>
<b><%= t('js.admin.enterprise.upsale.become_hero') %></b><br> <%= t('js.admin.enterprise.upsale.you_contribute') %>
<b><%= t('js.admin.enterprise.upsale.become_hero') %></b><br>
<%= t('js.admin.enterprise.upsale.you_contribute') %>
</p>
<enterprise></enterprise>
<div class="info-boxes upsale-benefits">
<h2>What are the benefits</h2>
<h2><%= t('homescreen.blocks.upsale.description') %></h2>
<div class="info-boxes--container">
<div class="info-boxes--item">
<%= image_tag "https://1t1rycb9er64f1pgy2iuseow-wpengine.netdna-ssl.com/wp-content/uploads/2017/06/icon-security-features.png",

@ -90,8 +90,7 @@
<div class="form--check-box-container">
<input type="checkbox"
class="form--check-box"
formControlName="newsletter_consent"
(change)="receiveNewsletter($event)">
formControlName="newsletter_consent">
</div>
<span>I want to receive the OpenProject
<a href="https://www.openproject.com/newsletter/" target="_blank">
@ -111,6 +110,7 @@
<span *ngIf="!confirmed; else confirmedStatus" class="status--waiting">
email sent - waiting for confirmation
<a id="resend-link" (click)="resendMail()">{{ text.resend }}</a>
<p *ngIf="cancelled">Sorry, something went wrong. Please try to resend mail.</p>
</span>
<ng-template #confirmedStatus>
<span class="status--confirmed">confirmed ✓</span>

@ -117,8 +117,8 @@ export class EnterpriseTrialModal extends OpModalComponent {
this.text = _.defaults(this.options.text, this.text);
}
// checks if form is valid and submits it
public onSubmit() {
// check if form is valid and handle input errors
if (this.enterpriseTrialForm.valid) {
this.enterpriseTrialForm.addControl('_type', new FormControl('enterprise-trial'));
@ -126,15 +126,20 @@ export class EnterpriseTrialModal extends OpModalComponent {
}
}
public sendForm(form:FormGroup) {
// sends POST request with form object
// receives an enterprise trial link to access a token
private sendForm(form:FormGroup) {
const delay = 5000; // wait 5s until next request
const retries = 60; // keep trying for 5 minutes
const trialPath = 'https://augur.openproject-edge.com/public/v1/trials';
// POST /public/v1/trials/ (send POST with form object)
// POST /public/v1/trials/
this.http.post(trialPath, form)
.toPromise()
.then((enterpriseTrial:any) => {
this.trialLink = enterpriseTrial._links.self.href;
this.confirmMailAddress();
this.retryConfirmation(delay, retries);
})
.catch((error:HttpErrorResponse) => {
// mail is invalid or user already created a trial
@ -147,7 +152,8 @@ export class EnterpriseTrialModal extends OpModalComponent {
});
}
public confirmMailAddress() {
// gets a token from the trial link if user confirmed mail
private getToken() {
// 2) GET /public/v1/trials/:id
this.http
.get<any>(this.baseUrlAugur + this.trialLink)
@ -161,20 +167,10 @@ export class EnterpriseTrialModal extends OpModalComponent {
.catch((error:HttpErrorResponse) => {
// returns error 422 while waiting of confirmation
if (error.status === 422 && error.error.identifier === 'waiting_for_email_verification') {
// open next modal window
// status waiting
// open next modal window -> status waiting
this.status = 'mailSubmitted';
// get resend button link
this.resendLink = error.error._links.resend.href;
// TODO add limit for retrying
setTimeout( () => {
// retry as long as modal is open and action is not cancelled
if (!this.cancelled) {
this.confirmMailAddress();
}
}, 5000);
} else if (_.get(error, 'error._type') === 'Error') {
this.notificationsService.addWarning(error.error.message);
} else {
@ -184,45 +180,54 @@ export class EnterpriseTrialModal extends OpModalComponent {
});
}
// TODO
// saves received token in controller
private saveToken(token:string) {
// POST /admin/enterprise (params[:enterprise_token][:encoded_token])
// -> if token is new (token_retrieved: false) save token in ruby controller
this.http.post(this.pathHelper.api.v3.appBasePath + '/admin/enterprise', { enterprise_token: { encoded_token: token } }, { withCredentials: true })
.toPromise()
.then((res:any) => {
// TODO: needs clarification: show token to copy?
console.log('saveToken() success: ', res);
})
.catch((error:HttpErrorResponse) => {
console.log('saveToken() failed: ', error.error);
this.notificationsService.addWarning(error.error.description || I18n.t('js.error.internal'));
});
}
// TODO: needs specification
// retries request while waiting for mail confirmation
private retryConfirmation(delay:number, retries:number) {
if (this.cancelled || this.confirmed) {
// stop if action was cancelled or confirmation link was clicked
return;
} else if (retries === 0) {
// action timed out -> show message
this.cancelled = true;
} else {
// retry as long as limit isn't reached
this.getToken();
setTimeout( () => {
this.retryConfirmation(delay, retries - 1);
}, delay);
}
}
// TODO: add enterprise onboarding youtube video
public startEnterpriseTrial() {
// open onboarding modal
this.status = 'startTrial';
console.log(this.status);
// on continue:
// this.closeModal();
// reload page to show enterprise trial
}
public checkMailField() {
if (this.enterpriseTrialForm.value.email !== '' && this.enterpriseTrialForm.controls.email.errors) {
this.errorMsg = 'Invalid e-mail address';
} else {
this.errorMsg = undefined;
}
}
// resends mail if resend link has been clicked
public resendMail() {
this.http.post(this.baseUrlAugur + this.resendLink, {})
.toPromise()
.then((enterpriseTrial:any) => {
console.log('Mail has been resent.');
this.notificationsService.addSuccess('Mail has been resent. Please check your mails and click the confirmation link provided.');
this.cancelled = false;
this.retryConfirmation(5000, 6);
})
.catch((error:HttpErrorResponse) => {
console.log('An Error occured: ', error);
@ -230,9 +235,13 @@ export class EnterpriseTrialModal extends OpModalComponent {
});
}
public receiveNewsletter(event:any) {
if (event.target.checked) {
// subscribe to newsletter
// checks if mail is valid after input field was edited by the user
// displays message for user
public checkMailField() {
if (this.enterpriseTrialForm.value.email !== '' && this.enterpriseTrialForm.controls.email.errors) {
this.errorMsg = 'Invalid e-mail address';
} else {
this.errorMsg = undefined;
}
}
@ -240,7 +249,7 @@ export class EnterpriseTrialModal extends OpModalComponent {
// cancel all actions (e.g. an already send request)
this.cancelled = true;
this.closeMe(event);
// refresh page to show trial
// refresh page to show enterprise trial
if (this.status === 'startTrial' || this.confirmed) {
window.location.reload();
}

@ -1,6 +1,11 @@
<div class='upsale--actions'>
<button class="button -alt-highlight" (click)="openTrialModal()">{{ text.button_trial }}</button>
<button class="button -highlight">{{ text.button_book }}</button>
<a href="javascript:void(0)"
class="button -highlight"
data-cb-type="checkout"
data-cb-plan-id="enterprise-edition---annual-user-license">
{{ text.button_book }}
</a>
<a href="https://www.openproject.org/upgrade-enterprise-edition/" target="_blank">
{{ text.link_quote }}
</a>

Loading…
Cancel
Save