Beispiel #1
0
    def create_user(self, username, email, password):
        '''
		'''
        try:
            user = User.objects.filter(username__iexact=username)
        except:
            user = None
        if user:
            return False

        try:
            user = User.objects.filter(email__iexact=email)
        except:
            user = None
        if user:
            return False

        try:
            user = UserProfile.objects.filter(email_unconfirmed__iexact=email)
        except:
            user = None
        if user:
            return False

        try:
            new_user = User.objects.create_user(username=username,
                                                password=password)
            new_user.is_active = False
            new_user.save()
        except:
            return False

        confirm_key = generate_sha1()
        account = self.create(user=new_user, \
                  confirm_key=confirm_key, \
                  confirm_key_creat_time = now(), \
                  email_unconfirmed = email, \
                  last_active = now())
        account.send_confirm_email()

        profile = UserProfile(user=new_user)
        try:
            anonymous = User.objects.get(pk=ANONYMOUS_ID)
        except:
            anonymous = self.create_anonymous()
        profile.avatar = anonymous.userprofile.avatar
        profile.username = username
        profile.save()

        # print 'send create_user_done signal'
        # create_user_done.send(sender='UserAccount', user=new_user)
        filename = get_gravatar(account.email_unconfirmed)
        if filename:
            avatar = Avatar()
            avatar.avatar_save(filename)
            remove(filename)
            profile.avatar = avatar
            profile.save()

        return new_user
Beispiel #2
0
	def create_user(self, username, email, password):
		'''
		'''
		try:
			user = User.objects.filter(username__iexact=username)
		except:
			user = None
		if user:
			return False
			
		try:
			user = User.objects.filter(email__iexact=email)
		except:
			user = None
		if user:
			return False
		
		try:
			user = UserProfile.objects.filter(email_unconfirmed__iexact = email)
		except:
			user = None
		if user:
			return False
		
		try:
			new_user = User.objects.create_user(username=username, password=password)
			new_user.is_active = False
			new_user.save()
		except:
			return False
		
		confirm_key = generate_sha1()
		account = self.create(user=new_user, \
		          confirm_key=confirm_key, \
		          confirm_key_creat_time = now(), \
		          email_unconfirmed = email, \
		          last_active = now())
		account.send_confirm_email()
		
		profile = UserProfile(user=new_user)
		try:
			anonymous = User.objects.get(pk=ANONYMOUS_ID)
		except:
			anonymous = self.create_anonymous()
		profile.avatar = anonymous.userprofile.avatar
		profile.username = username
		profile.save()
		
		# print 'send create_user_done signal'
		# create_user_done.send(sender='UserAccount', user=new_user)
		filename = get_gravatar(account.email_unconfirmed)
		if filename:
			avatar = Avatar()
			avatar.avatar_save(filename)
			remove(filename)
			profile.avatar = avatar
			profile.save()
		
		return new_user
Beispiel #3
0
def create_column(obj):
    '''
	'''
    c = Column(content_object=obj)

    key = ''
    while True:
        key = generate_sha1()[:20]
        if not Column.objects.filter(secret_id=key).count():
            break

    c.secret_id = key

    c.save()
Beispiel #4
0
def create_column(obj):
	'''
	'''
	c = Column(content_object=obj)
	
	key = ''
	while True:
		key = generate_sha1()[:20]
		if not Column.objects.filter(secret_id=key).count():
			break
	
	c.secret_id = key
	
	c.save()
Beispiel #5
0
    def change_email(self, email):
        '''
		'''
        if UserAccount.objects.is_email_regist(email):
            return False

        self.email_unconfirmed = email
        self.confirm_key = generate_sha1()
        self.confirm_key_creat_time = now()
        self.is_confirm_key_send = False
        self.save()

        self.send_confirm_email()

        return True
Beispiel #6
0
	def change_email(self, email):
		'''
		'''
		if UserAccount.objects.is_email_regist(email):
			return False
		
		self.email_unconfirmed = email
		self.confirm_key = generate_sha1()
		self.confirm_key_creat_time = now()
		self.is_confirm_key_send = False
		self.save()
		
		self.send_confirm_email()
		
		return True
Beispiel #7
0
	def avatar_save(self, upload):
		while True:
			if self.is_img_exist:
				self.avatar_delete()
			# change the url to reload the cache in user browser
			# if self.path_prefix:
			# 	break
			sha_hash = generate_sha1()
			test_prefix = r"%s/%s/%s" % \
			              (sha_hash[0:2], sha_hash[2:4], sha_hash[4:15], )
			test_path = r"%s/%s_%s.jpg" % (AVATARS_DIR, test_prefix, \
			                               str(AVATAR_LARGE_NAME))
			if test_path == storage.get_available_name(test_path):
				self.path_prefix = test_prefix
				self.is_img_exist = True
				break
		self._avatar_save(upload, 'origin')
		self._avatar_save(upload, 'large')
		self._avatar_save(upload, 'medium')
		self._avatar_save(upload, 'small')
		self.is_img_exist = True
		
		self.save()