public function registerAction()
 {
     if (current_user()) {
         $this->redirect($_SERVER['HTTP_REFERER']);
     }
     $openRegistration = get_option('guest_user_open') == 1;
     $instantAccess = get_option('guest_user_instant_access') == 1;
     $user = new User();
     $form = $this->_getForm(array('user' => $user));
     $this->view->form = $form;
     if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
         return;
     }
     $user->role = 'guest';
     if ($openRegistration || $instantAccess) {
         $user->active = true;
     }
     $user->setPassword($_POST['new_password']);
     $user->setPostData($_POST);
     try {
         if ($user->save()) {
             $token = $this->_createToken($user);
             $this->_sendConfirmationEmail($user, $token);
             //confirms that they registration request is legit
             if ($instantAccess) {
                 //log them right in, and return them to the previous page
                 $authAdapter = new Omeka_Auth_Adapter_UserTable($this->_helper->db->getDb());
                 $authAdapter->setIdentity($user->username)->setCredential($_POST['new_password']);
                 $authResult = $this->_auth->authenticate($authAdapter);
                 if (!$authResult->isValid()) {
                     if ($log = $this->_getLog()) {
                         $ip = $this->getRequest()->getClientIp();
                         $log->info(__("Failed login attempt from %s", $ip));
                     }
                     $this->_helper->flashMessenger($this->getLoginErrorMessages($authResult), 'error');
                     return;
                 }
                 $activation = UsersActivations::factory($user);
                 $activation->save();
                 $this->_helper->flashMessenger(__("You are logged in temporarily. Please check your email for a confirmation message. Once you have confirmed your request, you can log in without time limits."));
                 $session = new Zend_Session_Namespace();
                 if ($session->redirect) {
                     $this->_helper->redirector->gotoUrl($session->redirect);
                 }
                 return;
             }
             if ($openRegistration) {
                 $message = __("Thank you for registering. Please check your email for a confirmation message. Once you have confirmed your request, you will be able to log in.");
                 $this->_helper->flashMessenger($message, 'success');
                 $activation = UsersActivations::factory($user);
                 $activation->save();
             } else {
                 $message = __("Thank you for registering. Please check your email for a confirmation message. Once you have confirmed your request and an administrator activates your account, you will be able to log in.");
                 $this->_helper->flashMessenger($message, 'success');
             }
         }
     } catch (Omeka_Validator_Exception $e) {
         $this->flashValidationErrors($e);
     }
 }
Beispiel #2
0
 public function loginAction()
 {
     if (!is_admin_theme()) {
         $referer = rtrim($_SERVER['HTTP_REFERER'], '/');
         $master = rtrim(MASTER_URL, '/');
         $login = $master . '/users/login';
         if (isset($_SERVER['HTTP_REFERER']) && is_integer(strpos($referer, $master)) && $referer != $master && $referer != $login && !strpos($referer, '/users/activate')) {
             $session = new Zend_Session_Namespace();
             $session->redirect = $_SERVER['HTTP_REFERER'];
         }
     }
     // require_once is necessary because lacking form autoloading.
     require_once APP_DIR . '/forms/Login.php';
     $loginForm = new Omeka_Form_Login();
     $loginForm = apply_filters('login_form', $loginForm);
     $this->view->form = $loginForm;
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if ($loginForm instanceof Zend_Form && !$loginForm->isValid($_POST)) {
         return;
     }
     User::upgradeHashedPassword($loginForm->getValue('username'), $loginForm->getValue('password'));
     $authAdapter = new Omeka_Auth_Adapter_UserTable($this->_helper->db->getDb());
     $pluginBroker = $this->getInvokeArg('bootstrap')->getResource('Pluginbroker');
     // If there are no plugins filtering the login adapter, set the
     // credentials for the default adapter.
     if (!$pluginBroker || !$pluginBroker->getFilters('login_adapter')) {
         $authAdapter->setIdentity($loginForm->getValue('username'))->setCredential($loginForm->getValue('password'));
     } else {
         $authAdapter = apply_filters('login_adapter', $authAdapter, array('login_form' => $loginForm));
     }
     $authResult = $this->_auth->authenticate($authAdapter);
     if (!$authResult->isValid()) {
         if ($log = $this->_getLog()) {
             $ip = $this->getRequest()->getClientIp();
             $log->info("Failed login attempt from '{$ip}'.");
         }
         $this->_helper->flashMessenger($this->getLoginErrorMessages($authResult), 'error');
         return;
     }
     if ($loginForm && $loginForm->getValue('remember')) {
         // Remember that a user is logged in for the default amount of
         // time (2 weeks).
         Zend_Session::rememberMe();
     } else {
         // If a user doesn't want to be remembered, expire the cookie as
         // soon as the browser is terminated.
         Zend_Session::forgetMe();
     }
     $session = new Zend_Session_Namespace();
     if ($session->redirect) {
         $this->_helper->redirector->gotoUrl($session->redirect);
     } else {
         $this->_helper->redirector->gotoUrl('/');
     }
 }
