Example #1
0
 /**
  * Adds the user to the database. 
  * There are bunch of required parameters required to be passed as $params array:
  * - login: the arbitrary string which will be used as a login for the user. The checks defined in
  * {@link setLogin} method will be performed.
  * - password: user's password. The checks defined in {@link setPassword} will be performed.
  * - email: required parameter to, for example, send confirmation emails. The checks defined in 
  * {@link setEmail} method will be performed.
  *
  * Optionally, the 'state' parameter may be passed, showing the status of newly created user. 
  * If it's omitted, the "not_confirmed" or "active" state will be chosen depending on the 
  * <code>config.user.registration_confirm</code> config parameter. If the value distinguish 
  * from the described ones, make sure that this value could be held by the DB schema of the 'state' column.
  *
  * If <code>config.user.registration_confirm</code> config parameter is set to non-false value, 
  * the one time token will be added for newly created user. This could be used for example to
  * send activation email. Logic behind that should be created separately in the model/controller.
  *
  * Additionally, the profile entry for the new user will be created.
  *
  * Behavior BeforeAddNewUser is defined.
  *
  * @param array parameters for the new user as described above
  * @return User new user object
  * @throws UserException in case of errors
  */
 static function add(array $params)
 {
     if (empty($params['login']) || empty($params['password']) || empty($params['email'])) {
         throw new UserException("Login, password and email must be passed");
     }
     $config = Config::getInstance();
     if (empty($params['state'])) {
         $params['state'] = $config->user->registration_confirm ? "not_confirmed" : "active";
     }
     if (self::findBy('login', $params['login'])) {
         throw new UserException("User with the same login already exists");
     }
     $new_user = new self(null);
     $new_user->setLogin($params['login']);
     $new_user->setPassword($params['password']);
     $new_user->setState($params['state']);
     $new_user->setEmail($params['email']);
     $new_user->trigger("BeforeAddNewUser", array($new_user, &$params));
     $new_user->save();
     $one_time_token = null;
     if ($config->user->registration_confirm) {
         $one_time_token = OneTimeTokenAuth::generateAndAddToken($new_user->getId());
     }
     Profile::addUser($new_user->getId());
     return $new_user;
 }
Example #2
0
 public static function createTemporary($_hours)
 {
     $user = new self();
     $user->setLogin('temp_' . config::genKey());
     $user->setPassword(config::genKey(45));
     $user->setRights('admin', 1);
     $user->setOptions('validity_limit', date('Y-m-d H:i:s', strtotime('+' . $_hours . ' hour now')));
     $user->save();
     return $user;
 }
Example #3
0
File: User.php Project: serkin/blog
 /**
  * @param array $row
  */
 public function mapObject(array $row)
 {
     $entry = new self();
     $entry->setLogin($row['login'])->setId($row['id_user'])->setPassword($row['password']);
     return $entry;
 }