public function loginAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_redirect('/');
     }
     $form = new SP_Form_Login();
     $request = $this->getRequest();
     if ($request->isPost() && $form->isValid($_POST)) {
         $username = $request->getParam('name');
         $pwd = $request->getParam('pwd');
         $authAdapter = SP_Application::getAuthAdapter();
         $authAdapter->setIdentity($username)->setCredential($pwd);
         $auth = Zend_Auth::getInstance();
         $result = $auth->authenticate($authAdapter);
         if ($result->isValid()) {
             $storage = $auth->getStorage();
             $storage->write($authAdapter->getResultRowObject(null, 'pwd'));
             $this->_redirect('/');
         } else {
             $this->view->error = "Username" . $username . " or password:"******" is not right.";
         }
     }
     $this->view->form = $form;
     $this->view->title = $this->translator->_('Login');
     $this->getResponse()->insert('content', $this->render('login', null, true));
 }
Example #2
0
 public function init()
 {
     $this->setView(SP_Application::getView());
     $this->addPrefixPath('SP_Form_Decorator', 'SP/Form/Decorator/', 'decorator');
     $this->setDisableLoadDefaultDecorators(true);
     $this->setDecorators($this->formDecorators);
     $this->setElementDecorators($this->elementDecorators);
 }
Example #3
0
 /**
  * Check current role if has the right to access the $action
  * @param string $action
  * @return bool
  */
 protected function checkAcl($action)
 {
     $moudle = $this->getRequest()->getModuleName();
     $auth = Zend_Auth::getInstance();
     $acl = SP_Application::getAcl();
     if ($acl->isAllowed($auth->getStorage()->read()->role, ucfirst($moudle), $action)) {
         return true;
     }
     return false;
 }
Example #4
0
 public function init()
 {
     $this->addPrefixPath('SP_Form_Decorator', 'SP/Form/Decorator/', 'decorator');
     $this->_view = SP_Application::getView();
     $this->setName('Form_Login');
     $this->setAttrib('class', 'Form_Edit');
     $this->setMethod('post')->setAction('/user/login');
     $username = new Zend_Form_Element_Text('name');
     $username->setLabel($this->getTranslator()->translate('UserName:'******'NotEmpty', true)->setView($this->getView());
     $password = new Zend_Form_Element_Password('pwd');
     $password->setLabel($this->getTranslator()->translate('Password:'******'NotEmpty')->setView($this->getView());
     $btnLogin = new Zend_Form_Element_Submit('submit');
     $btnLogin->setLabel($this->getTranslator()->_('Login'))->setView($this->getView());
     $this->addElements(array($username, $password, $btnLogin));
     $this->clearDecorators();
     $this->setDecorators(array('FormElements', 'Form', array('OuterBox', array('attrs' => array('class' => 'form login_form'), 'title' => 'Login', 'placement' => 'PREPEND'))));
     $this->setElementDecorators(array('ViewHelper', array('data' => 'HtmlTag', array('tag' => 'div', 'class' => 'form_row')), array('Label', array('tag' => 'div', 'class' => 'form_label'))));
     $btnLogin->removeDecorator('Label');
 }
Example #5
0
 protected function _setTranslate()
 {
     self::$_translate = new Zend_Translate('gettext', SP_APP_PATH . DIRECTORY_SEPARATOR . 'locale', 'en', array('disableNotices' => true, 'scan' => Zend_Translate::LOCALE_DIRECTORY));
     //log untranslated string
     //self::$_translate->setOptions(array('log'=>self::$_log,'logUntranslated'=>true));
     self::$_translate->setCache(self::$_cache);
     Zend_Registry::getInstance()->set('Zend_Translate', self::$_translate);
 }
Example #6
0
   1. Redistributions of source code must retain the above copyright notice, this list of
      conditions and the following disclaimer.

   2. Redistributions in binary form must reproduce the above copyright notice, this list
      of conditions and the following disclaimer in the documentation and/or other materials
      provided with the distribution.

THIS SOFTWARE IS PROVIDED BY VictorLi (luckylzs@gmail.com) ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL VictorLi (luckylzs@gmail.com) OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of VictorLi (luckylzs@gmail.com).
***********************************************************************************************************/
define('SP_ENTRY', true);
define('SP_ROOT_PATH', realpath(dirname(__FILE__) . '/../'));
define('SP_APP_PATH', SP_ROOT_PATH . DIRECTORY_SEPARATOR . 'application');
define('SP_CONFIG_PATH', SP_APP_PATH . DIRECTORY_SEPARATOR . 'config');
define('SP_LIB_PATH', SP_ROOT_PATH . DIRECTORY_SEPARATOR . 'library');
define('SP_WWW_PATH', SP_ROOT_PATH . DIRECTORY_SEPARATOR . 'www');
define('SP_APP_ENV', getenv('SP_APP_ENV') ? getenv('SP_APP_ENV') : 'product');
require_once SP_LIB_PATH . DIRECTORY_SEPARATOR . 'SP' . DIRECTORY_SEPARATOR . 'Application.php';
$app = new SP_Application(SP_APP_ENV, SP_CONFIG_PATH . DIRECTORY_SEPARATOR . 'application.ini');
$app->run();