[guadec-web-regcfp] Allow person to select name upon registration
- From: Patrick Uiterwijk <puiterwijk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [guadec-web-regcfp] Allow person to select name upon registration
- Date: Fri, 19 Jun 2015 12:04:17 +0000 (UTC)
commit 307b91c76f2b965d310bb41cddb2fd1415881d4d
Author: Patrick Uiterwijk <puiterwijk redhat com>
Date: Wed Jun 10 21:23:31 2015 +0200
Allow person to select name upon registration
routes/registration.js | 51 ++++++++++++++++++++++++++++----------
views/registration/register.hbs | 4 +-
2 files changed, 39 insertions(+), 16 deletions(-)
---
diff --git a/routes/registration.js b/routes/registration.js
index 2cccc76..2f043e5 100644
--- a/routes/registration.js
+++ b/routes/registration.js
@@ -79,32 +79,58 @@ router.post('/pay/do', function(req, res, next) {
}
});
-router.all('/register', utils.require_user);
router.all('/register', utils.require_permission('registration/register'));
router.get('/register', function(req, res, next) {
- req.user.getRegistration()
- .complete(function(err, reg) {
- res.render('registration/register', { registration: reg,
- ask_regfee: reg == null});
- });
+ if(req.user){
+ req.user.getRegistration()
+ .complete(function(err, reg) {
+ res.render('registration/register', { registration: reg,
+ ask_regfee: reg == null});
+ });
+ } else {
+ res.render('registration/register', { registration: null, ask_regfee: true });
+ };
});
router.post('/register', function(req, res, next) {
+ if(!req.user) {
+ // Create user object and set as req.user
+ if(req.body.name.trim() == '') {
+ res.render('registration/register', { registration: null, submission_error: true, ask_regfee: true} );
+ } else {
+ var user_info = {
+ email: req.session.currentUser,
+ name: req.body.name.trim()
+ };
+ User.create(user_info)
+ .complete(function(err, user) {
+ if(!!err) {
+ console.log("Error saving user object: " + err);
+ res.status(500).send('Error saving user');
+ } else {
+ req.user = user;
+ handle_registration();
+ };
+ });
+ }
+ } else {
+ return handle_registration();
+ }
+}
+
+function handle_registration() {
req.user.getRegistration({include: [RegistrationPayment]})
.complete(function(err, reg) {
- console.log('Body: ' + JSON.stringify(req.body));
var reg_info = {
irc: req.body.irc.trim(),
- is_public: req.body.is_public.indexOf('true') != -1,
country: req.body.country.trim(),
+ is_public: req.body.is_public.indexOf('true') != -1,
badge_printed: false,
receipt_sent: false,
UserId: req.user.Id
};
-
- console.log("Reg info: " + JSON.stringify(reg_info));
-
var regfee = req.body.regfee;
+ reg_info.UserId = req.User.Id;
if((reg == null && regfee == null)) {
res.render('registration/register', { registration: reg_info,
@@ -112,7 +138,6 @@ router.post('/register', function(req, res, next) {
} else {
// Form OK
if(reg == null) {
- console.log("CREATING");
// Create new registration
Registration.create(reg_info)
.complete(function(err, reg) {
@@ -133,10 +158,8 @@ router.post('/register', function(req, res, next) {
});
} else {
// Update
- console.log("UPDATING");
reg.irc = reg_info.irc;
reg.is_public = reg_info.is_public;
- reg.country = reg_info.country;
reg.save().complete(function (err, reg){
if(!!err) {
res.render('registration/register', { registration: reg_info,
diff --git a/views/registration/register.hbs b/views/registration/register.hbs
index 0307456..9c67670 100644
--- a/views/registration/register.hbs
+++ b/views/registration/register.hbs
@@ -4,7 +4,7 @@
<form action="/registration/register" method="post">
<table class="submission-form">
-<tr><td>Your name</td><td><input type="text" name="submitter_name" value="{{user.name}}" disabled
/></td></tr>
+<tr><td>Your name</td><td><input type="text" name="name" value="{{user.name}}" {{#if user
}}disabled{{/if}}/></td></tr>
<tr><td>IRC nickname</td><td><input type="text" name="irc" value="{{registration.irc}}"
placeholder="(optional)"></td></tr>
<input type="hidden" name="is_public" value="false">
@@ -18,7 +18,7 @@ Registered
{{/unless}}</p>
</tr>
-<tr><td>Country</td><td><input type="text" name="country" value="{{registration.country}}"
placeholder="(optional)"><br/><p class="note">We will not publish country data.<br/> It will only be used for
attendee statistics.</p></td></tr>
+-<tr><td>Country</td><td><input type="text" name="country" value="{{registration.country}}"
placeholder="(optional)"><br/><p class="note">We will not publish country data.<br/> It will only be used for
attendee statistics.</p></td></tr>
<tr><td> </td><td><input type="checkbox" value="true" name="is_public"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]