コード例 #1
0
 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);
     }
 }
コード例 #2
0
 private function _contributorsToGuestUsers($contributorsData)
 {
     $map = array();
     foreach ($contributorsData as $index => $contributor) {
         $user = new User();
         $user->email = $contributor['email'];
         $user->name = $contributor['name'];
         //make sure username is 6 chars long and unique
         //base it on the email to lessen character restriction problems
         $explodedEmail = explode('@', $user->email);
         $username = $explodedEmail[0];
         $username = str_replace('.', '', $username);
         $user->username = $username;
         $user->active = true;
         $user->role = 'guest';
         $user->setPassword($user->email);
         $user->save();
         $map[$contributor['id']] = $user->id;
         $activation = UsersActivations::factory($user);
         $activation->save();
         release_object($user);
         release_object($activation);
     }
     return $map;
 }
コード例 #3
0
 protected function _createNewGuestUser($post)
 {
     $user = new User();
     $email = $post['contribution_simple_email'];
     $split = explode('@', $email);
     $name = $split[0];
     if (version_compare(OMEKA_VERSION, '2.2-dev', '<')) {
         $username = str_replace('@', 'AT', $email);
         $username = str_replace('.', 'DOT', $username);
         $user->username = $username;
     } else {
         $user->username = $email;
     }
     $user->email = $email;
     $user->name = $name;
     $user->role = 'guest';
     $user->active = 1;
     try {
         $user->save();
         //activate user so they can retrieve password without admin needing to activate first
         $activation = UsersActivations::factory($user);
         $activation->save();
     } catch (Exception $e) {
         _log($e);
     }
     return $user;
 }
コード例 #4
0
ファイル: UserController.php プロジェクト: kyfr59/cg35
 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);
     }
 }
コード例 #5
0
 protected function _createNewGuestUser($post)
 {
     $user = new User();
     $email = $post['contribution_simple_email'];
     $split = explode('@', $email);
     if (array_key_exists('contribution_form_name_mandatory', $post)) {
         $name = $post['contribution_form_name_mandatory'];
     } else {
         $name = $split[0];
     }
     //this is a good approximation of a unique username, allowing users with the same first name to still be added
     $user->username = $email;
     $user->email = $email;
     $user->name = preg_replace('/\\s+/', ' ', trim($name));
     $user->role = 'guest';
     $user->active = 1;
     try {
         $user->save();
         //activate user so they can retrieve password without admin needing to activate first
         $activation = UsersActivations::factory($user);
         $activation->save();
     } catch (Exception $e) {
         _log($e);
     }
     return $user;
 }