def register(request): ''' 注册 ''' error = {'errMessage': ''} if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): data = form.cleaned_data username = data['username'] email = data['email'] password = data['password'] register_dict = { 'company_name': data['company_name'], 'province': data['province'], 'city': data['city'], 'town': data['town'], 'mobile': data['mobile'], 'postalcode': data['postalcode'], 'industry': data['industry'], 'is_active': False, 'user_uuid': str(uuid.uuid1()).replace('-', '') } if not UserProfile.objects.filter( username=username) and not UserProfile.objects.filter( email=email): user = UserProfile.objects.create_user(username, email, password) user.company_name = register_dict['company_name'] user.province = register_dict['province'] user.city = register_dict['city'] user.town = register_dict['town'] user.mobile = register_dict['mobile'] user.postalcode = register_dict['postalcode'] user.industry = register_dict['industry'] user.user_uuid = register_dict['user_uuid'] user.is_active = False user.save() uu_url = set_email_url('register/', register_dict['user_uuid'], username, 'zllm') send_email_main(to_mail=email, user_uuid=uu_url, flag='login') return HttpResponseRedirect( '/account/register/complete_prompt') elif UserProfile.objects.filter(username=username): error['errMessage'] = '用户名已存在!' elif UserProfile.objects.filter(email=email): error['errMessage'] = '该邮箱已经被注册!' else: error['errMessage'] = form.errors else: # django生成的表单 form = RegisterForm() return render_to_response('register.html', error, RequestContext(request))
def register(request): ''' 注册 ''' error = {'errMessage': ''} if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): data = form.cleaned_data username = data['username'] email = data['email'] password = data['password'] register_dict = { 'company_name': data['company_name'], 'province': data['province'], 'city': data['city'], 'town': data['town'], 'mobile': data['mobile'], 'postalcode': data['postalcode'], 'industry': data['industry'], 'is_active': False, 'user_uuid': str(uuid.uuid1()).replace('-', '') } if not UserProfile.objects.filter(username=username) and not UserProfile.objects.filter(email=email): user = UserProfile.objects.create_user(username, email, password) user.company_name = register_dict['company_name'] user.province = register_dict['province'] user.city = register_dict['city'] user.town = register_dict['town'] user.mobile = register_dict['mobile'] user.postalcode = register_dict['postalcode'] user.industry = register_dict['industry'] user.user_uuid = register_dict['user_uuid'] user.is_active = False user.save() uu_url = set_email_url('register/', register_dict['user_uuid'], username, 'zllm') send_email_main(to_mail=email, user_uuid=uu_url, flag='login') return HttpResponseRedirect('/account/register/complete_prompt') elif UserProfile.objects.filter(username=username): error['errMessage'] = '用户名已存在!' elif UserProfile.objects.filter(email=email): error['errMessage'] = '该邮箱已经被注册!' else: error['errMessage'] = form.errors else: # django生成的表单 form = RegisterForm() return render_to_response('register.html', error, RequestContext(request))
def revise_password_check(request): ''' 重置密码,发送邮件和验证邮件 ''' template_name = 'register-complete-true-active.html' vm = {'content': ''} email = request.POST.get('email') if not UserProfile.objects.filter(email=email).exists(): vm['errMessage'] = '该邮箱未注册!' else: user_uuid = UserProfile.objects.get(email=email).user_uuid uu_url = set_email_url('revise-password/', user_uuid, '', 'zllm') send_email_main(to_mail=email, user_uuid=uu_url, flag='revise') vm['content'] = '修改密码邮件已发送,请至邮箱查看!' return render_to_response(template_name, vm, RequestContext(request))