def POST(cls, *args, **kwargs): new_user = User() form = request.form new_user.nickname = form.get('nickname') new_user.password_hash = generate_password_hash(form.get('password')) new_user.image_url = form.get('image_url') new_user.about = form.get('about') new_user.footer_text = form.get('footer') new_user.email = form.get('email') db.session.add(new_user) db.session.commit() return cls.GET(*args, **kwargs)
def form_valid(self, form): # Create a user, but remember to set inactive! user = User() user.username = form.cleaned_data['email'] user.email = form.cleaned_data['email'] user.is_active = False try: user.save() except IntegrityError: form.add_error('email', gettext('Shop with this email already exists.')) return super(ShopRegisterView, self).form_invalid(form) self.object = form.save(commit=False) self.object.postcode = Postcode.objects.get( postcode=form.cleaned_data['postcode_special']) self.object.user = user self.object.save() current_site = get_current_site(self.request) context = { 'shopname': self.object.name, 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user), } html_message = render_to_string('emails/account_activation.html', context) txt_message = render_to_string('emails/account_activation.txt', context) email = EmailMultiAlternatives(gettext('FOODBEE - Confirm email'), txt_message) email.from_email = settings.DEFAULT_FROM_EMAIL email.to = [self.object.email] email.attach_alternative(html_message, "text/html") email.content_subtype = 'html' email.mixed_subtype = 'related' with open('base/static/base/img/fb_logo.png', mode='rb') as f: image = MIMEImage(f.read()) image.add_header('Content-ID', "<Foodbee_logo_long.png>") email.attach(image) email.send() return super().form_valid(form)