Beautiful Open-Source Form Builder
Appsumo (#232)
Julien Nahume9174238e4b7
diff --git a/app/Http/Controllers/Auth/AppSumoAuthController.php b/app/Http/Controllers/Auth/AppSumoAuthController.phpnew file mode 100644index 000000000..505d2d966--- /dev/null+++ b/app/Http/Controllers/Auth/AppSumoAuthController.php@@ -0,0 +1,117 @@+<?php++namespace App\Http\Controllers\Auth;++use App\Http\Controllers\Controller;+use App\Models\License;+use App\Models\User;+use Illuminate\Auth\AuthenticationException;+use Illuminate\Foundation\Auth\AuthenticatesUsers;+use Illuminate\Http\Request;+use Illuminate\Support\Facades\Auth;+use Illuminate\Support\Facades\Http;++class AppSumoAuthController extends Controller+{+ use AuthenticatesUsers;++ public function handleCallback(Request $request)+ {+ $this->validate($request, [+ 'code' => 'required',+ ]);+ $accessToken = $this->retrieveAccessToken($request->code);+ $license = $this->fetchOrCreateLicense($accessToken);++ // If user connected, attach license+ if (Auth::check()) return $this->attachLicense($license);++ // otherwise start login flow by passing the encrypted license key id+ if (is_null($license->user_id)) {+ return redirect(url('/register?appsumo_license='.encrypt($license->id)));+ }++ return redirect(url('/register?appsumo_error=1'));+ }++ private function retrieveAccessToken(string $requestCode): string+ {+ return Http::withHeaders([+ 'Content-type' => 'application/json'+ ])->post('https://appsumo.com/openid/token/', [+ 'grant_type' => 'authorization_code',+ 'code' => $requestCode,+ 'redirect_uri' => route('appsumo.callback'),+ 'client_id' => config('services.appsumo.client_id'),+ 'client_secret' => config('services.appsumo.client_secret'),+ ])->throw()->json('access_token');+ }++ private function fetchOrCreateLicense(string $accessToken): License+ {+ // Fetch license from API+ $licenseKey = Http::get('https://appsumo.com/openid/license_key/?access_token=' . $accessToken)+ ->throw()+ ->json('license_key');++ // Fetch or create license model+ $license = License::where('license_provider','appsumo')->where('license_key',$licenseKey)->first();+ if (!$license) {+ $licenseData = Http::withHeaders([+ 'X-AppSumo-Licensing-Key' => config('services.appsumo.api_key'),+ ])->get('https://api.licensing.appsumo.com/v2/licenses/'.$licenseKey)->json();++ // Create new license+ $license = License::create([+ 'license_key' => $licenseKey,+ 'license_provider' => 'appsumo',+ 'status' => $licenseData['status'] === 'active' ? License::STATUS_ACTIVE : License::STATUS_INACTIVE,+ 'meta' => $licenseData,+ ]);+ }++ return $license;+ }++ private function attachLicense(License $license) {+ if (!Auth::check()) {+ throw new AuthenticationException('User not authenticated');+ }++ // Attach license if not already attached+ if (is_null($license->user_id)) {+ $license->user_id = Auth::id();+ $license->save();+ return redirect(url('/home?appsumo_connect=1'));+ }++ // Licensed already attached+ return redirect(url('/home?appsumo_error=1'));+ }++ /**+ * @param User $user+ * @param string|null $licenseHash+ * @return string|null+ *+ * Returns null if no license found+ * Returns true if license was found and attached+ * Returns false if there was an error (license not found or already attached)+ */+ public static function registerWithLicense(User $user, ?string $licenseHash): ?bool+ {+ if (!$licenseHash) {+ return null;+ }+ $licenseId = decrypt($licenseHash);+ $license = License::find($licenseId);++ if ($license && is_null($license->user_id)) {+ $license->user_id = $user->id;+ $license->save();+ return true;+ }++ return false;+ }+}diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.phpindex 736eff8a4..df7e99a31 100644--- a/app/Http/Controllers/Auth/RegisterController.php+++ b/app/Http/Controllers/Auth/RegisterController.php@@ -3,6 +3,7 @@namespace App\Http\Controllers\Auth;use App\Http\Controllers\Controller;+use App\Http\Resources\UserResource;use App\Models\Workspace;use App\Models\User;use Illuminate\Contracts\Auth\MustVerifyEmail;@@ -15,6 +16,8 @@ class RegisterController extends Controller{use RegistersUsers;+ private ?bool $appsumoLicense = null;+/*** Create a new controller instance.*@@ -28,8 +31,8 @@ class RegisterController extends Controller/*** The user has been registered.*- * @param \Illuminate\Http\Request $request- * @param \App\User $user+ * @param \Illuminate\Http\Request $request+ * @param \App\User $user* @return \Illuminate\Http\JsonResponse*/protected function registered(Request $request, User $user)@@ -38,13 +41,17 @@ class RegisterController extends Controllerreturn response()->json(['status' => trans('verification.sent')]);}- return response()->json($user);+ return response()->json(array_merge(+ (new UserResource($user))->toArray($request),+ [+ 'appsumo_license' => $this->appsumoLicense,+ ]));}/*** Get a validator for an incoming registration request.*- * @param array $data+ * @param array $data* @return \Illuminate\Contracts\Validation\Validator*/protected function validator(array $data)@@ -54,8 +61,9 @@ class RegisterController extends Controller'email' => 'required|email:filter|max:255|unique:users|indisposable','password' => 'required|min:6|confirmed','hear_about_us' => 'required|string',- 'agree_terms' => ['required',Rule::in([true])]- ],[+ 'agree_terms' => ['required', Rule::in([true])],+ 'appsumo_license' => ['nullable'],+ ], ['agree_terms' => 'Please agree with the terms and conditions.']);}@@ -63,7 +71,7 @@ class RegisterController extends Controller/*** Create a new user instance after a valid registration.*- * @param array $data+ * @param array $data* @return \App\User*/protected function create(array $data)@@ -87,6 +95,8 @@ class RegisterController extends Controller]], false);+ $this->appsumoLicense = AppSumoAuthController::registerWithLicense($user, $data['appsumo_license'] ?? null);+return $user;}}diff --git a/app/Http/Controllers/Webhook/AppSumoController.php b/app/Http/Controllers/Webhook/AppSumoController.phpnew file mode 100644index 000000000..6bbf900dc--- /dev/null+++ b/app/Http/Controllers/Webhook/AppSumoController.php@@ -0,0 +1,91 @@+<?php++namespace App\Http\Controllers\Webhook;++use App\Http\Controllers\Controller;+use App\Models\License;+use Illuminate\Http\Request;+use Illuminate\Validation\UnauthorizedException;++class AppSumoController extends Controller+{+ public function handle(Request $request)+ {+ $this->validateSignature($request);++ if ($request->test) {+ return $this->success([+ 'message' => 'Webhook received.',+ 'event' => $request->event,+ 'success' => true,+ ]);+ }++ // Call the right function depending on the event using match()+ match ($request->event) {+ 'activate' => $this->handleActivateEvent($request),+ 'upgrade', 'downgrade' => $this->handleChangeEvent($request),+ 'deactivate' => $this->handleDeactivateEvent($request),+ default => null,+ };++ return $this->success([+ 'message' => 'Webhook received.',+ 'event' => $request->event,+ 'success' => true,+ ]);+ }++ private function handleActivateEvent($request)+ {+ $licence = License::firstOrNew([+ 'license_key' => $request->license_key,+ 'license_provider' => 'appsumo',+ 'status' => License::STATUS_ACTIVE,+ ]);+ $licence->meta = $request->json()->all();+ $licence->save();+ }++ private function handleChangeEvent($request)+ {+ // Deactivate old license+ $oldLicense = License::where([+ 'license_key' => $request->prev_license_key,+ 'license_provider' => 'appsumo',+ ])->firstOrFail();+ $oldLicense->update([+ 'status' => License::STATUS_INACTIVE,+ ]);++ // Create new license+ License::create([+ 'license_key' => $request->license_key,+ 'license_provider' => 'appsumo',+ 'status' => License::STATUS_ACTIVE,+ 'meta' => $request->json()->all(),+ ]);+ }++ private function handleDeactivateEvent($request)+ {+ // Deactivate old license+ $oldLicense = License::where([+ 'license_key' => $request->prev_license_key,+ 'license_provider' => 'appsumo',+ ])->firstOrFail();+ $oldLicense->update([+ 'status' => License::STATUS_INACTIVE,+ ]);+ }++ private function validateSignature(Request $request)+ {+ $signature = $request->header('x-appsumo-signature');+ $payload = $request->getContent();++ if ($signature === hash_hmac('sha256', $payload, config('services.appsumo.api_key'))) {+ throw new UnauthorizedException('Invalid signature.');+ }+ }+}diff --git a/app/Http/Requests/AnswerFormRequest.php b/app/Http/Requests/AnswerFormRequest.phpindex be8085072..2a3039f77 100644--- a/app/Http/Requests/AnswerFormRequest.php+++ b/app/Http/Requests/AnswerFormRequest.php@@ -16,9 +16,6 @@ use App\Rules\ValidUrl;class AnswerFormRequest extends FormRequest{- const MAX_FILE_SIZE_FREE = 5000000; // 5 MB- const MAX_FILE_SIZE_PRO = 50000000; // 50 MB-public Form $form;protected array $requestRules = [];@@ -27,12 +24,7 @@ class AnswerFormRequest extends FormRequestpublic function __construct(Request $request){$this->form = $request->form;-- $this->maxFileSize = self::MAX_FILE_SIZE_FREE;- $workspace = $this->form->workspace;- if ($workspace && $workspace->is_pro) {- $this->maxFileSize = self::MAX_FILE_SIZE_PRO;- }+ $this->maxFileSize = $this->form->workspace->max_file_size;}/**diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.phpindex cfabaa00f..5e8de1df3 100644--- a/app/Http/Resources/UserResource.php+++ b/app/Http/Resources/UserResource.php@@ -21,6 +21,7 @@ class UserResource extends JsonResource'template_editor' => $this->template_editor,'has_customer_id' => $this->has_customer_id,'has_forms' => $this->has_forms,+ 'active_license' => $this->licenses()->active()->first(),] : [];return array_merge(parent::toArray($request), $personalData);diff --git a/app/Models/License.php b/app/Models/License.phpnew file mode 100644index 000000000..bb72f34e6--- /dev/null+++ b/app/Models/License.php@@ -0,0 +1,45 @@+<?php++namespace App\Models;++use Illuminate\Database\Eloquent\Factories\HasFactory;+use Illuminate\Database\Eloquent\Model;++class License extends Model+{+ const STATUS_ACTIVE = 'active';+ const STATUS_INACTIVE = 'inactive';++ use HasFactory;++ protected $fillable = [+ 'license_key',+ 'user_id',+ 'license_provider',+ 'status',+ 'meta'+ ];++ protected $casts = [+ 'meta' => 'array',+ ];++ public function user()+ {+ return $this->belongsTo(User::class);+ }++ public function scopeActive($query)+ {+ return $query->where('status', self::STATUS_ACTIVE);+ }++ public function getMaxFileSizeAttribute()+ {+ return [+ 1 => 25000000, // 25 MB,+ 2 => 50000000, // 50 MB,+ 3 => 75000000, // 75 MB,+ ][$this->meta['tier']];+ }+}diff --git a/app/Models/User.php b/app/Models/User.phpindex 538136b78..3ce5c21d8 100644--- a/app/Models/User.php+++ b/app/Models/User.php@@ -13,6 +13,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;use Illuminate\Notifications\Notifiable;use Laravel\Cashier\Billable;use Tymon\JWTAuth\Contracts\JWTSubject;+class User extends Authenticatable implements JWTSubject{use Notifiable, HasFactory, Billable;@@ -80,7 +81,9 @@ class User extends Authenticatable implements JWTSubjectpublic function getIsSubscribedAttribute(){- return $this->subscribed() || in_array($this->email, config('opnform.extra_pro_users_emails'));+ return $this->subscribed()+ || in_array($this->email, config('opnform.extra_pro_users_emails'))+ || !is_null($this->activeLicense());}public function getHasCustomerIdAttribute()@@ -138,7 +141,7 @@ class User extends Authenticatable implements JWTSubjectpublic function forms(){- return $this->hasMany(Form::class,'creator_id');+ return $this->hasMany(Form::class, 'creator_id');}public function formTemplates()@@ -146,6 +149,16 @@ class User extends Authenticatable implements JWTSubjectreturn $this->hasMany(Template::class, 'creator_id');}+ public function licenses()+ {+ return $this->hasMany(License::class);+ }++ public function activeLicense(): License+ {+ return $this->licenses()->active()->first();+ }+/*** =================================* Oauth Related@@ -187,26 +200,26 @@ class User extends Authenticatable implements JWTSubject})->first()?->onTrial();}- public static function boot ()+ public static function boot(){parent::boot();- static::deleting(function(User $user) {+ static::deleting(function (User $user) {// Remove user's workspace if he's the only one with this workspaceforeach ($user->workspaces as $workspace) {if ($workspace->users()->count() == 1) {$workspace->delete();}}- });+ });}public function scopeWithActiveSubscription($query){- return $query->whereHas('subscriptions', function($query) {- $query->where(function($q){- $q->where('stripe_status', 'trialing')- ->orWhere('stripe_status', 'active');- });+ return $query->whereHas('subscriptions', function ($query) {+ $query->where(function ($q) {+ $q->where('stripe_status', 'trialing')+ ->orWhere('stripe_status', 'active');+ });});}diff --git a/app/Models/Workspace.php b/app/Models/Workspace.phpindex 5974a5937..c0efa231d 100644--- a/app/Models/Workspace.php+++ b/app/Models/Workspace.php@@ -2,8 +2,8 @@namespace App\Models;+use App\Http\Requests\AnswerFormRequest;use App\Models\Forms\Form;-use App\Models\User;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model;@@ -11,6 +11,9 @@ class Workspace extends Model{use HasFactory;+ const MAX_FILE_SIZE_FREE = 5000000; // 5 MB+ const MAX_FILE_SIZE_PRO = 50000000; // 50 MB+protected $fillable = ['name','icon',@@ -37,6 +40,26 @@ class Workspace extends Modelreturn false;}+ public function getMaxFileSizeAttribute()+ {+ if(is_null(config('cashier.key'))){+ return self::MAX_FILE_SIZE_PRO;+ }++ // Return max file size depending on subscription+ foreach ($this->owners as $owner) {+ if ($owner->is_subscribed) {+ if ($license = $owner->activeLicense()) {+ // In case of special License+ return $license->max_file_size;+ }+ }+ return self::MAX_FILE_SIZE_PRO;+ }++ return self::MAX_FILE_SIZE_FREE;+ }+public function getIsEnterpriseAttribute(){if(is_null(config('cashier.key'))){diff --git a/config/services.php b/config/services.phpindex fe0ad4026..7e2b9d165 100644--- a/config/services.php+++ b/config/services.php@@ -45,7 +45,7 @@ return [],'notion' => [- 'worker' => env('NOTION_WORKER','https://notion-forms-worker.notionforms.workers.dev/v1')+ 'worker' => env('NOTION_WORKER', 'https://notion-forms-worker.notionforms.workers.dev/v1')],'openai' => [@@ -53,8 +53,14 @@ return [],'unsplash' => [- 'access_key' => env('UNSPLASH_ACCESS_KEY'),- 'secret_key' => env('UNSPLASH_SECRET_KEY'),+ 'access_key' => env('UNSPLASH_ACCESS_KEY'),+ 'secret_key' => env('UNSPLASH_SECRET_KEY'),+ ],++ 'appsumo' => [+ 'client_id' => env('APPSUMO_CLIENT_ID'),+ 'client_secret' => env('APPSUMO_CLIENT_SECRET'),+ 'api_key' => env('APPSUMO_API_KEY'),],'google_analytics_code' => env('GOOGLE_ANALYTICS_CODE'),diff --git a/database/migrations/2023_10_30_133259_create_licenses_table.php b/database/migrations/2023_10_30_133259_create_licenses_table.phpnew file mode 100644index 000000000..034cde5db--- /dev/null+++ b/database/migrations/2023_10_30_133259_create_licenses_table.php@@ -0,0 +1,39 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {+ Schema::create('licenses', function (Blueprint $table) {+ $table->id();+ $table->string('license_key');+ $table->unsignedBigInteger('user_id')->nullable();+ $table->string('license_provider');+ $table->string('status');+ $table->json('meta');+ $table->timestamps();++ $table->index(['license_key', 'license_provider']);+ $table->index(['user_id', 'license_provider']);+ });+ }++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ Schema::dropIfExists('licenses');+ }+};diff --git a/public/img/appsumo/as-Select-dark.png b/public/img/appsumo/as-Select-dark.pngnew file mode 100644index 000000000..44dc132c8Binary files /dev/null and b/public/img/appsumo/as-Select-dark.png differdiff --git a/public/img/appsumo/as-taco-white-bg.png b/public/img/appsumo/as-taco-white-bg.pngnew file mode 100644index 000000000..16442a479Binary files /dev/null and b/public/img/appsumo/as-taco-white-bg.png differdiff --git a/resources/js/components/common/Button.vue b/resources/js/components/common/Button.vueindex 85e21d87c..0e8304878 100644--- a/resources/js/components/common/Button.vue+++ b/resources/js/components/common/Button.vue@@ -7,24 +7,24 @@><template v-if="!loading"><span class="no-underline mx-auto">- <slot/>- </span>+ <slot />+ </span><svg v-if="arrow" class="ml-2 w-3 h-3 inline" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 11L11 1M11 1H1M11 1V11" stroke="currentColor" stroke-width="2" stroke-linecap="round"- stroke-linejoin="round"/>+ stroke-linejoin="round"+ /></svg>-</template>- <loader v-else class="h-6 w-6 mx-auto" :class="`text-${colorShades['text']}`"/>+ <loader v-else class="h-6 w-6 mx-auto" :class="`text-${colorShades['text']}`" /></button>- <router-link v-else :class="btnClasses" :to="to" :target="target"- >- <span class="no-underline mx-auto">- <slot/>- </span>+ <router-link v-else :class="btnClasses" :to="to" :target="target">+ <span class="no-underline mx-auto">+ <slot />+ </span><svg v-if="arrow" class="ml-2 w-3 h-3 inline" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 11L11 1M11 1H1M11 1V11" stroke="currentColor" stroke-width="2" stroke-linecap="round"- stroke-linejoin="round"/>+ stroke-linejoin="round"+ /></svg></router-link></template>@@ -72,11 +72,11 @@ export default {target: {type: String,default: '_self'- },+ }},computed: {- btnClasses() {+ btnClasses () {const sizes = this.sizesconst colorShades = this.colorShadesreturn `v-btn ${sizes['p-y']} ${sizes['p-x']}@@ -84,14 +84,14 @@ export default {${colorShades?.text} transition ease-in duration-200 text-center text-${sizes?.font} font-medium focus:outline-none focus:ring-2focus:ring-offset-2 rounded-lg flex items-center hover:no-underline`},- colorShades() {+ colorShades () {if (this.color === 'blue') {return {main: 'bg-blue-600',hover: 'hover:bg-blue-700',ring: 'focus:ring-blue-500','ring-offset': 'focus:ring-offset-blue-200',- text: 'text-white',+ text: 'text-white'}} else if (this.color === 'outline-blue') {return {@@ -99,7 +99,15 @@ export default {hover: 'hover:bg-blue-600',ring: 'focus:ring-blue-500','ring-offset': 'focus:ring-offset-blue-200',- text: 'text-blue-600 hover:text-white',+ text: 'text-blue-600 hover:text-white'+ }+ } else if (this.color === 'outline-gray') {+ return {+ main: 'bg-transparent border border-gray-300',+ hover: 'hover:bg-gray-500',+ ring: 'focus:ring-gray-500',+ 'ring-offset': 'focus:ring-offset-gray-200',+ text: 'text-gray-500 hover:text-white'}} else if (this.color === 'red') {return {@@ -107,7 +115,7 @@ export default {hover: 'hover:bg-red-700',ring: 'focus:ring-red-500','ring-offset': 'focus:ring-offset-red-200',- text: 'text-white',+ text: 'text-white'}} else if (this.color === 'gray') {return {@@ -115,7 +123,7 @@ export default {hover: 'hover:bg-gray-700',ring: 'focus:ring-gray-500','ring-offset': 'focus:ring-offset-gray-200',- text: 'text-white',+ text: 'text-white'}} else if (this.color === 'light-gray') {return {@@ -123,7 +131,7 @@ export default {hover: 'hover:bg-gray-100',ring: 'focus:ring-gray-500','ring-offset': 'focus:ring-offset-gray-300',- text: 'text-gray-700',+ text: 'text-gray-700'}} else if (this.color === 'green') {return {@@ -131,7 +139,7 @@ export default {hover: 'hover:bg-green-700',ring: 'focus:ring-green-500','ring-offset': 'focus:ring-offset-green-200',- text: 'text-white',+ text: 'text-white'}} else if (this.color === 'yellow') {return {@@ -139,7 +147,7 @@ export default {hover: 'hover:bg-yellow-700',ring: 'focus:ring-yellow-500','ring-offset': 'focus:ring-offset-yellow-200',- text: 'text-white',+ text: 'text-white'}} else if (this.color === 'white') {return {@@ -147,12 +155,12 @@ export default {hover: 'hover:bg-gray-200',ring: 'focus:ring-white-500','ring-offset': 'focus:ring-offset-white-200',- text: 'text-gray-700',+ text: 'text-gray-700'}}console.error('Unknown color')},- sizes() {+ sizes () {if (this.size === 'small') {return {font: 'sm',@@ -169,8 +177,8 @@ export default {},methods: {- onClick(event) {- this.$emit('click',event)+ onClick (event) {+ this.$emit('click', event)}}}diff --git a/resources/js/components/vendor/appsumo/AppSumoBilling.vue b/resources/js/components/vendor/appsumo/AppSumoBilling.vuenew file mode 100644index 000000000..5dcffbd71--- /dev/null+++ b/resources/js/components/vendor/appsumo/AppSumoBilling.vue@@ -0,0 +1,77 @@+<template>+ <div v-if="user.active_license" class="border p-5 shadow-md rounded-md">+ <div class="w-auto flex flex-col items-center">+ <img :src="asset('img/appsumo/as-taco-white-bg.png')" class="max-w-[60px]" alt="AppSumo">+ <img :src="asset('img/appsumo/as-Select-dark.png')" class="max-w-[150px]" alt="AppSumo">+ </div>+ <p class="mt-6">+ Your AppSumo <span class="font-semibold">lifetime deal tier {{ licenseTier }}</span> license is active. Here's a reminder of your plan details:+ </p>+ <ul class="list-disc pl-5 mt-4">+ <li>Number of Forms: <span class="font-semibold">{{ tierFeatures.form_quantity }}</span></li>+ <li>Custom domains: <span class="font-semibold">{{ tierFeatures.domain_names }}</span></li>+ <li>File Size Uploads: <span class="font-semibold">{{ tierFeatures.file_upload_size }}</span></li>+ </ul>+ <div class="w-max">+ <v-button color="outline-gray" shade="lighter" class="mt-4 block" href="https://appsumo.com/account/products/" target="_blank">+ Mangage in AppSumo+ </v-button>+ </div>+ </div>+</template>++<script>+import { mapGetters } from 'vuex'+import VButton from '../../common/Button.vue'++export default {++ name: 'AppSumoBilling',+ components: { VButton },++ data () {+ return {+ }+ },++ computed: {+ ...mapGetters({+ user: 'auth/user'+ }),+ licenseTier () {+ return this.user?.active_license?.meta?.tier+ },+ tierFeatures () {+ if (!this.licenseTier) return {}+ return {+ 1: {+ form_quantity: 'Unlimited',+ file_upload_size: '25mb',+ domain_names: '5'+ },+ 2: {+ form_quantity: 'Unlimited',+ file_upload_size: '50mb',+ domain_names: '25'+ },+ 3: {+ form_quantity: 'Unlimited',+ file_upload_size: '75mb',+ domain_names: 'Unlimited'+ }+ }[this.licenseTier]+ }+ },++ watch: {},++ mounted () {},++ created () {+ },+ destroyed () {+ },++ methods: {}+}+</script>diff --git a/resources/js/components/vendor/appsumo/AppSumoRegister.vue b/resources/js/components/vendor/appsumo/AppSumoRegister.vuenew file mode 100644index 000000000..71573cc3a--- /dev/null+++ b/resources/js/components/vendor/appsumo/AppSumoRegister.vue@@ -0,0 +1,50 @@+<template>+ <div v-if="hasValidLicense" class="p-6 bg-white border shadow-md rounded-md">+ <img :src="asset('img/appsumo/as-taco-white-bg.png')" class="max-w-[60px] mx-auto" alt="AppSumo">+ <img :src="asset('img/appsumo/as-Select-dark.png')" class="max-w-[300px] mx-auto" alt="AppSumo">+ <p class="mt-6">+ <span class="text-green-500">We found your AppSumo Lifetime deal license!</span> Just complete the registration form to finalize the activation of+ your license.+ </p>+ </div>+ <div v-else-if="hasLicenseError" class="p-6 bg-white border border-red-500 shadow-md rounded-md">+ <img :src="asset('img/appsumo/as-taco-white-bg.png')" class="max-w-[60px] mx-auto" alt="AppSumo">+ <img :src="asset('img/appsumo/as-Select-dark.png')" class="max-w-[300px] mx-auto" alt="AppSumo">+ <p class="mt-6">+ <span class="text-red-600">Invalid AppSumo license</span>. The license was probably already attached to an OpnForm account. Please contact support.+ </p>+ </div>+</template>++<script>+export default {++ name: 'AppSumoRegister',++ data () {+ return {+ hasValidLicense: false,+ hasLicenseError: false+ }+ },++ computed: {},++ watch: {},++ mounted () {+ if (this.$route.query.appsumo_license !== undefined && this.$route.query.appsumo_license) {+ this.hasValidLicense = true+ } else if (this.$route.query.appsumo_error !== undefined && this.$route.query.appsumo_error) {+ this.hasLicenseError = true+ }+ },++ created () {+ },+ destroyed () {+ },++ methods: {}+}+</script>diff --git a/resources/js/pages/auth/components/RegisterForm.vue b/resources/js/pages/auth/components/RegisterForm.vueindex a06f82d69..7eadc7dc6 100644--- a/resources/js/pages/auth/components/RegisterForm.vue+++ b/resources/js/pages/auth/components/RegisterForm.vue@@ -1,6 +1,6 @@<template><div>- <form @submit.prevent="register" @keydown="form.onKeydown($event)" class="mt-4">+ <form class="mt-4" @submit.prevent="register" @keydown="form.onKeydown($event)"><!-- Name --><text-input name="name" :form="form" :label="$t('name')" placeholder="Your name" :required="true" />@@ -18,42 +18,42 @@<!-- Password Confirmation--><text-input native-type="password" :form="form" :required="true" placeholder="Enter confirm password"- name="password_confirmation" :label="$t('confirm_password')"+ name="password_confirmation" :label="$t('confirm_password')"/><checkbox-input :form="form" name="agree_terms" :required="true"><template #label>- I agree with the <router-link :to="{name:'terms-conditions'}" target="_blank">Terms and conditions</router-link> and <router-link :to="{name:'privacy-policy'}" target="_blank">Privacy policy</router-link> of the website and I accept them.+ I agree with the <router-link :to="{name:'terms-conditions'}" target="_blank">+ Terms and conditions+ </router-link> and <router-link :to="{name:'privacy-policy'}" target="_blank">+ Privacy policy+ </router-link> of the website and I accept them.</template></checkbox-input><!-- Submit Button -->- <v-button :loading="form.busy">Create an account</v-button>+ <v-button :loading="form.busy">+ Create an account+ </v-button><p class="text-gray-500 mt-4">- Already have an account?- <a href="#" v-if="isQuick" @click.prevent="$emit('openLogin')" class="font-semibold ml-1">Log In</a>- <router-link v-else :to="{name:'login'}" class="font-semibold ml-1">Log In</router-link>+ Already have an account?+ <a v-if="isQuick" href="#" class="font-semibold ml-1" @click.prevent="$emit('openLogin')">Log In</a>+ <router-link v-else :to="{name:'login'}" class="font-semibold ml-1">+ Log In+ </router-link></p>-- <!-- GitHub Register Button -->- <login-with-github /></form></div></template><script>import Form from 'vform'-import LoginWithGithub from '~/components/LoginWithGithub.vue'-import SelectInput from '../../../components/forms/SelectInput.vue'import { initCrisp } from '../../../middleware/check-auth.js'export default {name: 'RegisterForm',- components: {- SelectInput,- LoginWithGithub,- },+ components: {},props: {isQuick: {type: Boolean,@@ -68,7 +68,8 @@ export default {email: '',password: '',password_confirmation: '',- agree_terms: false+ agree_terms: false,+ appsumo_license: null}),mustVerifyEmail: false}),@@ -91,6 +92,13 @@ export default {}},+ mounted () {+ // Set appsumo license+ if (this.$route.query.appsumo_license !== undefined && this.$route.query.appsumo_license) {+ this.form.appsumo_license = this.$route.query.appsumo_license+ }+ },+methods: {async register () {// Register the user.@@ -111,14 +119,23 @@ export default {// Track eventthis.$logEvent('register', { source: this.form.hear_about_us })-+initCrisp(data)this.$crisp.push(['set', 'session:event', [[['register', {}, 'blue']]]])+ // AppSumo License+ if (data.appsumo_license === false) {+ this.alertError('Invalid AppSumo license. This probably happened because this license was already' ++ ' attached to another OpnForm account. Please contact support.')+ } else if (data.appsumo_license === true) {+ this.alertSuccess('Your AppSumo license was successfully activated! You now have access to all the' ++ ' features of the AppSumo deal.')+ }+// Redirect- if(this.isQuick){+ if (this.isQuick) {this.$emit('afterQuickLogin')- }else{+ } else {this.$router.push({ name: 'forms.create' })}}diff --git a/resources/js/pages/auth/register.vue b/resources/js/pages/auth/register.vueindex ae680fa21..e0ac9dca5 100644--- a/resources/js/pages/auth/register.vue+++ b/resources/js/pages/auth/register.vue@@ -3,16 +3,17 @@<div class="flex mt-6 mb-10"><div class="w-full md:max-w-6xl mx-auto px-4 flex items-center md:flex-row-reverse flex-wrap"><div class="w-full lg:w-1/2 md:p-6">+ <app-sumo-register class="mb-10 p-6 lg:hidden" /><div class="border rounded-md p-6 shadow-md sticky top-4"><h2 class="font-semibold text-2xl">Create an account</h2><small>Sign up in less than 2 minutes.</small>-<register-form /></div></div><div class="w-full hidden lg:block lg:w-1/2 md:p-6 mt-8 md:mt-0 ">+ <app-sumo-register class="mb-10" /><h1 class="font-bold">Create beautiful forms and share them anywhere</h1>@@ -22,7 +23,7 @@<div class="flex flex-wrap justify-center"><p class="px-3 pb-3 text-sm text-gray-500"><svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 inline" fill="none" viewBox="0 0 24 24"- stroke="currentColor" stroke-width="2"+ stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" /></svg>@@ -30,7 +31,7 @@</p><p class="px-3 pb-3 text-sm text-gray-500"><svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 inline" fill="none" viewBox="0 0 24 24"- stroke="currentColor" stroke-width="2"+ stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" /></svg>@@ -38,16 +39,16 @@</p><p class="px-3 pb-3 text-sm text-gray-500"><svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 inline" fill="none" viewBox="0 0 24 24"- stroke="currentColor" stroke-width="2"+ stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" /></svg>Unlimited submissions</p></div>-<!-- <div class="mt-3 p-6">-->-<!-- <testimonials />-->-<!-- </div>-->+ <!-- <div class="mt-3 p-6">-->+ <!-- <testimonials />-->+ <!-- </div>--></div></div></div>@@ -57,29 +58,27 @@<script>import OpenFormFooter from '../../components/pages/OpenFormFooter.vue'-import Testimonials from '../../components/pages/welcome/Testimonials.vue'import RegisterForm from './components/RegisterForm.vue'import SeoMeta from '../../mixins/seo-meta.js'+import AppSumoRegister from '../../components/vendor/appsumo/AppSumoRegister.vue'export default {components: {- Testimonials,+ AppSumoRegister,OpenFormFooter,RegisterForm},- middleware: 'guest',-mixins: [SeoMeta],+ middleware: 'guest',+data: () => ({- metaTitle: 'Register',+ metaTitle: 'Register'}),- computed: {- },+ computed: {},- methods: {- }+ methods: {}}</script>diff --git a/resources/js/pages/settings/billing.vue b/resources/js/pages/settings/billing.vueindex 17164ebb0..47a497f2c 100644--- a/resources/js/pages/settings/billing.vue+++ b/resources/js/pages/settings/billing.vue@@ -1,14 +1,21 @@<template><div>- <h3 class="font-semibold text-2xl text-gray-900">Billing details</h3>- <small class="text-gray-600">Manage your billing. Download invoices, update your plan, or cancel it at any- time.</small>-- <div class="mt-4">- <v-button color="gray" shade="light" :loading="billingLoading" @click.prevent="openBillingDashboard">- Manage Subscription- </v-button>- </div>+ <h3 class="font-semibold text-2xl text-gray-900">+ Billing details+ </h3>++ <template v-if="user.has_customer_id">+ <small class="text-gray-600">Manage your billing. Download invoices, update your plan, or cancel it at any+ time.</small>++ <div class="mt-4">+ <v-button color="gray" shade="light" :loading="billingLoading" @click.prevent="openBillingDashboard">+ Manage Subscription+ </v-button>+ </div>+ </template>++ <app-sumo-billing class="mt-4" /></div></template>@@ -16,11 +23,13 @@import axios from 'axios'import VButton from '../../components/common/Button.vue'import SeoMeta from '../../mixins/seo-meta.js'+import { mapGetters } from 'vuex'+import AppSumoBilling from '../../components/vendor/appsumo/AppSumoBilling.vue'export default {- components: {VButton},- scrollToTop: false,+ components: { AppSumoBilling, VButton },mixins: [SeoMeta],+ scrollToTop: false,data: () => ({metaTitle: 'Billing',@@ -28,7 +37,7 @@ export default {}),methods: {- openBillingDashboard() {+ openBillingDashboard () {this.billingLoading = trueaxios.get('/api/subscription/billing-portal').then((response) => {const url = response.data.portal_url@@ -39,6 +48,12 @@ export default {this.billingLoading = false})}+ },++ computed: {+ ...mapGetters({+ user: 'auth/user'+ })}}</script>diff --git a/routes/api.php b/routes/api.phpindex 9ec4b922b..cfb0abad8 100644--- a/routes/api.php+++ b/routes/api.php@@ -129,6 +129,12 @@ Route::group(['middleware' => 'guest:api'], function () {Route::get('oauth/{driver}/callback', [OAuthController::class, 'handleCallback'])->name('oauth.callback');});++Route::group(['prefix' => 'appsumo'], function () {+ Route::get('oauth/callback', [\App\Http\Controllers\Auth\AppSumoAuthController::class, 'handleCallback'])->name('appsumo.callback');+ Route::post('webhook', [\App\Http\Controllers\Webhook\AppSumoController::class, 'handle'])->name('appsumo.webhook');+});+/** Public Forms related routes*/