Improve settings window and cleanup

This commit is contained in:
Eike Foken
2011-05-06 12:33:43 +02:00
parent 90c27d82cd
commit 6a1ae19983
9 changed files with 299 additions and 272 deletions

View File

@@ -52,7 +52,7 @@ $autoload['packages'] = array(APPPATH.'third_party');
| $autoload['libraries'] = array('database', 'session', 'xmlrpc'); | $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/ */
$autoload['libraries'] = array('lang_detect', 'database', 'session'); $autoload['libraries'] = array('lang_detect', 'database', 'session', 'access');
/* /*

View File

@@ -7,197 +7,200 @@
*/ */
class Auth extends CI_Controller { class Auth extends CI_Controller {
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
$this->load->library('access'); $this->load->library('access');
$this->load->library('form_validation'); $this->load->library('form_validation');
$this->load->model('user'); $this->load->model('user');
} }
//redirect if needed, otherwise display the user list /**
public function index() { * Redirects the user if needed, otherwise display the layout.
if (!$this->access->loggedIn()) { */
redirect('auth/login'); public function index() {
} else { if (!$this->access->loggedIn()) {
//set the flash data error message if there is one redirect('auth/login');
$this->data['message'] = validation_errors() ? validation_errors() : $this->session->flashdata('message'); } else {
$this->load->view('index');
}
}
//$this->data['users'] = $this->access->getUsers(); /**
$this->load->view('index', $this->data); * Logs the user in - or not ;-)
} */
} public function login() {
if ($this->access->loggedIn()) {
redirect();
}
/** // validate form input
* Logs the user in - or not ;-) $this->form_validation->set_rules('username', "Benutzername", 'required');
*/ $this->form_validation->set_rules('password', "Passwort", 'required');
public function login() {
if ($this->access->loggedIn()) {
redirect('welcome');
}
// validate form input if ($this->form_validation->run() == true) {
$this->form_validation->set_rules('username', "Benutzername", 'required'); // check for "remember me"
$this->form_validation->set_rules('password', "Passwort", 'required'); $remember = (boolean) $this->input->post('remember');
if ($this->form_validation->run() == true) { if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) {
// check for "remember me" $this->data['success'] = true;
$remember = (boolean) $this->input->post('remember'); } else { // if the login was un-successful
$this->data['success'] = false;
$this->data['message'] = $this->access->errors();
}
if ($this->access->login($this->input->post('username'), $this->input->post('password'), $remember)) { // output JSON data
$this->data['success'] = true; $this->output->set_content_type('application/json')
} else { // if the login was un-successful ->set_output(json_encode($this->data));
$this->data['success'] = false; } else {
$this->data['message'] = $this->access->errors(); $this->data['message'] = validation_errors() ? validation_errors() : null;
} $this->data['username'] = $this->form_validation->set_value('username');
// output json data $this->load->view('auth/login', $this->data);
$this->output->set_content_type('application/json') }
->set_output(json_encode($this->data)); }
} else {
$this->data['message'] = validation_errors() ? validation_errors() : null;
$this->data['username'] = $this->form_validation->set_value('username');
$this->load->view('auth/login', $this->data); /**
} * Logs the user out.
} */
public function logout() {
$logout = $this->access->logout();
/** // output JSON data
* Logs the user out. $this->output->set_content_type('application/json')
*/ ->set_output(json_encode(array('success' => true)));
public function logout() { }
$logout = $this->access->logout();
redirect('auth');
}
/** /**
* Allows users to register. * Allows users to register.
*/ */
public function register() { public function register() {
if ($this->access->loggedIn()) { if ($this->access->loggedIn()) {
redirect('welcome'); redirect('welcome');
} }
// validate form input // validate form input
$this->form_validation->set_rules('username', "Username", 'required'); $this->form_validation->set_rules('username', "Username", 'required');
$this->form_validation->set_rules('realname', "Realname", 'required'); $this->form_validation->set_rules('realname', "Realname", 'required');
$this->form_validation->set_rules('email', "Email address", 'required|valid_email'); $this->form_validation->set_rules('email', "Email address", 'required|valid_email');
$this->form_validation->set_rules('password', "Password", 'required|min_length[' . $this->config->item('min_password_length', 'access') . ']|max_length[' . $this->config->item('max_password_length', 'access') . ']|matches[password_confirm]'); $this->form_validation->set_rules('password', "Password", 'required|min_length[' . $this->config->item('min_password_length', 'access') . ']|max_length[' . $this->config->item('max_password_length', 'access') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', "Password confirmation", 'required'); $this->form_validation->set_rules('password_confirm', "Password confirmation", 'required');
if ($this->form_validation->run() == true) { if ($this->form_validation->run() == true) {
$username = $this->input->post('username'); $username = $this->input->post('username');
$email = $this->input->post('email'); $email = $this->input->post('email');
$password = $this->input->post('password'); $password = $this->input->post('password');
$additional_data = array( $additional_data = array(
'realname' => $this->input->post('realname'), 'realname' => $this->input->post('realname'),
); );
} }
if ($this->form_validation->run() == true && $this->access->register($username, $password, $email, $additional_data)) { if ($this->form_validation->run() == true && $this->access->register($username, $password, $email, $additional_data)) {
// redirect them to the login page // redirect them to the login page
$this->session->set_flashdata('message', "Registration successful"); $this->session->set_flashdata('message', "Registration successful");
redirect('auth/register_success'); redirect('auth/register_success');
} else { } else {
// set the flash data error message if there is one // set the flash data error message if there is one
$this->data['message'] = validation_errors() ? validation_errors() : ($this->access->errors() ? $this->access->errors() : $this->session->flashdata('message')); $this->data['message'] = validation_errors() ? validation_errors() : ($this->access->errors() ? $this->access->errors() : $this->session->flashdata('message'));
$this->data['username'] = $this->form_validation->set_value('username'); $this->data['username'] = $this->form_validation->set_value('username');
$this->data['email'] = $this->form_validation->set_value('email'); $this->data['email'] = $this->form_validation->set_value('email');
$this->data['realname'] = $this->form_validation->set_value('realname'); $this->data['realname'] = $this->form_validation->set_value('realname');
$this->data['password'] = $this->form_validation->set_value('password'); $this->data['password'] = $this->form_validation->set_value('password');
$this->data['password_confirm'] = $this->form_validation->set_value('password_confirm'); $this->data['password_confirm'] = $this->form_validation->set_value('password_confirm');
$this->load->view('auth/register', $this->data); $this->load->view('auth/register', $this->data);
} }
} }
public function register_success() { /**
$this->load->view('auth/register_success', $this->data); * Allows users to edit their settings.
} */
public function settings() {
if (!$this->access->loggedIn()) {
redirect('auth/login', 'refresh');
}
public function settings() { // validate the form
if (!$this->access->loggedIn()) { $this->form_validation->set_rules('new_password', 'New Password', 'min_length[' . $this->config->item('min_password_length', 'auth') . ']|max_length[' . $this->config->item('max_password_length', 'access') . ']|matches[new_password_confirm]');
redirect('auth/login', 'refresh');
}
// validate form if ($this->form_validation->run() == true) {
$this->form_validation->set_rules('new_password', 'New Password', 'min_length[' . $this->config->item('min_password_length', 'auth') . ']|max_length[' . $this->config->item('max_password_length', 'access') . ']|matches[new_password_confirm]'); // change password if needed
if ($this->input->post('new_password') != '') {
$username = $this->session->userdata('username');
$change = $this->access->changePassword($username, $this->input->post('old_password'), $this->input->post('new_password'));
if ($this->form_validation->run() == true) { if ($change) {
// change password if needed $this->logout();
if ($this->input->post('new_password') != '') { }
$username = $this->session->userdata('username'); }
$change = $this->access->changePassword($username, $this->input->post('old_password'), $this->input->post('new_password'));
if ($change) { // update user
$this->logout(); $updateData = array(
}
}
// update user
$updateData = array(
'firstname' => $this->input->post('firstname'), 'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'), 'lastname' => $this->input->post('lastname'),
'institution' => $this->input->post('institution'), 'institution' => $this->input->post('institution'),
'phone' => $this->input->post('phone'), 'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'), 'email' => $this->input->post('email'),
); );
$this->access->updateUser($this->session->userdata('user_id'), $updateData); $this->access->updateUser($this->session->userdata('user_id'), $updateData);
echo "{success: true}"; // output JSON data
} else { $this->output->set_content_type('application/json')
$this->data['success'] = true; ->set_output(json_encode(array('success' => true)));
$this->data['data'] = $this->access->getCurrentUser(); } else {
$data['success'] = true;
$data['data'] = $this->access->getCurrentUser();
// output json data // output JSON data
$this->output->set_content_type('application/json') $this->output->set_content_type('application/json')
->set_output(json_encode($this->data)); ->set_output(json_encode($data));
} }
} }
//forgot password /**
public function forgot_password() { * Allows users to request a new password.
$this->form_validation->set_rules('email', 'Email Address', 'required'); */
if ($this->form_validation->run() == false) { public function forgot_password() {
//setup the input $this->form_validation->set_rules('email', 'Email Address', 'required');
$this->data['email'] = array('name' => 'email', if ($this->form_validation->run() == false) {
//setup the input
$this->data['email'] = array('name' => 'email',
'id' => 'email', 'id' => 'email',
); );
//set any errors and display the form //set any errors and display the form
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message'); $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->load->view('auth/forgot_password', $this->data); $this->load->view('auth/forgot_password', $this->data);
} else { } else {
//run the forgotten password method to email an activation code to the user //run the forgotten password method to email an activation code to the user
$forgotten = $this->access->forgotten_password($this->input->post('email')); $forgotten = $this->access->forgotten_password($this->input->post('email'));
if ($forgotten) { //if there were no errors if ($forgotten) { //if there were no errors
$this->session->set_flashdata('message', $this->access->messages()); $this->session->set_flashdata('message', $this->access->messages());
redirect("auth/login", 'refresh'); //we should display a confirmation page here instead of the login page redirect("auth/login", 'refresh'); //we should display a confirmation page here instead of the login page
} else { } else {
$this->session->set_flashdata('message', $this->access->errors()); $this->session->set_flashdata('message', $this->access->errors());
redirect("auth/forgot_password", 'refresh'); redirect("auth/forgot_password", 'refresh');
} }
} }
} }
//reset password - final step for forgotten password /**
public function reset_password($code) { * Final step for forgotten password.
$reset = $this->access->forgotten_password_complete($code); */
public function reset_password($code) {
$reset = $this->access->forgotten_password_complete($code);
if ($reset) { //if the reset worked then send them to the login page if ($reset) { //if the reset worked then send them to the login page
$this->session->set_flashdata('message', $this->access->messages()); $this->session->set_flashdata('message', $this->access->messages());
redirect('auth/login'); redirect('auth/login');
} else { //if the reset didnt work then send them back to the forgot password page } else { //if the reset didnt work then send them back to the forgot password page
$this->session->set_flashdata('message', $this->access->errors()); $this->session->set_flashdata('message', $this->access->errors());
redirect('auth/forgot_password'); redirect('auth/forgot_password');
} }
} }
public function test() {
echo "{xtype: 'form', title: 'Bla'}";
}
} }
/* End of file auth.php */ /* End of file auth.php */

View File

@@ -24,7 +24,7 @@
<?=img(array('src' => 'assets/images/logo.png', 'style' => 'margin-left: 5px'));?> <?=img(array('src' => 'assets/images/logo.png', 'style' => 'margin-left: 5px'));?>
<div style="float: right; margin-top: 15px; margin-right: 10px; color: #ccc;"> <div style="float: right; margin-top: 15px; margin-right: 10px; color: #ccc;">
<a href="javascript:void(0);" onclick="settings.show();" style="padding: 5px">Einstellungen</a> | <a href="javascript:void(0);" onclick="settings.show();" style="padding: 5px">Einstellungen</a> |
<?=anchor('auth/logout', "Logout", array('style' => 'padding: 5px;'));?> <a href="javascript:void(0);" onclick="logout();" style="padding: 5px">Logout</a>
</div> </div>
<?=img(array('src' => 'assets/images/lang_' . $this->config->item('lang_selected') . '.png', 'style' => 'float: right; margin-top: 18px; margin-right: 5px;'));?> <?=img(array('src' => 'assets/images/lang_' . $this->config->item('lang_selected') . '.png', 'style' => 'float: right; margin-top: 18px; margin-right: 5px;'));?>
</div> </div>

View File

@@ -25,7 +25,7 @@ var projectTree = new Ext.tree.TreePanel({
dataUrl: BASE_URL + 'projects/getAvailable', dataUrl: BASE_URL + 'projects/getAvailable',
root: { root: {
nodeType: 'async', nodeType: 'async',
text: 'Projekte', text: "Projekte",
expanded: true, expanded: true,
id: 'projects' id: 'projects'
} }
@@ -48,7 +48,7 @@ var tabPanel = new Ext.TabPanel({
id: 'tab_welcome', id: 'tab_welcome',
bodyStyle: 'padding: 10px', bodyStyle: 'padding: 10px',
title: "Willkommen", title: "Willkommen",
closable: true, closable: true
}] }]
}); });
@@ -85,32 +85,21 @@ var layoutMain = new Ext.Viewport({
}, layoutCenter] }, layoutCenter]
}); });
function logout() {
Ext.Ajax.request({
url: BASE_URL + 'auth/logout',
method: 'post',
success: function(xhr) {
window.location = BASE_URL + 'auth/login';
}
});
}
function loadProjectInfo(n) { function loadProjectInfo(n) {
if(n.isLeaf()){ if (n.isLeaf()) {
Ext.Ajax.request({ Ext.Ajax.request({
url: BASE_URL + 'projects/detail/' + n.prjId, url: BASE_URL + 'projects/detail/' + n.prjId,
method: 'get', method: 'get',
success: function ( result, request ) { success: function(result, request) {
var theResponse = Ext.util.JSON.decode(result.responseText); var theResponse = Ext.util.JSON.decode(result.responseText);
tabPanel.add({ tabPanel.add({
title: 'New Tab ', title: "New Tab",
html: 'Lade Projekt...', html: "Lade Projekt...",
closable:true closable: true
}).show(); }).show();
}, },
failure: function ( result, request ) { failure: function(result, request) {
switch(result.status) { switch(result.status) {
case 404: case 404:
Ext.MessageBox.alert("Fehler", "Das gewünschte Projekt konnte nicht gefunden werden."); Ext.MessageBox.alert("Fehler", "Das gewünschte Projekt konnte nicht gefunden werden.");
@@ -119,13 +108,11 @@ function loadProjectInfo(n) {
Ext.MessageBox.alert("Fehler", "Sie besitzen nicht die nötigen Zugriffsrechte, um dieses Projekt zu lesen." Ext.MessageBox.alert("Fehler", "Sie besitzen nicht die nötigen Zugriffsrechte, um dieses Projekt zu lesen."
+ "Wenden Sie sich an den Projektbesitzer, um Zugriff zu erhalten."); + "Wenden Sie sich an den Projektbesitzer, um Zugriff zu erhalten.");
break; break;
} };
} }
}); });
} }
} }
</script> </script>
<div id="main"></div> <div id="main"></div>

View File

@@ -36,3 +36,7 @@ a:hover {
.x-tree-node-icon { .x-tree-node-icon {
height: 16px !important; height: 16px !important;
} }
.x-form-display-field {
color: #777;
}

View File

@@ -3,94 +3,109 @@
* *
* @class SettingsWindow * @class SettingsWindow
* @extends Ext.Window * @extends Ext.Window
* @author Eike Foken <kontakt@eikefoken.de>
*/ */
SettingsWindow = Ext.extend(Ext.Window, { SettingsWindow = Ext.extend(Ext.Window, {
title: lang['settings_window_title'], title: lang['settings_window_title'],
id: 'settings-window', id: 'settings-window',
width: 400, width: 400,
autoHeight: true, closeAction: 'hide',
closeAction: 'hide', draggable: false,
draggable: false, resizable: false,
resizable: false, modal: true,
modal: true, initComponent: function() {
initComponent: function() { this.items = [{
this.items = [{ xtype: 'form',
xtype: 'form', id: 'settings-form',
id: 'settings-form', url: BASE_URL + 'auth/settings',
url: BASE_URL + 'auth/settings', method: 'post',
method: 'POST', border: false,
border: false, items: [{
items: [{ xtype: 'tabpanel',
xtype: 'tabpanel', border: false,
border: false, activeTab: 0,
activeTab: 0, defaults: {
defaults: { layout: 'form',
layout: 'form', defaultType: 'textfield',
defaultType: 'textfield', labelWidth: 170,
labelWidth: 170, height: 150,
autoHeight: true, bodyStyle: 'padding: 10px'
bodyStyle: 'padding: 10px' },
}, items: [{
items: [{ xtype: 'panel',
xtype: 'panel', title: lang['settings_window_panel_profile'],
id: 'password', items: [{
title: lang['settings_window_panel_password'], fieldLabel: lang['settings_window_firstname'],
items: [{ name: 'firstname'
fieldLabel: lang['settings_window_old_password'], }, {
name: 'old_password' fieldLabel: lang['settings_window_lastname'],
}, { name: 'lastname'
fieldLabel: lang['settings_window_new_password'], }, {
name: 'new_password' fieldLabel: lang['settings_window_institution'],
}, { name: 'institution'
fieldLabel: lang['settings_window_new_password_confirm'], }, {
name: 'new_password_confirm' fieldLabel: lang['settings_window_phone'],
}] name: 'phone'
}, { }, {
xtype: 'panel', fieldLabel: lang['settings_window_email'],
title: lang['settings_window_panel_profile'], name: 'email'
items: [{ }]
fieldLabel: lang['settings_window_firstname'], }, {
name: 'firstname' xtype: 'panel',
}, { id: 'password',
fieldLabel: lang['settings_window_lastname'], title: lang['settings_window_panel_password'],
name: 'lastname' items: [{
}, { fieldLabel: lang['settings_window_old_password'],
fieldLabel: lang['settings_window_institution'], name: 'old_password',
name: 'institution' inputType: 'password'
}, { }, {
fieldLabel: lang['settings_window_phone'], fieldLabel: lang['settings_window_new_password'],
name: 'phone' name: 'new_password',
}, { inputType: 'password'
fieldLabel: lang['settings_window_email'], }, {
name: 'email' fieldLabel: lang['settings_window_new_password_confirm'],
}] name: 'new_password_confirm',
}] inputType: 'password'
}], }, {
buttons: [{ xtype: 'displayfield',
text: lang['settings_window_save'], value: lang['settings_window_password_note'],
handler: function() { hideLabel: true
Ext.getCmp('settings-form').getForm().submit(); }]
} }]
}, { }],
text: lang['settings_window_close'], buttons: [{
handler: function() { text: lang['settings_window_save'],
this.hide(); handler: function() {
} var theForm = Ext.getCmp('settings-form').getForm();
}]
}];
// call parent if (theForm.isValid()) {
SettingsWindow.superclass.initComponent.apply(this); theForm.submit({
}, success: function() {
beforeShow: function() { Ext.getCmp('settings-window').hide();
Ext.getCmp('settings-form').load({ }
url : BASE_URL + 'auth/settings', });
waitMsg: "Lade..." }
}); }
}, {
text: lang['settings_window_cancel'],
handler: function() {
Ext.getCmp('settings-window').hide();
}
}]
}];
// call parent // call parent
SettingsWindow.superclass.beforeShow.apply(this); SettingsWindow.superclass.initComponent.apply(this);
} },
beforeShow: function() {
Ext.getCmp('settings-form').load({
url : BASE_URL + 'auth/settings',
waitMsg: "Lade..."
});
// call parent
SettingsWindow.superclass.beforeShow.apply(this);
}
}); });
// register xtype to allow for lazy initialization // register xtype to allow for lazy initialization

View File

@@ -3,6 +3,7 @@
* *
* @param {} title * @param {} title
* @param {} message * @param {} message
* @param {} icon
*/ */
var message = function(title, message, icon) { var message = function(title, message, icon) {
Ext.Msg.show({ Ext.Msg.show({
@@ -15,11 +16,26 @@ var message = function(title, message, icon) {
}); });
}; };
var settings = new SettingsWindow(); /**
* Logs the user out.
*/
var logout = function() {
Ext.Ajax.request({
url: BASE_URL + 'auth/logout',
method: 'post',
success: function(xhr) {
window.location = BASE_URL + 'auth/login';
}
});
};
/** /**
* Application main entry point * Application main entry point
*/ */
Ext.onReady(function() { Ext.onReady(function() {
Ext.QuickTips.init(); Ext.QuickTips.init();
if (typeof(SettingsWindow) == "function") {
settings = new SettingsWindow();
}
}); });

View File

@@ -1,12 +1,13 @@
var lang = { var lang = {
settings_window_title: "Settings", settings_window_title: "Settings",
settings_window_save: "Save", settings_window_save: "Save",
settings_window_close: "Close", settings_window_cancel: "Cancel",
settings_window_panel_password: "Password", settings_window_panel_password: "Password",
settings_window_panel_profile: "Profile", settings_window_panel_profile: "Profile",
settings_window_old_password: "Old password", settings_window_old_password: "Current password",
settings_window_new_password: "New password", settings_window_new_password: "New password",
settings_window_new_password_confirm: "Confirm new password", settings_window_new_password_confirm: "Confirm new password",
settings_window_password_note: "If you want to change your password, please fill out these fields, otherwise leave it blank.",
settings_window_firstname: "Firstname", settings_window_firstname: "Firstname",
settings_window_lastname: "Lastname", settings_window_lastname: "Lastname",
settings_window_institution: "Company", settings_window_institution: "Company",

View File

@@ -1,12 +1,13 @@
var lang = { var lang = {
settings_window_title: "Einstellungen", settings_window_title: "Einstellungen",
settings_window_save: "Speichern", settings_window_save: "Speichern",
settings_window_close: "Schließen", settings_window_cancel: "Abbrechen",
settings_window_panel_password: "Passwort", settings_window_panel_password: "Passwort",
settings_window_panel_profile: "Profil", settings_window_panel_profile: "Profil",
settings_window_old_password: "Altes Passwort", settings_window_old_password: "Aktuelles Passwort",
settings_window_new_password: "Neues Passwort", settings_window_new_password: "Neues Passwort",
settings_window_new_password_confirm: "Neues Passwort wiederholen", settings_window_new_password_confirm: "Neues Passwort bestätigen",
settings_window_password_note: "Wenn Sie Ihr Passwort ändern möchten, füllen Sie bitte die obigen Felder aus, ansonsten lassen Sie sie einfach leer.",
settings_window_firstname: "Vorname", settings_window_firstname: "Vorname",
settings_window_lastname: "Nachname", settings_window_lastname: "Nachname",
settings_window_institution: "Institut", settings_window_institution: "Institut",