コード例 #1
0
ファイル: managers.py プロジェクト: mawang82/Newsnavig
    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
コード例 #2
0
ファイル: managers.py プロジェクト: haipome/Newsnavig
	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
コード例 #3
0
ファイル: managers.py プロジェクト: mawang82/Newsnavig
    def create_anonymous(self):
        '''
		'''
        anonymous = User(id=ANONYMOUS_ID, \
                         username=ANONYMOUS_USERNAME, \
                         password=ANONYMOUS_PASSWORD) # this password will
        # never be used!
        anonymous.save()
        avatar = Avatar()
        avatar.avatar_save(MEDIA_ROOT + ANONYMOUS_USERNAME + '.jpg')

        profile = UserProfile(user=anonymous)
        profile.avatar = avatar
        profile.name = ANONYMOUS_NAME
        profile.save()

        # there while add some other thing

        return anonymous
コード例 #4
0
ファイル: managers.py プロジェクト: haipome/Newsnavig
	def create_anonymous(self):
		'''
		'''
		anonymous = User(id=ANONYMOUS_ID, \
		                 username=ANONYMOUS_USERNAME, \
		                 password=ANONYMOUS_PASSWORD) # this password will 
		                                              # never be used!
		anonymous.save()
		avatar = Avatar()
		avatar.avatar_save(MEDIA_ROOT + ANONYMOUS_USERNAME + '.jpg')
		
		profile = UserProfile(user=anonymous)
		profile.avatar=avatar
		profile.name = ANONYMOUS_NAME
		profile.save()
		
		# there while add some other thing
		
		return anonymous