示例#1
0
文件: user.py 项目: danwinkler/dtext
def resend_email( mongodb ):
	user = helper.get_user( mongodb )
	email = request.query.get( 'email' )
	if not user or not email:
		redirect( "/" )
		
	if user:
		helper.send_verification_email( mongodb, user['name'], email )
		
	return redirect( "/profile" )
示例#2
0
文件: user.py 项目: danwinkler/dtext
def addemail( mongodb ):
	user = helper.get_user( mongodb )
	email = request.forms.get( 'email' )
	if not user:
		redirect( "/" )
	
	for uemail in user.get( 'emails', [] ):
		if uemail['address'] == email:
			redirect( "/profile" )
	
	helper.add_email( mongodb, user['name'], email )
	
	helper.send_verification_email( mongodb, user['name'], email )
	
	redirect( "/profile" )
示例#3
0
文件: user.py 项目: danwinkler/dtext
def post_signup( mongodb ):
	if helper.get_user( mongodb ):
		redirect( "/" )
	username = request.forms.get('username')
	password1 = request.forms.get('password1')
	password2 = request.forms.get('password2')
	email = request.forms.get('email')

	errors = []

	if len( username ) == 0:
		errors.append( "usernameblank" )

	if len( password1 ) == 0:
		errors.append( "password1blank" )

	if len( password2 ) == 0:
		errors.append( "password2blank" )
	
	if options.email_required and len( email ) == 0:
		errors.append( "emailblank" )

	if mongodb['users'].find( { "name": username } ).count() > 0:
		errors.append( "nametaken" )

	if password1 != password2:
		errors.append( "nomatch" )

	if len( errors ) > 0:
		return helper.template( 'user/signup', errors=errors, form=request.forms, errorMap=signupErrors )

	salt = bcrypt.gensalt()
	hash = bcrypt.hashpw( password1, salt )
	
	user_obj = { 
		'name': username, 
		'password': hash 
	}
		
	mongodb['users'].insert( user_obj )
	
	if email and len(email) > 0:
		helper.add_email( mongodb, username, email )
		helper.send_verification_email( mongodb, username, email )

	redirect( "/login" )