Skip to content

Commit

Permalink
Added steam keys form
Browse files Browse the repository at this point in the history
  • Loading branch information
thefirstspine committed Jan 22, 2024
1 parent cbe80e8 commit 62b33f7
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 35 deletions.
60 changes: 51 additions & 9 deletions api/controllers/DriftersTalesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@

module.exports = {

async steamCode(req, res) {
// Antispam
const ipAddress = req.headers['x-forwarded-for'] || req.socket.remoteAddress
const alreadyRequestedCodesForIp = await sails.models.steamcode.find({
where: {
product: 'drifters-tales-relaunch-demo',
ipAddress,
},
limit: 10,
});
if (alreadyRequestedCodesForIp.length >= 4) {
req.flash('steamCodeError', 'driftersTales.spamError');
return res.redirect('/drifters-tales#demo');
}

// Get entity
const entity = await sails.models.steamcode.find({
where: {
used: false,
product: 'drifters-tales-relaunch-demo',
},
limit: 1,
});
if (entity.length == 0) {
req.flash('steamCodeError', 'driftersTales.notEnoughCodes');
return res.redirect('/drifters-tales#demo');
}

await sails.models.steamcode.updateOne({ id: entity[0].id }, { used: true, ipAddress });
req.flash('steamCode', entity[0].code);
req.flash('steamCodeMessage', 'driftersTales.demoCode');
return res.redirect('/drifters-tales#demo');
},

async mailingList(req, res) {
const email = req.body.email;

Expand All @@ -15,28 +49,33 @@ module.exports = {
!/^[^@ ]+@[^@ ]+\.[^@ ]+$/.test(email)
)
{
req.flash('mailingListError', "Merci de rentrer une adresse valide.");
return res.redirect('/drifters-tales');
req.flash('mailingListError', 'driftersTales.invalidEmail');
return res.redirect('/drifters-tales#mailinglist');
}

const emails = await sails.models.mailinglist.find({
email,
campaign: 'drifters-tales',
campaign: 'drifters-tales-relaunch',
});
if (emails.length > 0) {
req.flash('mailingListError', "Vous avez déjà été inscrit.");
return res.redirect('/drifters-tales');
req.flash('mailingListError', 'driftersTales.alreadyRegistered');
return res.redirect('/drifters-tales#mailinglist');
}

await sails.models.mailinglist.create({
email,
campaign: 'drifters-tales-relaunch',
});
req.flash('mailingListMessage', "Vous avez été inscrit ! Merci !");
return res.redirect('/drifters-tales');
req.flash('mailingListMessage', 'driftersTales.registered');
return res.redirect('/drifters-tales#mailinglist');
},

async index(req, res) {
const mailingListError = req.flash('mailingListError');
const mailingListMessage = req.flash('mailingListMessage');
const steamCodeError = req.flash('steamCodeError');
const steamCodeMessage = req.flash('steamCodeMessage');
const steamCode = req.flash('steamCode');
return res.view(
'pages/drifters-tales.ejs',
{
Expand All @@ -45,8 +84,11 @@ module.exports = {
{ youtubeId: 'kTd0D3NbRrM' },
{ youtubeId: 'eRmVNS0-t0Q' },
],
mailingListError: req.flash('mailingListError'),
mailingListMessage: req.flash('mailingListMessage'),
mailingListError: mailingListError.length > 0 ? mailingListError : null,
mailingListMessage: mailingListMessage.length > 0 ? mailingListMessage : null,
steamCodeError: steamCodeError.length > 0 ? steamCodeError : null,
steamCodeMessage: steamCodeMessage.length > 0 ? steamCodeMessage : null,
steamCode: steamCode.length > 0 ? steamCode : null,
...await sails.helpers.layoutConfig(req.user_id),
tags: [
{
Expand Down
35 changes: 35 additions & 0 deletions api/models/SteamCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* News.js
*
* @description :: A model definition represents a database table/collection.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/

module.exports = {

attributes: {

// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝

code: { type: 'string', required: true },
product: { type: 'string', required: true },
used: { type: 'boolean', defaultsTo: false },
ipAddress: { type: 'string', defaultsTo: '' },
createdAt: { type: 'number', autoCreatedAt: true },
updatedAt: { type: 'number', autoUpdatedAt: true },

// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝


// ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝

},

};

Binary file added assets/images/drifters-tales-demo-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/drifters-tales-email-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/steam-demo-how-to.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions config/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@
"give": "Give",
"yourName": "Your name",
"tipText": "This early access is free and will remain so throughout the development period. If you want to encourage its development, you can tip the developers so that they can continue their work in peace. The name you will give us will appear in the final release!",
"videos": "Videos"
}
"videos": "Videos",
"tryTheDemo": "Try the demo of our relaunch",
"tryTheDemoText": "You can download the demo of our relaunch on Steam. Click the button below to get your code.",
"askCode": "Request a code",
"howToDemo": "How to use the code?",
"howToDemoText": "On your Steam client, click \"Add a game\" at the bottom left, then select \"Activate a product on Steam...\". Enter your code in the window that should appear.",
"steamSupport": "Click here to access the Steam help article"
},
"driftersTales.alreadyRegistered": "Are you already registered",
"driftersTales.registered": "Thank you! You are successfully registered!",
"driftersTales.invalidEmail": "Please enter a valid email address.",
"driftersTales.spamError": "The number of code requests is limited to 4 per IP address. You can request a code by sending an email to teddy[at]thefirstspine.fr",
"driftersTales.notEnoughCodes": "Unfortunately there aren't enough codes anymore. Try again in a few hours to get new codes!",
"driftersTales.demoCode": "Here is your code to try the demo directly on Steam: %s"
}
15 changes: 13 additions & 2 deletions config/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,18 @@
"tipTitle": "Donner un pourboire",
"give": "Donner",
"yourName": "Votre nom",
"tipText": "Cet accès anticipé est gratuit et le restera pendant toute la période de développement. Si vous voulez encourager son développement, vous pouvez donner un pourboire aux développeurs pour qu'ils puissent continuer leur travail en tout sérénité. Le nom que vous nous donnerez sera présent dans le jeu final !"
"tipText": "Cet accès anticipé est gratuit et le restera pendant toute la période de développement. Si vous voulez encourager son développement, vous pouvez donner un pourboire aux développeurs pour qu'ils puissent continuer leur travail en tout sérénité. Le nom que vous nous donnerez sera présent dans le jeu final !",
"tryTheDemo": "Essayez la démo de notre relaunch",
"tryTheDemoText": "Vous pouvez télécharger la démo de notre relaunch sur Steam. Cliquez sur le bouton ci-dessous pour obtenir votre code.",
"askCode": "Demander un code",
"howToDemo": "Comment utiliser le code ?",
"howToDemoText": "Sur votre client Steam, cliquez sur \"Ajouter un jeu\" en bas à gauche, puis selectionnez \"Activer un produit sur Steam...\". Entrez votre code dans la fenêtre qui devrait apparaître.",
"steamSupport": "Cliquez ici pour accéder à l'article d'aide de Steam"
},
"Vos codes sont arrivés !": "Vos codes sont arrivés !"
"driftersTales.alreadyRegistered": "Vous êtes déjà enregistré",
"driftersTales.registered": "Merci ! Vous êtes bien enregistré !",
"driftersTales.invalidEmail": "Merci de rentrer une adresse valide.",
"driftersTales.spamError": "Le nombre de demande de code est limité à 4 par adresse IP. Vous pouvez demander un code en envoyant un email à teddy[at]thefirstspine.fr",
"driftersTales.notEnoughCodes": "Il n'y a malheureusement plus assez de codes. Retentez dans quelques heures afin d'avoir de nouveau codes !",
"driftersTales.demoCode": "Voici votre code pour essayer la démo directement sur Steam : %s"
}
1 change: 1 addition & 0 deletions config/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ module.exports.policies = {
'event/findOne':[],
'code/*':['load-user', 'is-logged-in', 'is-admin'],
'mailinglist/*':['load-user', 'is-logged-in', 'is-admin'],
'steamcode/*':['load-user', 'is-logged-in', 'is-admin'],

};
1 change: 1 addition & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports.routes = {
// Drifter's Tales
'GET /drifters-tales': 'DriftersTalesController.index',
'POST /drifters-tales/mailing-list': 'DriftersTalesController.mailingList',
'POST /drifters-tales/steam-code': 'DriftersTalesController.steamCode',

// User & auth
'GET /login': 'UserController.viewLoginForm',
Expand Down
96 changes: 74 additions & 22 deletions views/pages/drifters-tales.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,86 @@
</div>
</div>

<a name="demo"></a>
<div class="separator my-6"></div>

<div class="container my-6">
<h1 class="is-size-3 is-uppercase has-text-primary mb-6"><%= __("driftersTales.stayInformed") %></h1>
<form class="columns" action="/drifters-tales/mailing-list" method="POST">
<div class="column is-4 is-offset-4 has-text-centered">
<p class="mb-4">
<%= __("driftersTales.newsletter") %>
</p>
<% if (mailingListError) { %>
<p class="has-text-danger"><%= mailingListError %></p>
<% } %>
<% if (mailingListMessage) { %>
<p class="has-text-success"><%= mailingListMessage %></p>
<% } %>
<div class="field has-addons">
<div class="control is-expanded has-icons-left">
<input class="input is-fullwidth" type="email" placeholder="<%= __("driftersTales.email") %>" name="email">
<span class="icon is-small is-left">
<i class="fas fa-envelope"></i>
</span>
<div style="background-position: top center; background-repeat: no-repeat; min-height: 600px; background-image: url(/images/drifters-tales-demo-background.png); margin-top: -100px;">
<div class="container my-6">
<p class="mt-6">&nbsp;</p>
<p class="mt-6">&nbsp;</p>
<h1 class="is-size-3 is-uppercase has-text-primary mb-6"><%= __("driftersTales.tryTheDemo") %></h1>
<form action="/drifters-tales/steam-code" method="POST">
<div class="columns">
<div class="column is-6 is-offset-3 has-text-centered">
<p class="mb-4 is-size-4">
<%= __("driftersTales.tryTheDemoText") %>
</p>
</div>
<div class="control">
<button type="submit" class="button is-primary m-0"><%= __("driftersTales.send") %></button>
</div>
<div class="columns">
<div class="column is-4 is-offset-4 has-text-centered">
<% if (steamCodeError) { %>
<p class="notification is-danger"><%= __(steamCodeError) %></p>
<% } %>
<% if (steamCodeMessage) { %>
<p class="notification is-success"><%= __(steamCodeMessage, steamCode) %></p>
<% } %>
<input type="hidden" name="code" value="code">
<div class="field">
<div class="control">
<button type="submit" class="button is-primary is-large"><%= __("driftersTales.askCode") %></button>
</div>
</div>
</div>
</div>
</form>
<p class="mt-6">&nbsp;</p>
<div class="columns">
<div class="column is-6 has-text-right">
<img src="/images/steam-demo-how-to.png" />
</div>
<div class="column is-6 has-text-left">
<h2 class="is-size-4 is-uppercase has-text-primary mb-6"><%= __("driftersTales.howToDemo") %></h2>
<p class="my-3"><%= __("driftersTales.howToDemoText") %></p>
<p class="my-3"><a href="https://help.steampowered.com/en/faqs/view/2A12-9D79-C3D7-F870" target="_blank"><%= __("driftersTales.steamSupport") %></a></p>
</div>
</div>
</form>
</div>
</div>

<a name="mailinglist"></a>
<div class="separator my-6"></div>

<div style="background-position: top center; background-repeat: no-repeat; min-height: 400px; background-image: url(/images/drifters-tales-email-background.png); margin-top: -100px;">
<div class="container my-6">
<p class="mt-6">&nbsp;</p>
<p class="mt-6">&nbsp;</p>
<h1 class="is-size-3 is-uppercase has-text-primary mb-6"><%= __("driftersTales.stayInformed") %></h1>
<form class="columns" action="/drifters-tales/mailing-list" method="POST">
<div class="column is-4 is-offset-4 has-text-centered">
<p class="mb-4">
<%= __("driftersTales.newsletter") %>
</p>
<% if (mailingListError) { %>
<p class="notification is-danger"><%= __(mailingListError) %></p>
<% } %>
<% if (mailingListMessage) { %>
<p class="notification is-success"><%= __(mailingListMessage) %></p>
<% } %>
<div class="field has-addons">
<div class="control is-expanded has-icons-left">
<input class="input is-fullwidth" type="email" placeholder="<%= __("driftersTales.email") %>" name="email">
<span class="icon is-small is-left">
<i class="fas fa-envelope"></i>
</span>
</div>
<div class="control">
<button type="submit" class="button is-primary m-0"><%= __("driftersTales.send") %></button>
</div>
</div>
</div>
</form>
</div>
</div>

<div class="separator my-6"></div>
Expand Down

0 comments on commit 62b33f7

Please sign in to comment.