def _create_user(self, login, password, **kwargs): if not password: if self._password_required(): raise CommandAbortedError("You must provide -p/--password parameter") password = '' try: user = User(email=login, password=password, **kwargs) user.update_webdav_digest_auth(password) self._session.add(user) self._session.flush() # We need to enable radicale if it not already done daemons = DaemonsManager() daemons.run('radicale', RadicaleDaemon) user_api = UserApi(user) user_api.execute_created_user_actions(user) except IntegrityError: self._session.rollback() raise AlreadyExistError() return user
def _create_user(self, login, password, **kwargs): if not password: if self._password_required(): raise CommandAbortedError( "You must provide -p/--password parameter") password = '' try: user = User(email=login, password=password, **kwargs) user.update_webdav_digest_auth(password) self._session.add(user) self._session.flush() # We need to enable radicale if it not already done daemons = DaemonsManager() daemons.run('radicale', RadicaleDaemon) user_api = UserApi(user) user_api.execute_created_user_actions(user) except IntegrityError: self._session.rollback() raise AlreadyExistError() return user
def _create_user(self, login, password, **kwargs): if not password: if self._password_required(): raise CommandAbortedError( "You must provide -p/--password parameter") password = '' try: user = User(email=login, password=password, **kwargs) self._session.add(user) self._session.flush() except IntegrityError: self._session.rollback() raise AlreadyExistError() return user
def _sync_ldap_user(self, email, environ, identity): # Create or get user for connected email if not self._user_api.user_with_email_exists(email): user = User(email=email, imported_from=LDAPAuth.name) DBSession.add(user) else: user = self._user_api.get_one_by_email(email) # Retrieve ldap user attributes self._auth.ldap_user_provider.add_metadata_for_auth(environ, identity) # Update user with ldap attributes user_ldap_values = identity.get('user').copy() for field_name in user_ldap_values: setattr(user, field_name, user_ldap_values[field_name]) DBSession.flush() transaction.commit()
def user_can_read(self, user: User) -> bool: role = user.get_role(self._related_object) return CALENDAR_PERMISSION_READ in self._workspace_rights[role]
def notify_created_account( self, user: User, password: str, ) -> None: """ Send created account email to given user. :param password: choosed password :param user: user to notify """ # TODO BS 20160712: Cyclic import from tracim.lib.notifications import EST logger.debug(self, 'user: {}'.format(user.user_id)) logger.info( self, 'Sending asynchronous email to 1 user ({0})'.format(user.email, )) async_email_sender = EmailSender( self._smtp_config, self._global_config.EMAIL_NOTIFICATION_ACTIVATED) subject = \ self._global_config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_SUBJECT \ .replace( EST.WEBSITE_TITLE, self._global_config.WEBSITE_TITLE.__str__() ) message = MIMEMultipart('alternative') message['Subject'] = subject message['From'] = formataddr(( self._global_config.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL, self._global_config.EMAIL_NOTIFICATION_FROM_EMAIL, )) message['To'] = formataddr((user.get_display_name(), user.email)) text_template_file_path = self._global_config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_TEXT # nopep8 html_template_file_path = self._global_config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML # nopep8 body_text = self._render( mako_template_filepath=text_template_file_path, context={ 'user': user, 'password': password, 'login_url': self._global_config.WEBSITE_BASE_URL, }) body_html = self._render( mako_template_filepath=html_template_file_path, context={ 'user': user, 'password': password, 'login_url': self._global_config.WEBSITE_BASE_URL, }) part1 = MIMEText(body_text, 'plain', 'utf-8') part2 = MIMEText(body_html, 'html', 'utf-8') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, # in this case the HTML message, is best and preferred. message.attach(part1) message.attach(part2) send_email_through(async_email_sender.send_mail, message)