Skip to content

Commit

Permalink
Added button to create account using an account creation token
Browse files Browse the repository at this point in the history
  • Loading branch information
rackover authored and Brutus5000 committed Nov 10, 2019
1 parent dd6c844 commit 0f229da
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
6 changes: 5 additions & 1 deletion express.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ app.get('/privacy', markdown("templates/views/privacy.md"))
app.get('/tos', markdown("templates/views/tos.md"))
app.get('/rules', markdown("templates/views/rules.md"))

//Account routes
/// Account routes
// Registration
app.get('/account/register', require(routes + 'accounts/get/register'));
app.post('/account/register', require(routes + 'accounts/post/register'));

// Callback for registration to create the account using a token
app.get('/account/create', require(routes + 'accounts/get/createAccount'));

app.get('/account/link', loggedIn, require(routes + 'accounts/get/linkSteam'));

app.get('/account/connect', loggedIn, require(routes + 'accounts/get/connectSteam'));
Expand Down
27 changes: 27 additions & 0 deletions routes/views/accounts/get/createAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
exports = module.exports = function(req, res) {

var locals = res.locals;

// locals.section is used to set the currently selected
// item in the header navigation.
locals.section = 'account';

if (req.body.token){
locals.tokenURL = process.env.API_URL+"/users/activate?token="+ req.body.token
}
else{
let flash = {};
flash.type = 'Error!';
flash.class = 'alert-danger';
flash.messages = [{msg: 'Invalid or missing account token'}];

let buff = Buffer.from(JSON.stringify(flash));
let data = buff.toString('base64');

return res.redirect('/?flash='+data);
}

// Render the view
res.render('account/create');

};
19 changes: 18 additions & 1 deletion routes/views/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,25 @@ exports = module.exports = function(req, res) {
else {
locals.topPlayers = {}
}

let flash = {};

if (req.query.flash){
let buff = Buffer.from(req.query.flash, 'base64');
let text = buff.toString('ascii');

try{
flash = JSON.parse(text);
}
catch(e){
console.err("Parsing error while trying to decode a flash error: "+text);
console.err(e);
flasg = [{msg: "Unknown error"}];
}
}

// Render the view
res.render('index');
res.render('index', {flash: flash});
});

};
20 changes: 20 additions & 0 deletions templates/views/account/create.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends ../../layouts/default
include ../../mixins/flash-messages
include ../../mixins/form/account

block content
.container.text-center
.row
.col-md-12
h1.account-title Create account
h4.account-subtitle.text-center Click the button below to confirm the account creation
hr
.row
.col-md-offset-3.col-md-6
+flash-messages(flash)

.row
.col-md-offset-3.col-md-6
a(href=tokenURL)
button.btn.btn-default.btn-lg.btn-outro.btn-danger Create account

3 changes: 3 additions & 0 deletions templates/views/index.pug
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
extends ../layouts/default
include ../mixins/flash-messages

block content
.intro
div(style="position:absolute;left:0;right:0;text-align:center;")
+flash-messages(flash)
div.hero
.introtitle
img(src="/images/vector_faf_logo.png")
Expand Down

0 comments on commit 0f229da

Please sign in to comment.