Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. class CustomUser(AbstractBaseUser, PermissionsMixin):
  2. first_name = models.CharField(max_length=254, blank=True)
  3. second_name = models.CharField(max_length=254, blank=True)
  4. email = models.EmailField(blank=True, unique=True)
  5. avatar = models.ImageField('profile picture', upload_to='images/avatars/', null=True, blank=True)
  6.  
  7. USERNAME_FIELD = 'email'
  8. REQUIRED_FIELDS = ['first_name', 'second_name']
  9.  
  10. objects = CustomUserManager()
  11.  
  12. class Meta:
  13. verbose_name = _('user')
  14. verbose_name_plural = _('users')
  15.  
  16. def save(self, *args, **kwargs):
  17. pil_image_obj = Image.open(self.avatar)
  18. new_image = resizeimage.resize_width(pil_image_obj, 250)
  19.  
  20. new_image_io = BytesIO()
  21. new_image.save(new_image_io, format='JPEG')
  22.  
  23. temp_name = self.avatar.name
  24. self.avatar.delete(save=False)
  25.  
  26. self.avatar.save(
  27. temp_name,
  28. content=ContentFile(new_image_io.getvalue()),
  29. save=False
  30. )
  31.  
  32. super(CustomUser, self).save(*args, **kwargs)
  33.  
  34. def login(request):
  35. if request.method == 'POST':
  36. login_form = CustomLoginForm(request.POST)
  37.  
  38. email = request.POST.get('email')
  39. password = request.POST.get('password1')
  40.  
  41. user = authenticate(email=email, password=password)
  42.  
  43. if user is not None:
  44. if user.is_active:
  45. auth_login(request, user)
  46. print "loggato"
  47. return HttpResponseRedirect('/')
  48. else:
  49. return HttpResponse("Your Pin a Voyage account is disabled.")
  50. else:
  51. print "Invalid login details: {0}, {1}".format(email, password)
  52. return HttpResponse("Invalid login details supplied. Get back to the <a href="/">homepage</a>.")
  53. else:
  54. login_form = CustomLoginForm()
  55.  
  56. return render(request, 'blog/post_list.html', {})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement