parent
3f171394b2
commit
b600c585bc
|
@ -5,7 +5,7 @@ const mail = require('mail');
|
|||
const pug = require('pug');
|
||||
const config = require('settings/config');
|
||||
|
||||
SIGNUP_ERRORS = {
|
||||
let SIGNUP_ERRORS = {
|
||||
USERNAME_ALREADY_EXISTS: "The username you want is already used.",
|
||||
EMAIL_ALREADY_EXISTS: "The email you want is already used.",
|
||||
UNKOWN_ERROR: "Something weird happened, i'm sorry :'(",
|
||||
|
@ -143,7 +143,7 @@ module.exports.activate = function(req, res, render, next) {
|
|||
user.save((err, user) => {
|
||||
req.session.user = user;
|
||||
req.session.save();
|
||||
res.redirect(getUrl('settings'));
|
||||
res.redirect(getUrl('calendarSettings'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,19 +1,87 @@
|
|||
extends ../../../templates/base.pug
|
||||
|
||||
block extracss
|
||||
style.
|
||||
.tab-content {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
|
||||
block content
|
||||
form(method="POST", action=getUrl("settingsTarget"))
|
||||
|
||||
nav.nav.nav-tabs(role='tablist')
|
||||
if !calendar
|
||||
a#account-settings-tab.tab.nav-item.nav-link.active(data-toggle='tab', href='#account-settings', role='tab', aria-controls='account-settings', aria-expanded='true') Account settings
|
||||
a#calendar-settings-tab.tab.nav-item.nav-link(data-toggle='tab', href='#calendar-settings', role='tab', aria-controls='calendar-settings') Calendar settings
|
||||
else
|
||||
a#account-settings-tab.tab.nav-item.nav-link(data-toggle='tab', href='#account-settings', role='tab', aria-controls='account-settings') Account settings
|
||||
a#calendar-settings-tab.tab.nav-item.nav-link.active(data-toggle='tab', href='#calendar-settings', role='tab', aria-controls='calendar-settings', aria-expanded='true') Calendar settings
|
||||
|
||||
.tab-content
|
||||
if settingsFailed !== undefined
|
||||
if settingsFailed === false
|
||||
.form-group.row
|
||||
.col-2
|
||||
.col-8
|
||||
.alert.alert-success.alert-dismissible.fade.show Modifications saved !
|
||||
.col-2
|
||||
|
||||
else
|
||||
.form-group.row
|
||||
.col-2
|
||||
.col-8
|
||||
.alert.alert-danger.alert-dismissible.fade.show #{settingsFailed}
|
||||
.col-2
|
||||
|
||||
.tab-content
|
||||
#account-settings.tab-pane.fade(class=!calendar ? 'active show' : '', role='tabpanel', aria-labelledby='account-settings-tab')
|
||||
form.content(method="POST", action=getUrl("accountSettingsTarget"))
|
||||
.form-group.row
|
||||
.col-2
|
||||
label.col-2.col-form-label(for="username") Username
|
||||
.col-6
|
||||
input.form-control(type="text", value=session.user.username, disabled, name="username", id="username")
|
||||
input.form-control(type="text", value=session.user.username, name="username", id="username")
|
||||
.col-2
|
||||
.form-group.row
|
||||
.col-2
|
||||
label.col-2.col-form-label(for="email") Email
|
||||
.col-6
|
||||
input.form-control(type="email", value=session.user.email, disabled, name="email", id="email")
|
||||
input.form-control(type="email", value=session.user.email, name="email", id="email" disabled)
|
||||
.col-2
|
||||
.form-group.row
|
||||
.col-2
|
||||
label.col-2.col-form-label(for="oldpassword") Old password
|
||||
.col-6
|
||||
input#oldpassword.form-control(type='password', name='oldpassword')
|
||||
.col2
|
||||
.form-group.row
|
||||
.col-2
|
||||
label.col-2.col-form-label(for="pass1") New password
|
||||
.col-6
|
||||
input#pass1.form-control(type='password', name='newpassword')
|
||||
.col2
|
||||
.form-group.row
|
||||
.col-2
|
||||
label.col-2.col-form-label(for="psss2") Confirm
|
||||
.col-6
|
||||
input#pass2.form-control(type='password')
|
||||
.col2
|
||||
.form-group.row
|
||||
.col-2
|
||||
.col-8.form-text.text-muted.
|
||||
Leave <em>new password</em> and <em>confirm</em> empty
|
||||
if you do not wish to change your password
|
||||
.col-2
|
||||
|
||||
.form-group.row
|
||||
.col-2
|
||||
.col-8
|
||||
input.btn.btn-primary.form-control(type='submit', value='Submit changes')
|
||||
.col-2
|
||||
|
||||
|
||||
#calendar-settings.tab-pane.fade(class=calendar ? 'active show' : '',role='tabpanel', aria-labelledby='calendar-settings-tab')
|
||||
form.content(method="POST", action=getUrl("calendarSettingsTarget"))
|
||||
.form-group.row
|
||||
.col-2
|
||||
label.col-2.col-form-label(for="resources") Resources
|
||||
|
@ -47,11 +115,23 @@ block content
|
|||
.form-group.row
|
||||
.col-4
|
||||
.col-4
|
||||
input.btn.btn-primary.form-control(type="submit", value="Submit")
|
||||
input.btn.btn-primary.form-control(type="submit", value="Submit changes")
|
||||
.col-4
|
||||
|
||||
block extrajs
|
||||
script.
|
||||
$(function() {
|
||||
|
||||
var tabs = document.getElementsByClassName('tab');
|
||||
for (var i = 0; i < tabs.length; i++) {
|
||||
tabs[i].addEventListener('click', function() {
|
||||
var alerts = document.getElementsByClassName('alert');
|
||||
for (var j = 0; j < alerts.length; j++) {
|
||||
$(alerts[j]).alert('close');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var urlButton = document.getElementById('urlButton');
|
||||
var url = document.getElementById('url');
|
||||
var resources = document.getElementById('resources');
|
||||
|
@ -70,3 +150,4 @@ block extrajs
|
|||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
const url = require('create-url').url;
|
||||
|
||||
module.exports = [
|
||||
url('/settings/', 'settings', 'settings'),
|
||||
url('/settingsTarget/', 'settingsTarget', 'settingsTarget', 'POST'),
|
||||
url('/settings', 'accountSettings', 'settings'),
|
||||
url('/settings/account', 'accountSettings', 'accountSettings'),
|
||||
url('/settings/calendar', 'calendarSettings', 'calendarSettings'),
|
||||
url('/accountSettingsTarget/', 'accountSettingsTarget', 'accountSettingsTarget', 'POST'),
|
||||
url('/calendarSettingsTarget/', 'calendarSettingsTarget', 'calendarSettingsTarget', 'POST'),
|
||||
]
|
||||
|
|
|
@ -1,13 +1,52 @@
|
|||
const getUrl = require('create-url').getUrl;
|
||||
const User = require('auth/models');
|
||||
const model = require('model');
|
||||
|
||||
const redirectIfNotLogged = require('auth/views').redirectIfNotLogged;
|
||||
|
||||
module.exports.settings = redirectIfNotLogged('settings', function(req, res, render) {
|
||||
let SETTINGS_ERROR = {
|
||||
INCORRECT_PASSWORD: 'Your password is incorrect.',
|
||||
};
|
||||
|
||||
module.exports.accountSettings = redirectIfNotLogged('accountSettings', function(req, res, render) {
|
||||
if (req.session.settingsFailed !== undefined) {
|
||||
res.locals.settingsFailed = req.session.settingsFailed;
|
||||
req.session.settingsFailed = undefined;
|
||||
req.session.save();
|
||||
}
|
||||
render('settings.pug');
|
||||
});
|
||||
|
||||
module.exports.settingsTarget = function(req, res, render) {
|
||||
module.exports.calendarSettings = redirectIfNotLogged('calendarSettings', function(req, res, render) {
|
||||
if (req.session.settingsFailed !== undefined) {
|
||||
res.locals.settingsFailed = req.session.settingsFailed;
|
||||
req.session.settingsFailed = undefined;
|
||||
req.session.save();
|
||||
}
|
||||
res.locals.calendar = true;
|
||||
render('settings.pug');
|
||||
});
|
||||
|
||||
module.exports.accountSettingsTarget = function(req, res, render) {
|
||||
User.getById(req.session.user.id, (err, user) => {
|
||||
if (!model.PasswordField.testSync(req.body.oldpassword, user.password)) {
|
||||
req.session.settingsFailed = SETTINGS_ERROR.INCORRECT_PASSWORD;
|
||||
req.session.save();
|
||||
return res.redirect(getUrl('settings'));
|
||||
}
|
||||
|
||||
if (req.body.newpassword) {
|
||||
req.session.settingsFailed = false;
|
||||
req.session.save();
|
||||
user.password = req.body.newpassword;
|
||||
user.save(() => {
|
||||
return res.redirect(getUrl('accountSettings'));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.calendarSettingsTarget = function(req, res, render) {
|
||||
let projectId = parseInt(req.body.projectId, 10);
|
||||
let resources = parseInt(req.body.resources, 10);
|
||||
|
||||
|
@ -22,8 +61,9 @@ module.exports.settingsTarget = function(req, res, render) {
|
|||
|
||||
user.save(() => {
|
||||
req.session.user = user;
|
||||
req.session.settingsFailed = false;
|
||||
req.session.save();
|
||||
res.redirect(getUrl('index'));
|
||||
res.redirect(getUrl('calendarSettings'));
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -12,6 +12,10 @@ html
|
|||
body {
|
||||
padding-top: 65px;
|
||||
}
|
||||
*::-moz-focus-inner {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
block extracss
|
||||
title ADEjs
|
||||
body
|
||||
|
|
Loading…
Reference in New Issue