diff --git a/codepot/src/codepot/controllers/main.php b/codepot/src/codepot/controllers/main.php index b0808abd..6eb4981a 100644 --- a/codepot/src/codepot/controllers/main.php +++ b/codepot/src/codepot/controllers/main.php @@ -20,6 +20,33 @@ class Main extends Controller 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 = '') { $this->load->model ('UserModel', 'users'); diff --git a/codepot/src/codepot/language/english/common_lang.php b/codepot/src/codepot/language/english/common_lang.php index c9e9597b..c45c88f4 100644 --- a/codepot/src/codepot/language/english/common_lang.php +++ b/codepot/src/codepot/language/english/common_lang.php @@ -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_FAILED_TO_READ_FILE'] = 'Failed to read 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_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete'; diff --git a/codepot/src/codepot/language/indonesian/common_lang.php b/codepot/src/codepot/language/indonesian/common_lang.php index fc4ce2fb..94b79561 100644 --- a/codepot/src/codepot/language/indonesian/common_lang.php +++ b/codepot/src/codepot/language/indonesian/common_lang.php @@ -127,6 +127,7 @@ $lang['MSG_NO_SUCH_PROJECT'] = 'No such project'; $lang['MSG_SURE_TO_DELETE_THIS'] = "Saya yakin untuk menghapus"; $lang['MSG_FAILED_TO_READ_FILE'] = 'Failed to read 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_FORM_INPUT_INCOMPLETE'] = 'Your input is incomplete'; diff --git a/codepot/src/codepot/language/korean/common_lang.php b/codepot/src/codepot/language/korean/common_lang.php index 5e902cac..5a59ec8f 100644 --- a/codepot/src/codepot/language/korean/common_lang.php +++ b/codepot/src/codepot/language/korean/common_lang.php @@ -130,6 +130,7 @@ $lang['MSG_NO_SUCH_PROJECT'] = '프로젝트가 없습니다'; $lang['MSG_SURE_TO_DELETE_THIS'] = '반드시 이것을 삭제하고 싶어요'; $lang['MSG_FAILED_TO_READ_FILE'] = '파일을 읽을 수 없습니다 - %s'; $lang['MSG_NO_SUCH_FILE'] = '파일이 없습니다 - %s'; +$lang['MSG_SIGNIN_FAILURE'] = '로그인할 수 없습니다'; $lang['MSG_PROJECT_MEMBERSHIP_REQUIRED'] = '이 작업을 수행하려면 %s 프로젝트의 멤버가 되어야 합니다'; $lang['MSG_FORM_INPUT_INCOMPLETE'] = '입력이 완전하지 않습니다'; diff --git a/codepot/src/codepot/models/dbloginmodel.php b/codepot/src/codepot/models/dbloginmodel.php index 8d5837a6..8fd50934 100644 --- a/codepot/src/codepot/models/dbloginmodel.php +++ b/codepot/src/codepot/models/dbloginmodel.php @@ -36,7 +36,7 @@ class DbLoginModel extends LoginModel function authenticate ($userid, $passwd) { - $this->db->trans_start (); + $this->db->trans_begin (); $this->db->select ('userid,passwd,email'); $this->db->where ('userid', $userid); @@ -45,27 +45,36 @@ class DbLoginModel extends LoginModel if ($this->db->trans_status() == FALSE) { - $this->db->trans_complete (); + $this->setErrorMessage ($this->db->_error_message()); + $this->db->trans_rollback (); return FALSE; } $result = $query->result (); if (empty($result)) { - $this->db->trans_complete (); + $this->setErrorMessage ('invalid credential'); // no such user name + $this->db->trans_rollback (); return FALSE; } - $this->db->trans_complete (); - if ($this->db->trans_status() == FALSE) return FALSE; + $this->db->trans_commit(); $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. $hexsalt = substr ($user->passwd, -10); $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); } @@ -80,6 +89,7 @@ class DbLoginModel extends LoginModel if ($this->db->trans_status() === FALSE) { + $this->setErrorMessage ($this->db->_error_message()); $this->db->trans_rollback (); return FALSE; } @@ -98,6 +108,7 @@ class DbLoginModel extends LoginModel if ($this->db->trans_status() == FALSE) { + $this->setErrorMessage ($this->db->_error_message()); $this->db->trans_complete (); return FALSE; } diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index 14abecf0..bd9c08ed 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -699,7 +699,6 @@ $(function () { } }, 'lang->line('Cancel')?>': function () { - if (import_in_progress) return; $('#code_folder_search').dialog('close'); } } diff --git a/codepot/src/codepot/views/taskbar.php b/codepot/src/codepot/views/taskbar.php index c2976a04..f37496ab 100644 --- a/codepot/src/codepot/views/taskbar.php +++ b/codepot/src/codepot/views/taskbar.php @@ -39,65 +39,30 @@ function show_taskbar ($con, $login) print ' '; - //print form_submit ( - // 'login', - // $con->lang->line('Sign out'), - // 'class="button" id="taskbar_signinout_button"' - //); printf ('%s', $con->lang->line('Sign out')); print form_close(); } else { - print form_open('main/signin', array('id' => 'taskbar_signinout_form')); + print '
'; - print form_fieldset(); + print '
'; - $user_name = ""; - $user_pass = ""; + print '
'; - print form_hidden ( - 'user_url', - set_value ('user_url', current_url()) - ); - - /* - print form_label( - $con->lang->line('Username'), - 'taskbar_user_name' - ); - print ' '; - */ print form_input ( - 'user_name', - set_value ('user_name', $user_name), + 'user_name', set_value ('user_name', ''), "size='16' id='taskbar_user_name' placeholder={$con->lang->line('Username')}" ); - print ' '; - /* - print form_label ( - $con->lang->line('Password'), - 'taskbar_user_pass' - ); - print ' '; - */ print form_password ( - 'user_pass', - set_value ('user_pass', $user_pass), + 'user_pass', set_value ('user_pass', ''), "size='16' id='taskbar_user_pass' placeholder={$con->lang->line('Password')}" ); + print '
'; + print '
'; - print ' '; - //print form_submit ( - // 'login', - // $con->lang->line('Sign in'), - // 'class="button" id="taskbar_signinout_button"' - //); printf ('%s', $con->lang->line('Sign in')); - - print form_fieldset_close(); - print form_close(); } print ''; // boxb @@ -120,7 +85,7 @@ function show_taskbar ($con, $login) } print ''; - print ''; + print ''; // boxa print ''; } @@ -140,20 +105,106 @@ function ready_to_signinout() } +var taskbar_signin_in_progress = 0; + $(function () { + $('#taskbar_signin_container').dialog ({ + title: 'lang->line('Sign in'); ?>', + resizable: true, + autoOpen: false, + modal: true, + width: 'auto', + height: 'auto', + buttons: { + '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('', ''), + 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', ''); + } + else + { + $('#taskbar_signin_error').text(codepot_htmlspecialchars('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'); + } + + }, + '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) { - if (e.keyCode == 13) { - if (ready_to_signinout()) $("#taskbar_signinout_form").submit(); + if (e.keyCode == 13) + { + 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) { - if (e.keyCode == 13) { - if (ready_to_signinout()) $("#taskbar_signinout_form").submit(); + if (e.keyCode == 13) + { + var buttons = $("#taskbar_signin_container").dialog("option", "buttons"); + buttons[Object.keys(buttons)[0]](); // trigger the first button } }); $("#taskbar_signinout_button").button().click (function() { + if (ready_to_signinout()) $("#taskbar_signinout_form").submit(); + + $('#taskbar_signin_container').dialog('open'); + + return false; }); $("#taskbar_project_to_find").button().autocomplete({ diff --git a/codepot/src/css/common.css b/codepot/src/css/common.css index 0ff294d8..0a728e66 100644 --- a/codepot/src/css/common.css +++ b/codepot/src/css/common.css @@ -1000,6 +1000,13 @@ textarea { line-height: 1em; } +#taskbar_signin_error { + color: #AA3344; + font-weight: bold; + text-align: center; + margin-bottom: 0.5em; +} + /* ================ login page =================== */ #login_user_name {