Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve registration

  • Loading branch information...
commit 579f229333fdcaf61865465904da22da785110e9 1 parent f65d3dc
@anddimario authored
View
2  README.md
@@ -32,7 +32,7 @@ You can add in a route some function before the normal response to manage the ac
You can change menu and pagetitle language added it to the value separeted by a comma in the "Menu" and "Path" page.
For site text and basic controller language you can work in the page "Language" in the admin area to add the language. Then go in "Content" and write you content. Go in "Themes" and in the mustache tag {{content_...}} for your page add the tag that you set in "Content" as {{tag}} (IMP: if you want add html in the content, use {{{tag}}}).
-You can add your content wherever you want in the Theme.
+You can add your content wherever you want in the Theme with mustache tag.
The language selection work on the session variable req.session.lang and the language id.
Type of content in collections: Message (application message in controller route) and Content (all content in theme that can be manage by mustache).
View
55 controller/user.js
@@ -48,7 +48,7 @@ function route() {
var message = {
action: '',
reference: 'connected',
- value: req.session.info.name
+ value: req.session.info.email
};
var data = {
form: false
@@ -64,7 +64,7 @@ function route() {
} );
router.post('/login', utils.auth_yet, function (req, res) {
var validator = new Validator();
- validator.check(req.body.name, 'name').notEmpty();
+ validator.check(req.body.email, 'email').isEmail();
validator.check(req.body.password, 'password').notEmpty();
var errors = validator.getErrors();
if (errors.length)
@@ -74,7 +74,7 @@ function route() {
reference: 'required',
value: errors
};
- var data = { name: req.body.name}
+ var data = { email: req.body.email}
utils.rendering(req.headers.host, 'login', data, req.session.info, req.session.lang, message, function callback(layout) {
res.end(layout);
});
@@ -83,21 +83,21 @@ function route() {
var shasum = crypto.createHash('sha1');
shasum.update(req.body.password);
var value = {
- name: req.body.name,
+ email: req.body.email,
password: shasum.digest('hex')
};
user_login.find(value, function callbacks(results) {
// CHECK ON DATABASE AND ENSURE THAT USER IS IN, THEN LOGIN
if (results.length != 0) {
req.session.info = {
- name: results[0].name,
+ email: results[0].email,
role: results[0].role
}
// if i don't use this temp variable the objects are overwrited by rendering function
var message = {
action: '',
reference: 'connected',
- value: results[0].name
+ value: results[0].email
};
var data = { form: {form_user: false}}
utils.rendering(req.headers.host, 'login', data, req.session.info, req.session.lang, message, function callback(layout) {
@@ -146,8 +146,9 @@ function route() {
} );
router.post('/registration', utils.auth_yet, function (req, res) {
var validator = new Validator();
- validator.check(req.body.name, 'name').notEmpty();
validator.check(req.body.email, 'email').isEmail();
+ validator.check(req.body.firstname, 'name').notEmpty();
+ validator.check(req.body.surname, 'name').notEmpty();
validator.check(req.body.password, 'password').notEmpty();
var errors = validator.getErrors();
@@ -198,7 +199,7 @@ function route() {
} else {
// ONLY ONE USERNAME
var user_check = new ModelsUser(req.headers.host);
- var value = { name: req.body.name };
+ var value = { email: req.body.email };
user_check.find(value, function callbacks(results) {
// CHECK IF THERE ARE OTHER USER
if (results.length == 0) {
@@ -207,8 +208,9 @@ function route() {
shasum.update(req.body.password);
var value = {
- name: req.body.name,
email: req.body.email,
+ firstname: req.body.firstname,
+ surname: req.body.surname,
password: shasum.digest('hex')
};
if (req.body.role) {
@@ -237,8 +239,9 @@ function route() {
value: errors
};
var data = {
- name: req.body.name,
- email: req.body.email
+ email: req.body.email,
+ firstname: req.body.firstname,
+ surname: req.body.surname,
};
utils.rendering(req.headers.host, 'registration', data, req.session.info, req.session.lang, message, function callback(layout) {
res.end(layout);
@@ -252,10 +255,10 @@ function route() {
} );
- router.get('/user/:operation?/:name?', utils.restricted, function (req, res) {
- if (req.params.name){
- if ((req.session.info.role === "admin") || (req.params.name == req.session.info.name)) {
- var value = {name: req.params.name};
+ router.get('/user/:operation?/:email?', utils.restricted, function (req, res) {
+ if (req.params.email){
+ if ((req.session.info.role === "admin") || (req.params.email == req.session.info.email)) {
+ var value = { email: req.params.email};
} else {
utils.rendering(req.headers.host, '404', {}, req.session.info, req.session.lang, {}, function callback(layout) {
res.end(layout);
@@ -267,7 +270,7 @@ function route() {
var value = {};
} else {
// redirect to right user
- var location = '/user/view/'+req.session.info.name;
+ var location = '/user/view/'+req.session.info.email;
res.writeHead(302, {
'Location': location
});
@@ -282,8 +285,9 @@ function route() {
data = {
form: {form_user: true, registration: true},
type: 'user',
- name: results[0].name,
email: results[0].email,
+ firstname: results[0].firstname,
+ surname: results[0].surname,
password: results[0].password
};
if (req.session.info.role == "admin") {
@@ -292,7 +296,7 @@ function route() {
}
} else if ((req.params.operation === "delete") && (req.session.info.role == "admin")) {
var value = {
- name: req.params.name
+ email: req.params.email
};
var user_remove = new ModelsUser(req.headers.host);
user_remove.remove(value, function callbacks(results) {
@@ -323,10 +327,11 @@ function route() {
} );
router.post('/user', utils.restricted, function (req, res) {
// could be only edit, not change username else 404
- if ((req.session.info.role === "admin") || (req.body.name == req.session.info.name)) {
+ if ((req.session.info.role === "admin") || (req.body.email == req.session.info.email)) {
var validator = new Validator();
- validator.check(req.body.name, 'name').notEmpty();
validator.check(req.body.email, 'email').isEmail();
+ validator.check(req.body.firstname, 'firstname').notEmpty();
+ validator.check(req.body.surname, 'surname').notEmpty();
validator.check(req.body.role, 'role').notEmpty();
validator.check(req.body.password, 'password').notEmpty();
var errors = validator.getErrors();
@@ -340,9 +345,10 @@ function route() {
var data = {
form: {form_user: true, registration: true, restricted: true},
type: 'user',
- name: req.body.name,
+ email: req.body.email,
+ firstname: req.body.firstname,
+ surname: req.body.surname,
role: req.body.role,
- email: req.body.email
};
utils.rendering(req.headers.host, 'user', data, req.session.info, req.session.lang, message, function callback(layout) {
res.end(layout);
@@ -353,11 +359,12 @@ function route() {
shasum.update(req.body.password);
var find = {
- name: req.body.name
+ email: req.body.email
}
var value = {
role: req.body.role,
- email: req.body.email,
+ firstname: req.body.firstname,
+ surname: req.body.surname,
password: shasum.digest('hex')
};
user_edit.update(find, value, function callbacks(results) {
View
5 lib/newsite.js
@@ -67,7 +67,8 @@ var defaultcontent = [
{ "type": "message", "tag": "notchange", "lang_id": "0", "text": "You can't change your username" },
{ "type": "message", "tag": "waitrefresh", "lang_id": "0", "text": "Please wait cache refresh for changes" },
{ "type": "message", "tag": "done", "lang_id": "0", "text": "Done!" },
-{ "type": "content", "tag": "langformname", "lang_id": "0", "text": "Name" },
+{ "type": "content", "tag": "langformfirstname", "lang_id": "0", "text": "First Name" },
+{ "type": "content", "tag": "langformsurname", "lang_id": "0", "text": "Surname" },
{ "type": "content", "tag": "langformemail", "lang_id": "0", "text": "Email" },
{ "type": "content", "tag": "langformrole", "lang_id": "0", "text": "User Role" },
{ "type": "content", "tag": "langformpassword", "lang_id": "0", "text": "Password" },
@@ -129,7 +130,7 @@ var server3 = new mongodb.Server(configuration.Params.mongodb_ip, configuration.
new mongodb.Db(database, server3, {}).open(function (error, client) {
if (error) throw error;
var collection = new mongodb.Collection(client, 'user');
- collection.insert({name: 'admin', password: 'd033e22ae348aeb5660fc2140aec35850c4da997', role: 'admin'}, {safe:true},
+ collection.insert({email: 'admin@admin.com', password: 'd033e22ae348aeb5660fc2140aec35850c4da997', role: 'admin'}, {safe:true},
function(err, objects) {
if (err) console.log(err.message);
else console.log("Done Admin Installation");
View
2  package.json
@@ -1,7 +1,7 @@
{
"name":"mucontent",
"description":"A multisite, multilanguage, modulare and scalable CMS",
- "version":"1.0.3",
+ "version":"1.0.5",
"author": {
"name": "Andrea Di Mario",
"email": "anddimario@gmail.com"
View
10 views/default.mustache
@@ -162,9 +162,10 @@
{{#form}}
{{#form_user}}
<form method='post' action='/{{type}}' class='well form-horizontal'>
- <input type='text' name='name' placeholder='{{langformname}}' value='{{name}}'/>
- {{#registration}}
<input type='text' name='email'' placeholder='{{langformemail}}' value='{{email}}'/>
+ {{#registration}}
+ <input type='text' name='firstname' placeholder='{{langformfirstname}}' value='{{firstname}}'/>
+ <input type='text' name='surname' placeholder='{{langformsurname}}' value='{{surname}}'/>
{{/registration}}
{{#restricted}}
<input type='text' name='role' placeholder='{{langformrole}}' value='{{role}}'/>
@@ -216,7 +217,7 @@
{{#form_information}}
<form method='post' action='/information' class='well form-horizontal'>
<input type='text' name='captcha_public_key' placeholder='{{langformrecaptchapublic}}' value='{{captcha_public_key}}'/>
- <input type='text' name='captcha_private_key' placeholder='{{langformprivatekey}}' value='{{captcha_private_key}}'/>
+ <input type='text' name='captcha_private_key' placeholder='{{langformrecaptchaprivatekey}}' value='{{captcha_private_key}}'/>
<button type="submit" class="btn btn-primary">Invia</button>
</form>
{{/form_information}}
@@ -258,8 +259,9 @@
{{/restricted}}
{{/data_user_new}}
{{#data_user}}
- {{name}} -
{{email}} -
+ {{firstname}} -
+ {{surname}} -
{{password}}
{{#user_edit}}
<a href='/user/edit/{{name}}'>edit</a>
Please sign in to comment.
Something went wrong with that request. Please try again.