def __init__(self, **kwargs): super(User, self).__init__(**kwargs) if self.role is None: admin_emails = get_config_var('ADMIN_EMAIL').split( ' ') if get_config_var('ADMIN_EMAIL') is not None else [] if len(admin_emails) > 0 and self.email in admin_emails: self.role = Role.query.filter_by(name='Admin').first() else: default_role = Role.query.filter_by(is_default=True).first() self.role = default_role if self.account == None: self.account = Account()
def post(self, folder_name, generate_flag): current_user_id = get_current_user_id() current_user = db_user_service.get_user_by_id(current_user_id) uploaded_urls = [] if current_user: for key in request.files: uploaded_file = request.files.get(key) bucket_name = get_config_var('AWS_BUCKET_NAME') upload_result = aws_s3_service.upload_file( uploaded_file, bucket_name, folder_name, generate_flag) if upload_result.get('result') == True: # Use this code to screen the actual address # public_file_url = '/pic/{0}/{1}'.format(folder_name, upload_result.get('file_name')) uploaded_urls.append(upload_result.get('file_url')) else: return jsonify({ 'result': False, 'error': 'Could not upload files...' }) return jsonify({ 'result': True, 'file_urls': uploaded_urls #'file_name': upload_result.get('file_name') }) return jsonify({'result': False, 'error': 'Cannot find user.'})
def send_confirmation_email(user, token): confirmation_link = url_for('auth.all_auth_requests', path='confirm/{0}/{1}'.format(token, user.id), _external=True) text_body = render_template( '/modules/auth/email_templates/confirmation_template.txt', user_name=user.username, company_name=get_config_var('COMPANY_NAME'), confirmation_link=confirmation_link) html_body = render_template( '/modules/auth/email_templates/confirmation_template.html', user_name=user.username, company_name=get_config_var('COMPANY_NAME'), confirmation_link=confirmation_link) email_service.send_email( user.email, get_config_var('COMPANY_NAME') + ': Confirm your registration', text_body, html_body, get_config_var('COMPANY_NAME'), get_config_var('MAIL_DEFAULT_SENDER'))
def confirm(self, token): s = Serializer(get_config_var('SECRET_KEY')) try: data = s.loads(token.encode('utf-8')) except: return False if data.get('confirm') != self.id.__str__(): return False self.confirmed = True return True
def __init__(self, **kwargs): super(User, self).__init__(**kwargs) if self.role is None: if self.email == get_config_var('ADMIN_EMAIL'): self.role = Role.query.filter_by(name='Admin').first() else: default_role = Role.query.filter_by(is_default=True).first() self.role = default_role if self.account == None: self.account = Account()
def send_verification_email(user, token, action, template_name, subject): confirmation_link = url_for('auth.all_auth_requests', path='{0}/{1}/{2}'.format( action, token, user.id), _external=True) text_body = render_template( '/modules/auth/email_templates/{0}.txt'.format(template_name), user_name=user.username, company_name=get_config_var('COMPANY_NAME'), confirmation_link=confirmation_link) html_body = render_template( '/modules/auth/email_templates/{0}.html'.format(template_name), user_name=user.username, company_name=get_config_var('COMPANY_NAME'), confirmation_link=confirmation_link) email_service.send_email( user.email, '{0}: {1}'.format(get_config_var('COMPANY_NAME'), subject), text_body, html_body, get_config_var('COMPANY_NAME'), get_config_var('MAIL_DEFAULT_SENDER'))
def delete(self, folder_name): current_user_id = get_current_user_id() current_user = db_user_service.get_user_by_id(current_user_id) bucket_name = get_config_var('AWS_BUCKET_NAME') if current_user: # Add additional checking preventing abuse deletion delete_result = aws_s3_service.delete_file( bucket_name, folder_name, uploader_api.payload.get('url')) return jsonify({ 'result': delete_result.get('result'), 'error': delete_result.get('error') }) return jsonify({'result': False, 'error': 'Cannot find user.'})
def generate_confirmation_token(self, expiration=3600): s = Serializer(get_config_var('SECRET_KEY'), expiration) return s.dumps({'confirm': self.id.__str__()}).decode('utf-8')