예제 #1
0
 static function form()
 {
     try {
         $anonymous = Variable::get('anonymous_setup');
     } catch (NoSuchVariableException $e) {
         $anonymous = true;
     }
     if (!Base_AclCommon::is_user() && Base_User_LoginCommon::is_banned()) {
         return self::t('You have exceeded the number of allowed login attempts.');
     }
     require_once 'modules/Libs/QuickForm/requires.php';
     if (!Base_AclCommon::is_user() && !$anonymous) {
         Base_User_LoginCommon::autologin();
     }
     if (!Base_AclCommon::is_user() && !$anonymous) {
         $get = count($_GET) ? '?' . http_build_query($_GET) : '';
         $form = new HTML_QuickForm('loginform', 'post', $_SERVER['PHP_SELF'] . $get);
         $form->setRequiredNote('<span style="font-size:80%; color:#ff0000;">*</span><span style="font-size:80%;">' . self::t('denotes required field') . '</span>');
         $form->addElement('text', 'username', self::t('Username'));
         $form->addRule('username', 'Field required', 'required');
         $form->addElement('password', 'password', self::t('Password'));
         $form->addRule('password', 'Field required', 'required');
         // register and add a rule to check if user is banned
         $form->registerRule('check_user_banned', 'callback', 'rule_login_banned', 'Base_User_LoginCommon');
         $form->addRule('username', self::t('You have exceeded the number of allowed login attempts.'), 'check_user_banned');
         // register and add a rule to check if user and password exists
         $form->registerRule('check_login', 'callback', 'submit_login', 'Base_User_LoginCommon');
         $form->addRule(array('username', 'password'), self::t('Login or password incorrect'), 'check_login', $form);
         $form->addElement('submit', null, self::t('Login'));
         if ($form->validate()) {
             $user = $form->exportValue('username');
             Base_AclCommon::set_user(Base_UserCommon::get_user_id($user), true);
             // redirect below is used to better browser refresh behavior.
             header('Location: ' . $_SERVER['REQUEST_URI']);
         } else {
             return "<center>" . $form->toHtml() . "</center>";
         }
     }
 }
예제 #2
0
파일: Login_0.php 프로젝트: 62BRAINS/EPESI
 public function body($tpl = null)
 {
     //check bans
     if (!Acl::is_user() && Base_User_LoginCommon::is_banned()) {
         print __('You have exceeded the number of allowed login attempts.') . '<br>';
         print '<a href="' . get_epesi_url() . '">' . __('Host banned. Click here to refresh.') . '</a>';
         return;
     }
     //if logged
     $this->theme->assign('is_logged_in', Acl::is_user());
     $this->theme->assign('is_demo', DEMO_MODE);
     if (SUGGEST_DONATION) {
         $this->theme->assign('donation_note', __('If you find our software useful, please support us by making a %s.', array('<a href="http://epe.si/cost" target="_blank">' . __('donation') . '</a>')) . '<br>' . __('Your funding will help to ensure continued development of this project.'));
     }
     if (Acl::is_user()) {
         if ($this->get_unique_href_variable('logout')) {
             Base_User_LoginCommon::logout();
             eval_js('document.location=\'index.php\';', false);
         } else {
             $this->theme->assign('logged_as', '<div class="logged_as">' . __('Logged as %s', array('</br><b class="green">' . Base_UserCommon::get_my_user_login() . '</b>')) . '</div>');
             $this->theme->assign('logout', '<div class="logout_css3_box"><a class="logout_icon" ' . $this->create_unique_href(array('logout' => 1)) . '>' . __('Logout') . '<div class="logout_icon_img"></div></a></div>');
             $this->theme->display();
         }
         return;
     }
     if ($this->is_back()) {
         $this->unset_module_variable('mail_recover_pass');
     }
     //if recover pass
     if ($this->get_module_variable_or_unique_href_variable('mail_recover_pass') == '1') {
         $this->recover_pass();
         return;
     }
     if (isset($_REQUEST['password_recovered'])) {
         $this->theme->assign('message', __('An e-mail with a new password has been sent.') . '<br><a href="' . get_epesi_url() . '">' . __('Login') . '</a>');
         $this->theme->display();
         return;
     }
     if ($this->autologin()) {
         return;
     }
     //else just login form
     $form = $this->init_module('Libs/QuickForm', __('Logging in'));
     $form->addElement('header', 'login_header', __('Login'));
     if (DEMO_MODE) {
         global $demo_users;
         $form->addElement('select', 'username', __('Username'), $demo_users, array('id' => 'username', 'onChange' => 'this.form.elements["password"].value=this.options[this.selectedIndex].value;'));
         $form->addElement('hidden', 'password', key($demo_users));
     } else {
         $form->addElement('text', 'username', __('Username'), array('id' => 'username'));
         $form->addElement('password', 'password', __('Password'));
     }
     // Display warning about storing a cookie
     if (Base_User_LoginCommon::is_autologin_forbidden() == false) {
         $warning = __('Keep this box unchecked if using a public computer');
         $form->addElement('static', 'warning', null, $warning);
         $form->addElement('checkbox', 'autologin', '', __('Remember me'));
     }
     $form->addElement('static', 'recover_password', null, '<a ' . $this->create_unique_href(array('mail_recover_pass' => 1)) . '>' . __('Recover password') . '</a>');
     $form->addElement('submit', 'submit_button', __('Login'), array('class' => 'submit'));
     // register and add a rule to check if user is banned
     $form->registerRule('check_user_banned', 'callback', 'rule_login_banned', 'Base_User_LoginCommon');
     $form->addRule('username', __('You have exceeded the number of allowed login attempts for this username. Try again later.'), 'check_user_banned');
     // register and add a rule to check if a username and password is ok
     $form->registerRule('check_login', 'callback', 'submit_login', 'Base_User_LoginCommon');
     $form->addRule(array('username', 'password'), __('Login or password incorrect'), 'check_login');
     $form->addRule('username', __('Field required'), 'required');
     $form->addRule('password', __('Field required'), 'required');
     if ($form->isSubmitted() && $form->validate()) {
         $user = $form->exportValue('username');
         Base_User_LoginCommon::set_logged($user);
         if (Base_User_LoginCommon::is_autologin_forbidden() == false) {
             $autologin = $form->exportValue('autologin');
             if ($autologin) {
                 Base_User_LoginCommon::new_autologin_id();
             }
         }
         location(array());
     } else {
         $form->assign_theme('form', $this->theme);
         $this->theme->assign('mode', 'login');
         $logo = $this->init_module('Base/MainModuleIndicator');
         $logo->set_inline_display();
         $this->theme->assign('logo', $this->get_html_of_module($logo, null, 'login_logo'));
         ob_start();
         if (!$tpl) {
             $this->theme->set_inline_display();
             $this->theme->display();
             eval_js("focus_by_id('username')");
         } else {
             Base_ThemeCommon::display_smarty($this->theme->get_smarty(), $tpl[0], $tpl[1]);
         }
         $ret = ob_get_clean();
         if (stripos($ret, '<a href="http://www.telaxus.com">Telaxus LLC</a>') === false || stripos($ret, '<a href="http://epe.si/"><img src="images/epesi-powered.png" alt="EPESI powered" /></a>') === false) {
             trigger_error('Epesi terms of use have been violated', E_USER_ERROR);
         }
         print $ret;
     }
 }