コード例 #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
ファイル: UsersController.php プロジェクト: kyfr59/cg35
 /**
  * Send an activation email to a new user telling them how to activate
  * their account.
  *
  * @param User $user
  * @return boolean True if the email was successfully sent, false otherwise.
  */
 protected function sendActivationEmail($user)
 {
     $ua = $this->_helper->db->getTable('UsersActivations')->findByUser($user);
     if ($ua) {
         $ua->delete();
     }
     $ua = new UsersActivations();
     $ua->user_id = $user->id;
     $ua->save();
     // send the user an email telling them about their new user account
     $siteTitle = get_option('site_title');
     $from = get_option('administrator_email');
     $body = __('Welcome!') . "\n\n" . __('Your account for the %s repository has been created. Please click the following link to activate your account:', $siteTitle) . "\n\n" . WEB_ROOT . "/admin/users/activate?u={$ua->url}\n\n" . __('%s Administrator', $siteTitle);
     $subject = __('Activate your account with the %s repository', $siteTitle);
     $mail = new Zend_Mail('UTF-8');
     $mail->setBodyText($body);
     $mail->setFrom('*****@*****.**', "Archives départementales 35");
     $mail->addTo($user->email, $user->name);
     $mail->setSubject($subject);
     $mail->addHeader('X-Mailer', 'PHP/' . phpversion());
     try {
         $mail->send();
         return true;
     } catch (Zend_Mail_Transport_Exception $e) {
         $logger = $this->getInvokeArg('bootstrap')->getResource('Logger');
         if ($logger) {
             $logger->log($e, Zend_Log::ERR);
         }
         return false;
     }
 }
コード例 #3
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;
 }
コード例 #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);
     $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;
 }
コード例 #6
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;
 }