コード例 #1
0
ファイル: models.py プロジェクト: zhyq0826/linkus-django
def reset_password_apply(id,email):
	ck = random_char()
	urp = UserResetPassword(id=id,ck=ck)
	urp.save()
	urp.sendemail(email)

	return urp
コード例 #2
0
ファイル: views.py プロジェクト: zhyq0826/linkus-django
def handle_avatar(imagefile,cordinate=None):
	if imagefile:
		path=os.path.join(settings.MEDIA_ROOT,'avatar/temp')
		path_file=os.path.join(path,imagefile)

		now = datetime.now()
		t = "%d%d%d%d%d%d"%(now.year,now.month,now.day,now.hour,now.minute,now.second)

		try:
		    #open image
		    img = Image.open(path_file)
		except IOError:
		    return None


		#crop image
		crop_img= img.crop(cordinate)

		#new_name
		avatar_name=random_char(3)+t+random_char(3)
		thubnail_name = avatar_name+"thumb"+".jpg"
		avatar_name = avatar_name+".jpg"

		path = os.path.join(settings.MEDIA_ROOT,'avatar')
		path_file = os.path.join(path,avatar_name)

		#resize image 120 120
		avatar_image=crop_img.resize((160,160),Image.ANTIALIAS)
		try:
		    avatar_image.save(path_file,"jpeg",quality=100)
		except Exception, e:
		    return None


		#produce thumbnail
		thumbnail =avatar_image.resize((48,48),Image.ANTIALIAS)
		path_file = os.path.join(path,thubnail_name)

		try:
		    thumbnail.save(path_file,"jpeg",quality=100)
		except Exception, e:
		    return None
コード例 #3
0
ファイル: models.py プロジェクト: zhyq0826/linkus-django
def apply(email,password,nickname):
	email = email.lower()
	try:
		e = UserEmail.objects.get(email=email)
		if e:
			id = e.id			
	except ObjectDoesNotExist:

		#创建新的注册用户
		e = UserEmail(email=email)
		e.save()
		id = e.id

		
	else:
		pass
	finally:


		#创建用户密码
		password = hash_password(id,password)
		user_password = UserPassword(id=id,password=password)
		user_password.save()


		#生成随机key
		ck = random_char()

		try:
			apply_user = UserApply.objects.get(id=id)
		except ObjectDoesNotExist:
			apply_user = UserApply(id=id)

		finally:
			apply_user.ck = ck
			apply_user.time=datetime.now()
			apply_user.nickname = nickname
			apply_user.save()

			return apply_user