def register(self, brl_user, email, plain_password, allow_mailing,
                 provider=None, access_token=None, invited_by=None):
        # Validate password
        if len(plain_password) < MIN_PASSWORD_LENGTH:
            logger.debug("Invalid password length for %s" % email)
            raise ControledErrorException("Password length must"
                                          " be %s characters min" % MIN_PASSWORD_LENGTH)
        # Search users with same email
        if self.store.read_user_by_email(email):
            logger.debug("Email '%s' already exists!" % email)
            raise ControledErrorException("Email '%s' already exists! Forgot password? "
                                          "Go to login and click on forgot password" % email)

        try:
            brl_user = BRLUser(brl_user)
            bii_user = User(brl_user)
            bii_user.password = plain_password
        except InvalidNameException as e:
            raise ControledErrorException(e)

        # Search invited_by user (by mail or login)
        friend = None
        if invited_by:
            if "@" in invited_by:  # email address
                friend = self.store.read_user_by_email(invited_by)
                friend = friend.ID if friend else None
            else:  # Login
                friend_object = self.store.exists_user_id_ignoring_case(invited_by)
                if friend_object and friend_object.active:
                    friend = invited_by
            if not friend:
                raise ControledErrorException("User %s doesn't exist" % invited_by)
        bii_user.invited_by = friend

        # Check the existing of user name (User.ID), with case-insensitive
        if self.store.exists_user_id_ignoring_case(brl_user):
            logger.debug("User name '%s' already exists!" % brl_user)
            raise ControledErrorException("Username '%s' already exists! "
                                          "Choose other username" % brl_user)

        try:
            bii_user.email = email
            bii_user.allow_mailing = allow_mailing

            manager = JWTConfirmEmailManagerFactory.new()
            token = manager.get_token_for(brl_user)

            bii_user.confirmation_token = token
            bii_user.joined_date = datetime.datetime.now()
            bii_user.active = False

            oauth_service = get_oauth_service(self.store)
            oauth_user_info = oauth_service.get_user_info(provider, access_token)
            self.store.create_user(bii_user)

            if oauth_user_info:
                # If user has changed the oauth email, not confirm the account
                if oauth_user_info[1] == bii_user.email:
                    bii_user.active = True
                try:
                    register_signup(self.store, brl_user)
                except Exception as exc:
                    logger.error("Can't register sign-up in background! %s" % str(exc))

                bii_user.fill_user_oauth_token(provider, access_token)
                self.store.update_user(bii_user)

            return bii_user

        except Exception as e:
            logger.error("Error creating user at mongo: %s" % str(e))
            logger.error(traceback.format_exc())
            raise e
Returns the element with focus, or BODY if nothing has focus.
dataset/ETHPy150Open biicode/bii-server/user/user_service.py/UserService.register--crossover with--dataset/ETHPy150Open apiad/sublime-browser-integration/selenium/webdriver/remote/webdriver.py/WebDriver.switch_to_active_element