Example #1
0
    def create_user(self,
                    username=None,
                    password=None,
                    password2=None,
                    role=None,
                    email=None,
                    comment=None,
                    email_msg=None,
                    validated=False):
        """
        Service Layer for creating a new user.
        """
        #Basic fields validation.
        if (username is None) or len(username) < 1:
            raise UsernameException("Empty UserName!")
        if (password is None) or len(password) < 1:
            raise UsernameException("Empty password!")
        if password2 is None:
            password2 = password
        if password != password2:
            raise UsernameException("Passwords do not match!")
        try:
            user_validated = (role == 'ADMINISTRATOR') or validated
            user = model.User(username, password, email, user_validated, role)
            if email_msg is None:
                email_msg = 'Hello ' + username + TEXT_CREATE
            admin_msg = (TEXT_CREATE_TO_ADMIN + username + ' :\n ' +
                         TvbProfile.current.web.BASE_URL + 'user/validate/' +
                         username + '\n\n"' + str(comment) + '"')
            self.logger.info("Registering user " + username + " !")
            if role != 'ADMINISTRATOR' and email is not None:
                admins = UserService.get_administrators()
                admin = admins[randint(0, len(admins) - 1)]
                if admin.email is not None and (
                        admin.email !=
                        TvbProfile.current.web.admin.DEFAULT_ADMIN_EMAIL):
                    # Do not send validation email in case default admin email remained unchanged
                    email_sender.send(FROM_ADDRESS, admin.email,
                                      SUBJECT_REGISTER, admin_msg)
                    self.logger.debug("Email sent to:" + admin.email +
                                      " for validating user:"******" !")
                email_sender.send(FROM_ADDRESS, email, SUBJECT_REGISTER,
                                  email_msg)
                self.logger.debug("Email sent to:" + email +
                                  " for notifying new user:"******" !")
            user = dao.store_entity(user)

            if role == model.ROLE_ADMINISTRATOR:
                handle_event(
                    ".".join([self.__class__.__name__, "create_admin"]), user)
            else:
                handle_event(
                    ".".join([self.__class__.__name__,
                              stack()[0][3]]), user)
            return TEXT_DISPLAY
        except Exception, excep:
            self.logger.error("Could not create user!")
            self.logger.exception(excep)
            raise UsernameException(str(excep))
Example #2
0
def update():
    """
    Try to import Default_Project, so that new users created with the latest code can share this project.
    """

    try:
        admins = dao.get_administrators()
        handle_event(EVENT_FILE_IDENTIFIER, admins[0])
    except Exception:
        LOGGER.exception("Could import DefaultProject!")
def update():
    """
    Try to import Default_Project, so that new users created with the latest code can share this project.
    """

    try:
        admins = dao.get_administrators()
        handle_event(EVENT_FILE_IDENTIFIER, admins[0])
    except Exception:
        LOGGER.exception("Could import DefaultProject!")
Example #4
0
def update():
    """
    Update TVB code to SVN revision version 4770.
    This update was done for release 1.0.5
    """
    projects_count = dao.get_all_projects(is_count=True)
    
    for page_start in range(0, projects_count, PAGE_SIZE):
        projects_page = dao.get_all_projects(page_start=page_start, page_size=PAGE_SIZE)
        
        for project in projects_page:
            try:
                handle_event(EVENT_FILE_IDENTIFIER, dao.get_system_user(), project)
            except Exception, excep:
                LOGGER.exception(excep)
def update():
    """
    Update TVB code to SVN revision version 6093.
    This update was done for release 1.1.5.
    """
    projects_count = dao.get_all_projects(is_count=True)
    
    for page_start in range(0, projects_count, PAGE_SIZE):
        projects_page = dao.get_all_projects(page_start=page_start, page_size=PAGE_SIZE)
        
        for project in projects_page:
            try:
                handle_event(EVENT_FILE_IDENTIFIER, dao.get_system_user(), project)
            except Exception:
                LOGGER.exception("could not migrate project id: %s, name %s" % (project.id, project.name))
Example #6
0
    def create_user(self, username=None, password=None, password2=None,
                    role=None, email=None, comment=None, email_msg=None, validated=False):
        """
        Service Layer for creating a new user.
        """
        #Basic fields validation.
        if (username is None) or len(username) < 1:
            raise UsernameException("Empty UserName!")
        if (password is None) or len(password) < 1:
            raise UsernameException("Empty password!")
        if password2 is None:
            password2 = password
        if password != password2:
            raise UsernameException("Passwords do not match!")
        try:
            user_validated = (role == 'ADMINISTRATOR') or validated
            user = model.User(username, password, email, user_validated, role)
            if email_msg is None:
                email_msg = 'Hello ' + username + TEXT_CREATE
            admin_msg = (TEXT_CREATE_TO_ADMIN + username + ' :\n ' + TvbProfile.current.web.BASE_URL +
                         'user/validate/' + username + '\n\n"' + str(comment) + '"')
            self.logger.info("Registering user " + username + " !")
            if role != 'ADMINISTRATOR' and email is not None:
                admins = UserService.get_administrators()
                admin = admins[randint(0, len(admins) - 1)]
                if admin.email is not None and (admin.email != TvbProfile.current.web.admin.DEFAULT_ADMIN_EMAIL):
                    # Do not send validation email in case default admin email remained unchanged
                    email_sender.send(FROM_ADDRESS, admin.email, SUBJECT_REGISTER, admin_msg)
                    self.logger.debug("Email sent to:" + admin.email + " for validating user:"******" !")
                email_sender.send(FROM_ADDRESS, email, SUBJECT_REGISTER, email_msg)
                self.logger.debug("Email sent to:" + email + " for notifying new user:"******" !")
            user = dao.store_entity(user)

            if role == model.ROLE_ADMINISTRATOR:
                handle_event(".".join([self.__class__.__name__, "create_admin"]), user)
            else:
                handle_event(".".join([self.__class__.__name__, stack()[0][3]]), user)
            return TEXT_DISPLAY
        except Exception, excep:
            self.logger.error("Could not create user!")
            self.logger.exception(excep)
            raise UsernameException(str(excep))