def deco(*a, **b): """ Decorator for public method""" if hasattr(cherrypy, basecontroller.KEY_SESSION): user = basecontroller.get_logged_user() if (user is not None and user.is_administrator()) or SettingsService.is_first_run(): return func(*a, **b) basecontroller.set_error_message('Only Administrators can access this application area!') raise cherrypy.HTTPRedirect('/tvb')
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 ' + cfg.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 != cfg.DEFAULT_ADMIN_EMAIL or cfg.SERVER_IP != cfg.LOCALHOST): # Do not send validation email in case default admin email # remained unchanged but TVB in locally deployed.... 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 not SettingsService.is_first_run(): 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(excep.message)
from tvb.interfaces.web.controllers.flow_controller import FlowController from tvb.interfaces.web.controllers.settings_controller import SettingsController from tvb.interfaces.web.controllers.burst.burst_controller import BurstController from tvb.interfaces.web.controllers.burst.exploration_controller import ParameterExplorationController from tvb.interfaces.web.controllers.spatial.base_spatio_temporal_controller import SpatioTemporalController from tvb.interfaces.web.controllers.spatial.region_model_parameters_controller import RegionsModelParametersController from tvb.interfaces.web.controllers.spatial.surface_model_parameters_controller import SurfaceModelParametersController from tvb.interfaces.web.controllers.spatial.region_stimulus_controller import RegionStimulusController from tvb.interfaces.web.controllers.spatial.surface_stimulus_controller import SurfaceStimulusController from tvb.interfaces.web.controllers.spatial.local_connectivity_controller import LocalConnectivityController from tvb.interfaces.web.controllers.spatial.noise_configuration_controller import NoiseConfigurationController from tvb.interfaces.web.controllers.api.simulator_controller import SimulatorController LOGGER = get_logger('tvb.interface.web.run') CONFIG_EXISTS = not SettingsService.is_first_run() PARAM_RESET_DB = "reset" ### Ensure Python is using UTF-8 encoding. ### While running distribution/console, default encoding is ASCII reload(sys) sys.setdefaultencoding('utf-8') LOGGER.info("TVB application running using encoding: " + sys.getdefaultencoding()) def init_cherrypy(arguments=None): #### Mount static folders from modules marked for introspection arguments = arguments or [] CONFIGUER = TVBSettings.CHERRYPY_CONFIGURATION for module in arguments:
def deco(*a, **b): """ Decorator for public method""" if not SettingsService.is_first_run(): return func(*a, **b) raise cherrypy.HTTPRedirect('/settings/settings')