Example #1
0
def activate_account(request):
	'''当用户访问属于他的激活链接时会调用此视图
	首先检测激活码的正确性,若激活码有效,那么就激活该账户,并为其设置默认关联信息
	如果不正确,那么就返回提示信息
	'''
	active_code = request.matchdict['active_code']
	
	query_result = DBSession.query(ActivateAccount).filter(ActivateAccount.user_active_code==active_code).first()
	
	if(query_result):
		req_email = query_result.user_email
		user_result = DBSession.query(Users).filter(Users.email==req_email).first()
		
		default_title = get_default_title(req_email)
		print default_title
		default_domain = user_result.id
		user_title = UserTitle(req_email, default_title)
		user_domain = UserDomain(req_email, default_domain)
		DBSession.add(user_title)
		DBSession.add(user_domain)
		
		user_result.activated=1
		DBSession.delete(query_result)
		transaction.commit()
		request.session.flash(u'激活账户成功')
		return HTTPFound(location=request.route_url('login'))
	else:
		return Response(u'此激活链接失效或者此激活码不存在,若实在找不到激活邮件,请与管理员联系。管理员:[email protected]')
Example #2
0
def password_reset_post(request):
	req_email = request.POST['user_session[login]']
	req_password = request.POST['user_session[password]']
	
	query_result = DBSession.query(Users).filter(Users.email==req_email).first()
	#重置密码
	query_result.password = req_password
	transaction.commit()
	
	#把重置密码的重置码从密码重置表中删除
	reset_result = DBSession.query(PasswordResets).filter(PasswordResets.user_email==req_email).first()
	DBSession.delete(reset_result)
	transaction.commit()
	request.session.flash(u'密码重置成功,现在你可以使用您的新密码登入了')
	return HTTPFound(location=request.route_url('login'))
Example #3
0
def password_reset_new_post(request):
	req_email = request.POST['user_session[login]']
	query_result = DBSession.query(PasswordResets).filter(PasswordResets.user_email==req_email).first()
	reset_num = get_random_string()
	new_password_reset = PasswordResets(req_email, reset_num)
	if(query_result):
		DBSession.delete(query_result)
	DBSession.add(new_password_reset)
		
	transaction.commit()
	
	mailer = get_mailer(request)
	message = Message(subject=u'为您的听说账户找回密码',
						sender='*****@*****.**',
						recipients=req_email,
						body= request.route_url('password_reset', reset_num=reset_num)
						)
	mailer.send_immediately(message, fail_silently=False)
	
	request.session.flash(u'一封关于找回您密码的邮件已经发送到您的邮箱')
	request.session.flash(u'如果您在10分钟内没有收到邮件,请重新发送')
	
	return HTTPFound(location=request.route_url('password_reset_new'))