/**
  * Creates and returns a new Exception instance.
  *
  * @param string $message The message itself
  * @param string $key The key for I18N
  * @return Faett_Channel_Exceptions_InvalidCredentialsException
  */
 public static function create($message, $key = '')
 {
     // create a new message
     $e = new Faett_Channel_Exceptions_InvalidCredentialsException($message);
     // set the message key
     $e->_setKey($key);
     // return the message
     return $e;
 }
 /**
  * Checks if user is already registered in the session, if
  * not a header is sent to request HTTP Basic Authentication.
  *
  * @return void
  */
 protected function _authenticate()
 {
     // load authentication flag from backend
     $this->_authentication = (bool) Mage::getStoreConfig('channel/global/authentication');
     // check if authentication is requested
     if (!$this->_authentication) {
         return Mage::getModel('api/user');
     }
     // if the user is already logged in, redirect to the requested resource
     if ($this->_getSession()->isLoggedIn()) {
         $this->_redirect('*/*/');
         return $this->_getSession()->getUser();
     }
     // load the session
     $session = $this->_getSession();
     // get the username from the request
     $username = $this->getRequest()->getServer(Faett_Channel_IndexController::PHP_AUTH_USER);
     // get the password from the request
     $password = $this->getRequest()->getServer(Faett_Channel_IndexController::PHP_AUTH_PW);
     // check if username and password is not empty
     if (!empty($username) && !empty($password)) {
         try {
             // login workflow
             return $session->login($username, $password);
         } catch (Exception $e) {
             $message = $e->getMessage();
             Mage::logException($e);
             $session->addError($message);
             $session->setUsername($username);
             // throw an exception
             throw Faett_Channel_Exceptions_InvalidCredentialsException::create('You\'ve entered invalid user credentials', '200.error.invalid-credentials');
         }
     } else {
         // throw an exception
         throw Faett_Channel_Exceptions_InvalidCredentialsException::create('Please enter your user credentials', '200.error.no-credentials');
     }
 }