def regiest_action(request): if request.method == "POST": userform = Userform(request.POST) msg_count = 1 if userform.is_valid(): userform = userform.cleaned_data t_username = userform.get('username') user = UserCreationForm({'username':t_username,'password1':userform.get('passwd1'),'password2':userform.get('passwd2')}) verify = getverify() ret = send(userform.get('email'), t_username, verify) if ret: username = t_username user.save() userinfo = Userinfo(username=userform.get('username'),activity='0',email=userform.get('email'),telephone=userform.get('telephone'),address=userform.get('address'),verify=security(verify),gender=userform.get('gender'),id=User.objects.get(username = username)) userinfo.save() user = auth.authenticate(username = username,password = userform.get('passwd1')) auth.login(request,user) request.session['user'] = username user_from = Userinfo.objects.get(username = '******') user_to = Userinfo.objects.get(username = username) message = Message(title = NEW_USER_TITLE,body = NEW_USER_BODY,state = 0,date = datetime.now(),user_from = user_from,user_to = user_to) message.save() success_msg = '请登录%s查收邮件激活!'.decode('utf-8') % userform.get('email') return jump_to_success(success_msg) else: error_msg = '验证邮件发送失败!' return jump_to_error(error_msg) else: error = "出错了,请重新注册!" return render_to_response('regiest.html',locals()) else: return render_to_response('regiest.html',locals())
def userinfo_submit_action(request,username=False,msg_count=0): if request.method == 'POST': form = Userform(request.POST) if form.is_valid(): form_cd = form.cleaned_data verify = getverify() ret = send(form_cd.get('email'), username, verify) if ret: Userinfo.objects.filter(username=username).update(gender=form_cd.get('gender'), email=form_cd.get('email'), telephone=form_cd.get('telephone'), address=form_cd.get('address'),verify=security(verify)) success_msg = '请查收邮件激活!' return jump_to_success(success_msg) else: error_msg = '验证邮件发送失败!' return jump_to_error(error_msg) else: error = True form = Userform() return render_to_response('user.html',locals()) return HttpResponseRedirect('/home')