Beispiel #3
0
 public function registerAction()
 {
     $ariane['créer mon espace'] = null;
     $this->view->ariane = $ariane;
     if (current_user()) {
         $this->redirect($_SERVER['HTTP_REFERER']);
     }
     $openRegistration = get_option('guest_user_open') == 1;
     $instantAccess = get_option('guest_user_instant_access') == 1;
     $user = new User();
     $form = $this->_getForm(array('user' => $user));
     $this->view->form = $form;
     if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
         return;
     }
     $user->role = 'guest';
     if ($openRegistration || $instantAccess) {
         $user->active = true;
     }
     $user->setPassword($_POST['new_password']);
     $user->setPostData($_POST);
     if (!$user->usernameIsUnique($_POST['username'])) {
         $this->_helper->flashMessenger(__("Ce nom d'utilisateur existe déjà"), 'error');
         return;
     }
     try {
         if ($user->save()) {
             $token = $this->_createToken($user);
             $this->_sendConfirmationEmail($user, $token);
             //confirms that they registration request is legit
             if ($instantAccess) {
                 //log them right in, and return them to the previous page
                 $authAdapter = new Omeka_Auth_Adapter_UserTable($this->_helper->db->getDb());
                 $authAdapter->setIdentity($user->username)->setCredential($_POST['new_password']);
                 $authResult = $this->_auth->authenticate($authAdapter);
                 if (!$authResult->isValid()) {
                     if ($log = $this->_getLog()) {
                         $ip = $this->getRequest()->getClientIp();
                         $log->info(__("Failed login attempt from %s", $ip));
                     }
                     $this->_helper->flashMessenger($this->getLoginErrorMessages($authResult), 'error');
                     return;
                 }
                 $activation = UsersActivations::factory($user);
                 $activation->save();
                 $this->_helper->flashMessenger(__("Vous êtes identifiés temporairement. Merci de consulter vos e-mails et de confirmer votre inscription."));
                 $session = new Zend_Session_Namespace();
                 if ($session->redirect) {
                     $this->_helper->redirector->gotoUrl($session->redirect);
                 }
                 return;
             }
             if ($openRegistration) {
                 $message = __("Merci pour votre inscription. Un lien de validation vous a été envoyé par e-mail. Votre inscription sera effective après validation.");
                 $this->_helper->flashMessenger($message, 'success');
                 $activation = UsersActivations::factory($user);
                 $activation->save();
             } else {
                 $message = __("Merci pour votre inscription. Un lien de validation vous a été envoyé par e-mail. Votre inscription sera effective après validation.");
                 $this->_helper->flashMessenger($message, 'success');
             }
         }
     } catch (Omeka_Validator_Exception $e) {
         $this->flashValidationErrors($e);
     }
 }