public function add($data = [])
	{
		if (isset($data['email']) && isset($data['password'])) {
			if ((isset($data['username']) && $data['username'] === '')
				or !$this->useUsernames
			){
				$data['username'] = $data['email'];
			}

			if (!Validators::isEmail($data['email'])){
				throw new \InvalidArgumentException('Bad email address format');
			}
			if (!Validators::is($data['password'], 'string:6..')){
				throw new \InvalidArgumentException('Too short password');
			}

			$create = [
				'email' => $data['email'],
				'username' => self::clearUsername($data['username']),
				'password' => Passwords::hash($data['password']),
			];

		} else {
			throw new \InvalidArgumentException('We need email and password');
		}

		if (isset($data['role'])) {
			$create['role'] = $data['role'];
		} else {
			$create['role'] = 'user';
		}

		if (isset($data['name'])) {
			$create['name'] = $data['name'];
		}

		if ($this->isImage() && isset($data['avatar_namespace']) && isset($data['avatar_filename'])) {
			$create['avatar_namespace'] = $data['avatar_namespace'];
			$create['avatar_filename'] = $data['avatar_filename'];
		}

		$person = $this->repository->insert($create);

		return $person;
	}
public function add($data = [])
	{
		if (isset($data['email']) && isset($data['password'])) {
			if ((isset($data['username']) && $data['username'] === '')
				or !$this->useUsernames
			){
				$data['username'] = $data['email'];
			}

			if (!Validators::isEmail($data['email'])){
				throw new \InvalidArgumentException('Bad email address format');
			}
			if (!Validators::is($data['password'], 'string:6..')){
				throw new \InvalidArgumentException('Too short password');
			}

			$create = [
				'email' => $data['email'],
				'username' => self::clearUsername($data['username']),
				'password' => Passwords::hash($data['password']),
			];

		} else {
			throw new \InvalidArgumentException('We need email and password');
		}

		if (isset($data['role'])) {
			$create['role'] = $data['role'];
		} else {
			$create['role'] = 'user';
		}

		if (isset($data['name'])) {
			$create['name'] = $data['name'];
		}

		if ($this->isImage() && isset($data['avatar_namespace']) && isset($data['avatar_filename'])) {
			$create['avatar_namespace'] = $data['avatar_namespace'];
			$create['avatar_filename'] = $data['avatar_filename'];
		}

		$person = $this->repository->insert($create);

		return $person;
	}
public function add ( $ data = [ ] ) { if ( isset ( $ data [ 'email' ] ) && isset ( $ data [ 'password' ] ) ) { if ( ( isset ( $ data [ 'username' ] ) && $ data [ 'username' ] === '' ) or ! $ this -> useUsernames ) { $ data [ 'username' ] = $ data [ 'email' ] ; } if ( ! Validators :: isEmail ( $ data [ 'email' ] ) ) { throw new \ InvalidArgumentException ( 'Bad email address format' ) ; } if ( ! Validators :: is ( $ data [ 'password' ] , 'string:6..' ) ) { throw new \ InvalidArgumentException ( 'Too short password' ) ; } $ create = [ 'email' => $ data [ 'email' ] , 'username' => self :: clearUsername ( $ data [ 'username' ] ) , 'password' => Passwords :: hash ( $ data [ 'password' ] ) , ] ; } else { throw new \ InvalidArgumentException ( 'We need email and password' ) ; } if ( isset ( $ data [ 'role' ] ) ) { $ create [ 'role' ] = $ data [ 'role' ] ; } else { $ create [ 'role' ] = 'user' ; } if ( isset ( $ data [ 'name' ] ) ) { $ create [ 'name' ] = $ data [ 'name' ] ; } if ( $ this -> isImage ( ) && isset ( $ data [ 'avatar_namespace' ] ) && isset ( $ data [ 'avatar_filename' ] ) ) { $ create [ 'avatar_namespace' ] = $ data [ 'avatar_namespace' ] ; $ create [ 'avatar_filename' ] = $ data [ 'avatar_filename' ] ; } $ person = $ this -> repository -> insert ( $ create ) ; return $ person ; }
Inserts new user

@param array|\Nette\ArrayHash $data

@return \Nette\Database\Table\ActiveRow
@throws \Aprila\DuplicateEntryException
Inserts new user