Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomUser(AbstractBaseUser, PermissionsMixin):
- first_name = models.CharField(max_length=254, blank=True)
- second_name = models.CharField(max_length=254, blank=True)
- email = models.EmailField(blank=True, unique=True)
- avatar = models.ImageField('profile picture', upload_to='images/avatars/', null=True, blank=True)
- USERNAME_FIELD = 'email'
- REQUIRED_FIELDS = ['first_name', 'second_name']
- objects = CustomUserManager()
- class Meta:
- verbose_name = _('user')
- verbose_name_plural = _('users')
- def save(self, *args, **kwargs):
- pil_image_obj = Image.open(self.avatar)
- new_image = resizeimage.resize_width(pil_image_obj, 250)
- new_image_io = BytesIO()
- new_image.save(new_image_io, format='JPEG')
- temp_name = self.avatar.name
- self.avatar.delete(save=False)
- self.avatar.save(
- temp_name,
- content=ContentFile(new_image_io.getvalue()),
- save=False
- )
- super(CustomUser, self).save(*args, **kwargs)
- def login(request):
- if request.method == 'POST':
- login_form = CustomLoginForm(request.POST)
- email = request.POST.get('email')
- password = request.POST.get('password1')
- user = authenticate(email=email, password=password)
- if user is not None:
- if user.is_active:
- auth_login(request, user)
- print "loggato"
- return HttpResponseRedirect('/')
- else:
- return HttpResponse("Your Pin a Voyage account is disabled.")
- else:
- print "Invalid login details: {0}, {1}".format(email, password)
- return HttpResponse("Invalid login details supplied. Get back to the <a href="/">homepage</a>.")
- else:
- login_form = CustomLoginForm()
- return render(request, 'blog/post_list.html', {})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement