Commit 1d38dd49 authored by Ruben Davila's avatar Ruben Davila

Add ability to generate trial license and upload it immediately

parent 4d7b6a6d
class TrialsController < ApplicationController
SUBSCRIPTIONS_PORTAL_URL = 'https://customers.gitlab.com'
before_filter :check_presence_of_license
def new
end
def create
build_license
if save_license
redirect_to admin_license_url
else
flash.now[:alert] = 'An error occurred while generating the trial license, please try again a few minutes'
render :new
end
end
private
def build_license
@license = License.new
end
def save_license
result = HTTParty.post("#{SUBSCRIPTIONS_PORTAL_URL}/trials", body: params)
if result.ok?
@license.data = result['license_key']
@license.save
else
Rails.logger.error("Error generating trial license: #{result['error']}")
@license.errors.add(:base, result['error'])
end
@license.persisted?
end
def check_presence_of_license
current_license = License.current
if current_license && !current_license.expired?
redirect_to admin_license_url
end
end
end
- page_title 'Trial license'
%h3.page-title Trial License
%main{ :role => "main" }
.actions
= form_tag oauth_authorization_path, method: :post do
= form_tag trials_path, method: :post do
.form-group
= label_tag :first_name
= text_field_tag :first_name, nil, class: "form-control", required: true
= text_field_tag :first_name, params[:first_name], class: "form-control", required: true
.form-group
= label_tag :last_name
= text_field_tag :last_name, nil, class: "form-control", required: true
= text_field_tag :last_name, params[:last_name], class: "form-control", required: true
.form-group
= label_tag :work_email
= text_field_tag :work_email, nil, class: "form-control", required: true
= text_field_tag :work_email, params[:work_email], class: "form-control", required: true
.form-group
= label_tag :company_name
= text_field_tag :company_name, nil, class: "form-control", required: true
= text_field_tag :company_name, params[:company_name], class: "form-control", required: true
.form-group
= label_tag :phone_number
= text_field_tag :phone_number, nil, class: "form-control", required: true
= text_field_tag :phone_number, params[:phone_number], class: "form-control", required: true
.form-group
= label_tag :number_of_developers
= text_field_tag :number_of_developers, nil, class: "form-control", required: true
= text_field_tag :number_of_developers, params[:number_of_developers], class: "form-control", required: true
.form-group
= label_tag :number_of_users
= text_field_tag :number_of_users, nil, class: "form-control", required: true
= text_field_tag :number_of_users, params[:number_of_users], class: "form-control", required: true
.form-group
= label_tag :country
= text_field_tag :country, nil, class: "form-control", required: true
= text_field_tag :country, params[:country], class: "form-control", required: true
.form-group
= submit_tag 'Start your free trial', class: "btn btn-default"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment