changed the signin form to a dialog

This commit is contained in:
hyung-hwan 2016-01-10 19:02:58 +00:00
parent 0e3d30989a
commit 6f2fb6c747
8 changed files with 153 additions and 55 deletions

View File

@ -20,6 +20,33 @@ class Main extends Controller
redirect ("main/signin/$xurl"); redirect ("main/signin/$xurl");
} }
function xhr_signin ()
{
$this->load->model ('UserModel', 'users');
if($this->input->post('user_name'))
{
$user_name = $this->input->post('user_name');
$user_pass = $this->input->post('user_pass');
if ($this->login->authenticate ($user_name, $user_pass) === FALSE)
{
print 'error - ' . $this->login->getErrorMessage();
}
else
{
$settings = $this->users->fetchSettings ($user_name);
if ($settings !== FALSE) $this->login->setUserSettings ($settings);
print 'ok';
}
}
else
{
$this->login->deauthenticate ();
print 'ok';
}
}
function signin ($xurl = '') function signin ($xurl = '')
{ {
$this->load->model ('UserModel', 'users'); $this->load->model ('UserModel', 'users');

View File

@ -130,6 +130,7 @@ $lang['MSG_NO_SUCH_PROJECT'] = 'No such project';
$lang['MSG_SURE_TO_DELETE_THIS'] = "I'm sure to delete this"; $lang['MSG_SURE_TO_DELETE_THIS'] = "I'm sure to delete this";
$lang['MSG_FAILED_TO_READ_FILE'] = 'Failed to read file - %s'; $lang['MSG_FAILED_TO_READ_FILE'] = 'Failed to read file - %s';
$lang['MSG_NO_SUCH_FILE'] = 'No such file - %s'; $lang['MSG_NO_SUCH_FILE'] = 'No such file - %s';
$lang['MSG_SIGNIN_FAILURE'] = 'Cannot sign in';
$lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = 'You have to be a member of the %s project to perform this task'; $lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = 'You have to be a member of the %s project to perform this task';
$lang['MSG_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete'; $lang['MSG_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete';

View File

@ -127,6 +127,7 @@ $lang['MSG_NO_SUCH_PROJECT'] = 'No such project';
$lang['MSG_SURE_TO_DELETE_THIS'] = "Saya yakin untuk menghapus"; $lang['MSG_SURE_TO_DELETE_THIS'] = "Saya yakin untuk menghapus";
$lang['MSG_FAILED_TO_READ_FILE'] = 'Failed to read file - %s'; $lang['MSG_FAILED_TO_READ_FILE'] = 'Failed to read file - %s';
$lang['MSG_NO_SUCH_FILE'] = 'No such file - %s'; $lang['MSG_NO_SUCH_FILE'] = 'No such file - %s';
$lang['MSG_SIGNIN_FAILURE'] = 'Cannot sign in';
$lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = 'You have to be a member of the %s project to perform this task'; $lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = 'You have to be a member of the %s project to perform this task';
$lang['MSG_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete'; $lang['MSG_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete';

View File

@ -130,6 +130,7 @@ $lang['MSG_NO_SUCH_PROJECT'] = '프로젝트가 없습니다';
$lang['MSG_SURE_TO_DELETE_THIS'] = '반드시 이것을 삭제하고 싶어요'; $lang['MSG_SURE_TO_DELETE_THIS'] = '반드시 이것을 삭제하고 싶어요';
$lang['MSG_FAILED_TO_READ_FILE'] = '파일을 읽을 수 없습니다 - %s'; $lang['MSG_FAILED_TO_READ_FILE'] = '파일을 읽을 수 없습니다 - %s';
$lang['MSG_NO_SUCH_FILE'] = '파일이 없습니다 - %s'; $lang['MSG_NO_SUCH_FILE'] = '파일이 없습니다 - %s';
$lang['MSG_SIGNIN_FAILURE'] = '로그인할 수 없습니다';
$lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = '이 작업을 수행하려면 %s 프로젝트의 멤버가 되어야 합니다'; $lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = '이 작업을 수행하려면 %s 프로젝트의 멤버가 되어야 합니다';
$lang['MSG_FORM_INPUT_INCOMPLETE'] = '입력이 완전하지 않습니다'; $lang['MSG_FORM_INPUT_INCOMPLETE'] = '입력이 완전하지 않습니다';

View File

@ -36,7 +36,7 @@ class DbLoginModel extends LoginModel
function authenticate ($userid, $passwd) function authenticate ($userid, $passwd)
{ {
$this->db->trans_start (); $this->db->trans_begin ();
$this->db->select ('userid,passwd,email'); $this->db->select ('userid,passwd,email');
$this->db->where ('userid', $userid); $this->db->where ('userid', $userid);
@ -45,27 +45,36 @@ class DbLoginModel extends LoginModel
if ($this->db->trans_status() == FALSE) if ($this->db->trans_status() == FALSE)
{ {
$this->db->trans_complete (); $this->setErrorMessage ($this->db->_error_message());
$this->db->trans_rollback ();
return FALSE; return FALSE;
} }
$result = $query->result (); $result = $query->result ();
if (empty($result)) if (empty($result))
{ {
$this->db->trans_complete (); $this->setErrorMessage ('invalid credential'); // no such user name
$this->db->trans_rollback ();
return FALSE; return FALSE;
} }
$this->db->trans_complete (); $this->db->trans_commit();
if ($this->db->trans_status() == FALSE) return FALSE;
$user = $result[0]; $user = $result[0];
if (strlen($user->passwd) < 10) return FALSE; if (strlen($user->passwd) < 10)
{
$this->setErrorMessage ('wrongly formatted password');
return FALSE;
}
// the last 10 characters are the salt. // the last 10 characters are the salt.
$hexsalt = substr ($user->passwd, -10); $hexsalt = substr ($user->passwd, -10);
$binsalt = pack('H*' , $hexsalt); $binsalt = pack('H*' , $hexsalt);
if (strcmp ($this->format_password_with_salt($passwd,$binsalt),$user->passwd) != 0) return FALSE; if (strcmp ($this->format_password_with_salt($passwd,$binsalt),$user->passwd) != 0)
{
$this->setErrorMessage ('invalid credential'); // invalid password
return FALSE;
}
return parent::authenticate ($userid, $user->passwd, $user->email); return parent::authenticate ($userid, $user->passwd, $user->email);
} }
@ -80,6 +89,7 @@ class DbLoginModel extends LoginModel
if ($this->db->trans_status() === FALSE) if ($this->db->trans_status() === FALSE)
{ {
$this->setErrorMessage ($this->db->_error_message());
$this->db->trans_rollback (); $this->db->trans_rollback ();
return FALSE; return FALSE;
} }
@ -98,6 +108,7 @@ class DbLoginModel extends LoginModel
if ($this->db->trans_status() == FALSE) if ($this->db->trans_status() == FALSE)
{ {
$this->setErrorMessage ($this->db->_error_message());
$this->db->trans_complete (); $this->db->trans_complete ();
return FALSE; return FALSE;
} }

View File

@ -699,7 +699,6 @@ $(function () {
} }
}, },
'<?php print $this->lang->line('Cancel')?>': function () { '<?php print $this->lang->line('Cancel')?>': function () {
if (import_in_progress) return;
$('#code_folder_search').dialog('close'); $('#code_folder_search').dialog('close');
} }
} }

View File

@ -39,65 +39,30 @@ function show_taskbar ($con, $login)
print '&nbsp;'; print '&nbsp;';
//print form_submit (
// 'login',
// $con->lang->line('Sign out'),
// 'class="button" id="taskbar_signinout_button"'
//);
printf ('<a href="#" id="taskbar_signinout_button">%s</a>', $con->lang->line('Sign out')); printf ('<a href="#" id="taskbar_signinout_button">%s</a>', $con->lang->line('Sign out'));
print form_close(); print form_close();
} }
else else
{ {
print form_open('main/signin', array('id' => 'taskbar_signinout_form')); print '<div id="taskbar_signin_container">';
print form_fieldset(); print '<div id="taskbar_signin_error"></div>';
$user_name = ""; print '<div id="taskbar_signin_form">';
$user_pass = "";
print form_hidden (
'user_url',
set_value ('user_url', current_url())
);
/*
print form_label(
$con->lang->line('Username'),
'taskbar_user_name'
);
print '&nbsp;';
*/
print form_input ( print form_input (
'user_name', 'user_name', set_value ('user_name', ''),
set_value ('user_name', $user_name),
"size='16' id='taskbar_user_name' placeholder={$con->lang->line('Username')}" "size='16' id='taskbar_user_name' placeholder={$con->lang->line('Username')}"
); );
print '&nbsp;';
/*
print form_label (
$con->lang->line('Password'),
'taskbar_user_pass'
);
print '&nbsp;';
*/
print form_password ( print form_password (
'user_pass', 'user_pass', set_value ('user_pass', ''),
set_value ('user_pass', $user_pass),
"size='16' id='taskbar_user_pass' placeholder={$con->lang->line('Password')}" "size='16' id='taskbar_user_pass' placeholder={$con->lang->line('Password')}"
); );
print '</div>';
print '</div>';
print '&nbsp;';
//print form_submit (
// 'login',
// $con->lang->line('Sign in'),
// 'class="button" id="taskbar_signinout_button"'
//);
printf ('<a href="#" id="taskbar_signinout_button">%s</a>', $con->lang->line('Sign in')); printf ('<a href="#" id="taskbar_signinout_button">%s</a>', $con->lang->line('Sign in'));
print form_fieldset_close();
print form_close();
} }
print '</div>'; // boxb print '</div>'; // boxb
@ -120,7 +85,7 @@ function show_taskbar ($con, $login)
} }
print '</ul>'; print '</ul>';
print '</div>'; print '</div>'; // boxa
print '</div>'; print '</div>';
} }
@ -140,20 +105,106 @@ function ready_to_signinout()
<?php endif; ?> <?php endif; ?>
} }
var taskbar_signin_in_progress = 0;
$(function () { $(function () {
$('#taskbar_signin_container').dialog ({
title: '<?php print $this->lang->line('Sign in'); ?>',
resizable: true,
autoOpen: false,
modal: true,
width: 'auto',
height: 'auto',
buttons: {
'<?php print $this->lang->line('OK')?>': function () {
if (taskbar_signin_in_progress) return;
if (!!window.FormData)
{
// FormData is supported
taskbar_signin_in_progress = true;
var form_data = new FormData();
form_data.append ('user_name', $('#taskbar_user_name').val());
form_data.append ('user_pass', $('#taskbar_user_pass').val());
$('#taskbar_signin_container').dialog('disable');
$.ajax({
url: codepot_merge_path('<?php print site_url() ?>', '<?php print "/main/xhr_signin"; ?>'),
type: 'POST',
data: form_data,
mimeType: 'multipart/form-data',
contentType: false,
processData: false,
cache: false,
success: function (data, textStatus, jqXHR) {
taskbar_signin_in_progress = false;
$('#taskbar_signin_container').dialog('enable');
if (data == 'ok')
{
$('#taskbar_signin_container').dialog('close');
// refresh the page to the head revision
$(location).attr ('href', '<?php print current_url(); ?>');
}
else
{
$('#taskbar_signin_error').text(codepot_htmlspecialchars('<?php print $this->lang->line('MSG_SIGNIN_FAILURE')?>'));
}
},
error: function (jqXHR, textStatus, errorThrown) {
taskbar_signin_in_progress = false;
$('#taskbar_signin_container').dialog('enable');
var errmsg = '';
if (errmsg == '' && errorThrown != null) errmsg = errorThrown;
if (errmsg == '' && textStatus != null) errmsg = textStatus;
if (errmsg == '') errmsg = 'Unknown error';
$('#taskbar_signin_error').text(codepot_htmlspecialchars(errmsg));
}
});
}
else
{
$('#taskbar_signin_error').text('NOT SUPPORTED');
}
},
'<?php print $this->lang->line('Cancel')?>': function () {
if (taskbar_signin_in_progress) return;
$('#taskbar_signin_container').dialog('close');
}
},
beforeClose: function() {
// if importing is in progress, prevent dialog closing
return !taskbar_signin_in_progress;
}
});
$("#taskbar_user_name").button().bind ('keyup', function(e) { $("#taskbar_user_name").button().bind ('keyup', function(e) {
if (e.keyCode == 13) { if (e.keyCode == 13)
if (ready_to_signinout()) $("#taskbar_signinout_form").submit(); {
var buttons = $("#taskbar_signin_container").dialog("option", "buttons");
buttons[Object.keys(buttons)[0]](); // trigger the first button
} }
}); });
$("#taskbar_user_pass").button().bind ('keyup', function(e) { $("#taskbar_user_pass").button().bind ('keyup', function(e) {
if (e.keyCode == 13) { if (e.keyCode == 13)
if (ready_to_signinout()) $("#taskbar_signinout_form").submit(); {
var buttons = $("#taskbar_signin_container").dialog("option", "buttons");
buttons[Object.keys(buttons)[0]](); // trigger the first button
} }
}); });
$("#taskbar_signinout_button").button().click (function() { $("#taskbar_signinout_button").button().click (function() {
<?php if (isset($login['id']) && $login['id'] != ''): ?>
if (ready_to_signinout()) $("#taskbar_signinout_form").submit(); if (ready_to_signinout()) $("#taskbar_signinout_form").submit();
<?php else: ?>
$('#taskbar_signin_container').dialog('open');
<?php endif; ?>
return false;
}); });
$("#taskbar_project_to_find").button().autocomplete({ $("#taskbar_project_to_find").button().autocomplete({

View File

@ -1000,6 +1000,13 @@ textarea {
line-height: 1em; line-height: 1em;
} }
#taskbar_signin_error {
color: #AA3344;
font-weight: bold;
text-align: center;
margin-bottom: 0.5em;
}
/* ================ login page =================== */ /* ================ login page =================== */
#login_user_name { #login_user_name {