示例#1
0
def register(request):
	try:
		rp = request.POST
		(username, password, email, verify_email) = (
			rp.get('username'), rp.get('password'), rp.get('email'), rp.get('mailbox'))
		check_user(username)
		check_password(password)
		check_email(email, verify_email == 'on')
		user = UserProfile(username=username, email=email, sex_str=rp.get('sex'))
		user.set_password(password)
		default_thread, created_default = Room.objects.get_or_create(name=ANONYMOUS_REDIS_ROOM)
		registered_only, created_registered = Room.objects.get_or_create(name=REGISTERED_REDIS_ROOM)
		user.save()
		user.rooms.add(default_thread)
		user.rooms.add(registered_only)
		user.save()
		logger.info('Signed up new user %s, subscribed for channels %s', user, user.rooms)
		# You must call authenticate before you can call login
		auth_user = authenticate(username=username, password=password)
		djangologin(request, auth_user)
		# register,js redirect if message = 'Account created'
		message = settings.VALIDATION_IS_OK
		if verify_email == 'Y':
			send_email_verification(user, request.get_host())
	except ValidationError as e:
		message = e.message
	return HttpResponse(message, content_type='text/plain')
示例#2
0
	def test_send_email(self):
		up = UserProfile(username='******', email='*****@*****.**', sex_str='Mail')
		send_email_verification(up, 'Any')