Beispiel #1
0
 /**
  * Save the model in the database.
  *
  * @param bool Commit in the database or not. If not, the object
  *             is returned but not saved in the database.
  * @return Object Model with data set from the form.
  */
 function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     $password = Pluf_Utils::getPassword();
     $user = new Pluf_User();
     $user->setFromFormData($this->cleaned_data);
     $user->active = true;
     $user->staff = false;
     $user->administrator = false;
     $user->setPassword($password);
     $user->create();
     /**
      * [signal]
      *
      * Pluf_User::passwordUpdated
      *
      * [sender]
      *
      * IDF_Form_Admin_UserCreate
      *
      * [description]
      *
      * This signal is sent when a user is created
      * by the staff.
      *
      * [parameters]
      *
      * array('user' => $user)
      *
      */
     $params = array('user' => $user);
     Pluf_Signal::send('Pluf_User::passwordUpdated', 'IDF_Form_Admin_UserCreate', $params);
     // Create the public key as needed
     if ('' !== $this->cleaned_data['public_key']) {
         $key = new IDF_Key();
         $key->user = $user;
         $key->content = $this->cleaned_data['public_key'];
         $key->create();
     }
     // Send an email to the user with the password
     Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
     $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::login', array(), array(), false);
     $context = new Pluf_Template_Context(array('password' => Pluf_Template::markSafe($password), 'user' => $user, 'url' => Pluf_Template::markSafe($url), 'admin' => $this->request->user));
     $tmpl = new Pluf_Template('idf/gadmin/users/createuser-email.txt');
     $text_email = $tmpl->render($context);
     $email = new Pluf_Mail(Pluf::f('from_email'), $user->email, __('Your details to access your forge.'));
     $email->addTextMessage($text_email);
     $email->sendMail();
     return $user;
 }
Beispiel #2
0
 /**
  * Create 2 projects to work with and 2 users.
  */
 public function setUp()
 {
     $this->projects = array();
     $this->users = array();
     for ($i = 1; $i < 3; $i++) {
         $project = new IDF_Project();
         $project->name = 'Test project ' . $i;
         $project->shortname = 'test' . $i;
         $project->description = sprintf('This is a test project %d.', $i);
         $project->create();
         $this->projects[] = $project;
         $user = new Pluf_User();
         $user->last_name = 'user' . $i;
         $user->login = '******' . $i;
         $user->email = 'user' . $i . '@example.com';
         $user->create();
         $this->users[] = $user;
     }
 }
Beispiel #3
0
 public function testUniqueLogin()
 {
     $user = new Pluf_User();
     $user->login = '******';
     $user->first_name = 'test';
     $user->last_name = 'test';
     $user->email = '*****@*****.**';
     $user->setPassword('test');
     $user->active = true;
     // Test user already exists
     try {
         $user->create();
     } catch (Exception $e) {
         return;
     }
     $this->fail();
 }
Beispiel #4
0
 /**
  * Save the model in the database.
  *
  * @param bool Commit in the database or not. If not, the object
  *             is returned but not saved in the database.
  * @return Object Model with data set from the form.
  */
 function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     $user = new Pluf_User();
     $user->first_name = '---';
     // with both this set and
     // active==false we can find later
     // on, all the unconfirmed accounts
     // that could be purged.
     $user->last_name = $this->cleaned_data['login'];
     $user->login = $this->cleaned_data['login'];
     $user->email = $this->cleaned_data['email'];
     $user->language = $this->request->language_code;
     $user->active = false;
     $user->create();
     self::sendVerificationEmail($user);
     return $user;
 }