def register(request): error = '' if request.method == 'GET': return render_to_response('usercenter_register.html',{},context_instance=RequestContext(request)) else: username = request.POST['username'].strip() email = request.POST['email'].strip() password = request.POST['password'].strip() re_password = request.POST['re_password'].strip() if not username or not email or not password or not re_password: error = u"任何字段均不能为空" if password != re_password: error = u'两次密码不一致' if User.objects.filter(username=username).count() > 0: error = u"用户名已存在" if User.objects.filter(email=email).count() > 0: error = u"该邮箱已被注册" if not error: user = User.objects.create_user(username=username,email=email,password=password) user.is_active = False user.save() #获取32位随机码 new_code = str(uuid.uuid4()).replace('-','') #设置过期时间 expire_time = datetime.datetime.now()+datetime.timedelta(days=1) code_record = ActivateCode(owner=user,code=new_code,expire_timestamp=expire_time) code_record.save() activate_link = "http://%s%s" % (request.get_host(),reverse('usercenter_activate',args=[new_code])) send_mail(u'[Python部落论坛]激活邮件',u'您的激活链接为:%s' % activate_link,'*****@*****.**',[email],fail_silently=False) else: return render_to_response('usercenter_register.html',{'errors':error},context_instance = RequestContext(request)) return redirect(reverse('login'))
def register(request): error='' if request.method=='GET': return render_to_response('usercenter_register.html',{},context_instance=RequestContext(request)) else: username=request.POST['username'].strip() email=request.POST['email'].strip() password=request.POST['password'].strip() re_password=request.POST['re_password'].strip() if not username or not email or not password: error='任何字段不能为空' if password != re_password: error='两次密码不一致' if User.objects.filter(username=username).count() > 0: error='用户已存在' if not error: user=User.objects.create_user(username=username,email=email,password=password) user.is_active=False user.save() new_code=str(uuid.uuid4()).replace('-','') expire_time=datetime.datetime.now()+datetime.timedelta(days=2) code_recode=ActivateCode(owner=user,code=new_code,expire_timestamp=expire_time) code_recode.save() activate_link="http://%s%s" %(request.get_host(),reverse('usercenter_activate',args=[new_code])) send_mail(u'python部落激活邮件',u'激活地址:%s' % activate_link , '*****@*****.**', [email],fail_silently=False) else: return render_to_response('usercenter_register.html',{'error':error},context_instance=RequestContext(request)) return redirect(reverse('login'))
def register(request): if request.method == "GET": return render(request, "usercenter_register.html") else: error = '' username = request.POST["username"].strip() password = request.POST["password"].strip() email = request.POST["email"].strip() re_password = request.POST["re_password"].strip() if password != re_password: error = u'两次的密码不一致' if not request.POST["username"] or not request.POST["password"] or not request.POST["email"]: error = u'字段不能空' if error: messages.add_message(request, messages.INFO, error) return redirect(reverse('usercenter_register')) new_user = User.objects.create_user(username=username,password=password,email=email) new_user.is_active = False new_user.save() new_code = str(uuid.uuid4()).replace('-','') expire_time = datetime.datetime.now() + datetime.timedelta(days=2) code_record = ActivateCode(owner=new_user,code=new_code,expire_timestamp=expire_time) code_record.save() activate_url = "http://%s%s" % (request.get_host(),reverse("usercenter_activate",args=[new_code])) send_mail(u'激活邮件', u'你的激活链接为: %s'%activate_url, '*****@*****.**' ,[email], fail_silently=False) return redirect(reverse('login'))
def register(request): error = '' if request.method == "GET": return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) else: username = request.POST['username'].strip() email = request.POST['email'].strip() password = request.POST['password'].strip() re_password = request.POST['re_password'].strip() if not username or not password or not email: error = u'任何字段都不能为空' if password != re_password: error = u'两次密码不一致' if User.objects.filter(username=username).count() > 0: error = u'用户名已存在' if not error: user = User.objects.create_user(username=username, email=email, password=password) user.is_active = False user.save() new_code = str(uuid.uuid4()).replace('-', '') expire_time = datetime.datetime.now() + datetime.timedelta(days=2) code_record = ActivateCode(owner=user, expire_timestamp=expire_time, code=new_code) code_record.save() activate_link = "http://%s%s" % (request.get_host(), reverse("usercenter_activate", args=[new_code])) send_mail(u'[Python部落论坛]激活邮件', u'您的激活码链接为:%s' % activate_link, '*****@*****.**', [email], fail_silently=False) else: return render_to_response("usercenter_register.html", {"error": error}, context_instance=RequestContext(request)) return redirect(reverse("login"))
def user_register(request): if request.method == 'GET': return render_to_response('usercenter_register.html',{},context_instance=RequestContext(request)) else: username = request.POST['username'].strip() password = request.POST['password'].strip() re_password = request.POST['repassword'].strip() email = request.POST['email'].strip() error = '' if not username or not password or not re_password or not email: error = u'以上内容均不能为空' if password != re_password: error = u'两次输入密码不一致' if User.objects.filter(username = username).count()>0: error = u'该用户已存在' if not error: user = User.objects.create_user(username=username, password=password,email=email) user.is_active = False user.save() new_code = str(uuid.uuid4()).replace('-','') code_record = ActivateCode(ower = user, Code = new_code, expiry_ti = datetime.datetime.now() + datetime.timedelta(days = 2)) code_record.save() activate_link = "http://%s%s" % (request.get_host(),reverse("usercenter_activate",args=[new_code])) send_mail(u'激活邮件', u'您的激活链接为: %s' % activate_link, '*****@*****.**',[email], fail_silently=False) else: return render_to_response('usercenter_register.html',{'error':error},context_instance = RequestContext(request)) return redirect(reverse('login'))
def register(request): error = "" if request.method == "GET": return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) else: username = request.POST["username"].strip() email = request.POST["email"].strip() password = request.POST["password"].strip() re_password = request.POST["re_password"].strip() if not username or not password or not email: error = u"用户名,密码,邮箱均不能为空" if password != re_password: error = u"两次密码不一致" if User.objects.filter(username=username).count() > 0: error = u"用户名已经存在" if not error: user = User.objects.create_user(username=username, email=email, password=password) user.is_active = False user.save() new_code = str(uuid.uuid4()).replace("-", "") expire_time = datetime.datetime.now() + datetime.timedelta(days=2) code_record = ActivateCode(owner=user, code=new_code, expire_timestamp=expire_time) code_record.save() activate_link = "http://%s%s" % (request.get_host(), reverse("usercenter_activate", args=[new_code])) send_mail(u"LET'S FUN!激活邮件", u'点击链接进行激活: %s' % activate_link, "*****@*****.**", [email], fail_silently=False) else: return render_to_response("usercenter_register.html", {"error": error}, context_instance=RequestContext(request)) return redirect(reverse("login"))
def register(request): error = '' if request.method == 'GET': return render_to_response('usercenter_register.html',{},context_instance=RequestContext(request)) else: username = request.POST['username'].strip() email = request.POST['email'].strip() password = request.POST['password'].strip() re_password = request.POST['re_password'].strip() if not username or not password or not email: error = u'任何字段都不能为空' if password != re_password: error = u'密码不一致' if User.objects.filter(username=username).count() > 0: error = u'用户已存在' if not error: user = User.objects.create_user(username=username,email=email,password=password) user.is_active = False user.save() profile = UserProfile(owner=user,avatar="http://res.myform.com/mmexport1445957752296.jpg") profile.save() new_code = str(uuid.uuid4()).replace("-","") expire_time = datetime.datetime.now() + datetime.timedelta(days=2) code_record = ActivateCode(owner=user,code=new_code,expire_timestamp=expire_time) code_record.save() activate_link = "http://%s%s" % ((request.get_host()),reverse("usercenter_activate",args=[new_code])) send_mail(u'激活邮件',u'您的激活链接为: %s' % activate_link,"*****@*****.**",[email],fail_silently=False) else: return render_to_response("usercenter_register.html",{"error":error},context_instance=RequestContext(request)) return redirect('login')
def register(request): if request.method=="GET": return render_to_response("usercenter_register.html",{},context_instance=RequestContext(request)) else: username=request.POST['username'].strip() email=request.POST['email'].strip() password=request.POST['password'].strip() re_password=request.POST['re_password'].strip() if not username or not email or not password or not re_password: messages.add_message(request,messages.ERROR,u"任何字段都不能为空") return render_to_response("usercenter_register.html",{},context_instance=RequestContext(request)) if password != re_password: messages.add_message(request,messages.ERROR,u"两次密码不同") return render_to_response("usercenter_register.html",{},context_instance=RequestContext(request)) if User.objects.filter(username=username).count()>0: messages.add_message(request,messages.ERROR,u"用户已存在") return render_to_response("usercenter_register.html",{},context_instance=RequestContext(request)) else: user=User.objects.create_user(username=username,email=email,password=password) user.is_active=False user.save() new_code=str(uuid.uuid4()).replace("-","") expire_time=datetime.datetime.now()+datetime.timedelta(days=2) code_record=ActivateCode(owner=user,code=new_code,expire_timestamp=expire_time) code_record.save() activate_link="http://%s%s"%(request.get_host(),reverse("usercenter_activate",args=[new_code])) send_mail(u"激活邮件",u"激活链接为:%s"%(activate_link),'*****@*****.**',[email],fail_silently=False) return redirect(reverse("login"))
def register(request): error = '' if request.method == "GET": return render_to_response("register.html", {}, context_instance=RequestContext(request)) else: username = request.POST['username'].strip() email = request.POST['email'].strip() password = request.POST['password'].strip() re_password = request.POST['re_password'].strip() if not username or not password or not email: error = u'不能为空' if password != re_password: error = u'密码不一致' if User.objects.filter(username=username).count() > 0: error = u'用户已经存在' if not error: user = User.objects.create_user(username=username, email=email, password=password) user.is_active = False user.save() profile = UserProfile(owner=user, avatar="") profile.save() new_code = str(uuid.uuid4()).replace("-", "") expire_time = datetime.datetime.now() + datetime.timedelta( days=2) #过期时间=当前时间加2天 code_record = ActivateCode(owner=user, code=new_code, expire_timestamp=expire_time) code_record.save() activate_link = "http://%s%s" % ( request.get_host(), reverse("usercenter_activate", args=[new_code])) #激活链接,域名加激活码 send_mail(u'激活邮件', u'您的激活链接为:%s' % activate_link, '*****@*****.**', [email], fail_silently=False) #最后一个参数是发生错误时是否选择静默,false就是要报错 else: return render_to_response('register.html', {'error': error}, context_instance=RequestContext(request)) return redirect(reverse("login"))
def register(request): if request.method == "GET": return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) else: username = request.POST['username'].strip() email = request.POST['email'].strip() password = request.POST['password'].strip() re_password = request.POST['re_password'].strip() if not username or not email or not password or not re_password: messages.add_message(request, messages.ERROR, u"任何字段都不能为空") return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) if password != re_password: messages.add_message(request, messages.ERROR, u"两次密码不同") return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) if User.objects.filter(username=username).count() > 0: messages.add_message(request, messages.ERROR, u"用户已存在") return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) else: user = User.objects.create_user(username=username, email=email, password=password) user.is_active = False user.save() new_code = str(uuid.uuid4()).replace("-", "") expire_time = datetime.datetime.now() + datetime.timedelta(days=2) code_record = ActivateCode(owner=user, code=new_code, expire_timestamp=expire_time) code_record.save() activate_link = "http://%s%s" % (request.get_host(), reverse("usercenter_activate", args=[new_code])) send_mail(u"激活邮件", u"激活链接为:%s" % (activate_link), '*****@*****.**', [email], fail_silently=False) return redirect(reverse("login"))
def register(request): error = "" if request.method == "GET": return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) else: username = request.POST['username'].strip() email = request.POST['email'].strip() password = request.POST['password'].strip() re_password = request.POST['re_password'].strip() if not username or not password or not email: error = u"任何字段都不能为空" if password != re_password: error = u"两次密码不一致" if User.objects.filter(username=username).count() > 0: error = u"用户已存在" if not error: user = User.objects.create_user(username=username, email=email, password=password) user.is_active = False user.save() profile = UserProfile(owner=user) profile.save() new_code = str(uuid.uuid4()).replace("-", "") expire_time = datetime.datetime.now() + datetime.timedelta(days=2) code_record = ActivateCode(owner=user, code=new_code, expire_timestamp=expire_time) code_record.save() activate_link = "http://%s%s" % (request.get_host(), reverse("usercenter_activate", args=[new_code])) send_mail(u'[Python部落论坛]激活邮件', u'您的激活链接为: %s' % activate_link, '*****@*****.**', [email], fail_silently=False) else: return render_to_response("usercenter_register.html", {"error": error}, context_instance=RequestContext(request)) return redirect(reverse("login"))
def register(request): error = "" if request.method == 'GET': return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) else: username = request.POST["username"].strip() email = request.POST["email"].strip() password = request.POST["password"].strip() re_password = request.POST["re_password"].strip() if not username or not email or not password: error = u"不允许为空" if password != re_password: error = u"密码不一致" if User.objects.filter(username=username).count() > 1: error = u"用户已经存在" if not error: user = User.objects.create_user(username=username, password=password, email=email) user.is_active = 0 user.save() new_code = str(uuid.uuid4()).replace("-", "") #生成随机码 expire_time = datetime.datetime.now() + datetime.timedelta( days=2) #需要两天之内激活 code_record = ActivateCode(owner=user, code=new_code, expire_timestamp=expire_time) code_record.save() activate_link = "http://%s%s" % (request.get_host(), reverse("usercenter_activate", args=[new_code])) send_mail(u"发送激活邮件", u"你的激活链接为%s" % (activate_link, ), '*****@*****.**', [email], fail_silently=False) #发送失败需要报错 else: return render_to_response("usercenter_register.html", {"error": error}, context_instance=RequestContext(request)) return redirect(reverse("login"))
def usercenter_register(request): error = "" if request.method == 'GET': return render_to_response('usercenter_register.html', {}, context_instance=RequestContext(request)) else: username = request.POST['username'].strip() email = request.POST['email'].strip() password = request.POST['password'].strip() confirmed_pwd = request.POST['confirmed_pwd'].strip() if not username or not email or not password: error = u'所有信息都不能空!' messages.add_message(request, messages.WARNING, error) return render_to_response('usercenter_register.html', {}, context_instance = RequestContext(request)) if password != confirmed_pwd: error = u'密码两次输入不一致!' if User.objects.filter(username=username).count() > 0: error = u'用户以存在!' if User.objects.filter(email=email).count() > 0: error = u'该邮箱已被注册!' if error: messages.add_message(request, messages.WARNING, error) return render_to_response('usercenter_register.html', {}, context_instance = RequestContext(request)) else: new_code = str(uuid.uuid4()).replace('-', '') expire_time = datetime.datetime.now() + datetime.timedelta(days=2) activate_link = 'http://%s%s' % (request.get_host(), reverse('usercenter_activate', args=[new_code])) try: send_mail(u'我的论坛', u'欢迎注册,请使用如下地址激活账号 %s:%s' % (username, activate_link), '*****@*****.**', [email], fail_silently=False) except Exception as e: print e messages.add_message(request, messages.WARNING, u'邮件发送失败!') return render_to_response('usercenter_register.html', {}, context_instance = RequestContext(request)) messages.add_message(request, messages.INFO, u'邮件已发送,请激活!') user = User.objects.create_user(username=username, email=email, password=password) user.is_active = False user.save() code_record = ActivateCode(owner=user, code=new_code, expire_timestamp=expire_time) code_record.save() print activate_link return render_to_response('usercenter_register.html', {}, context_instance=RequestContext(request))
def register(request): error = "" if request.method == "GET": return render(request, 'user_register.html') else: username = request.POST.get('username', None).strip() email = request.POST.get('email', None).strip() password = request.POST.get('password', None).strip() re_password = request.POST.get('re_password', None).strip() if not username or not password or not email: error = u"任何字段都不能为空" if password != re_password: error = u"两次密码不一致" if User.objects.filter(username=username).count() > 0: error = u"用户名已存在" #if User.objects.filter(email=email).count() > 0: # error = u"该邮箱已注册" if not error: user = User.objects.create_user(username=username, email=email, password=password) user.is_active = False user.save() new_string = random_string() expire_time = datetime.datetime.now() + datetime.timedelta(days=2) code = ActivateCode(owner=user, code=new_string, expire_time=expire_time) code.save() activate_link = "http://%s/userinfo/activate/%s" % ( request.get_host(), new_string) try: send_mail("激活邮件", "您的激活链接是%s" % activate_link, DEFAULT_FROM_EMAIL, [email]) return render(request, "user_register_process.html") except SMTPRecipientsRefused: error = u"邮箱地址不正确,无法正常发送激活邮件" return render(request, "user_register.html", {'error': error})
def register(request): error = "" if request.method == "GET": return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) else: username = request.POST["username"].strip() email = request.POST["email"].strip() password = request.POST["password"].strip() re_password = request.POST["re_password"].strip() if not username or not password or not email: error = "All fields need to be completed" if password != re_password: error = "Two passwords does not match" if User.objects.filter(username=username).count() > 0: error = "Already exist user" if not error: user = User.objects.create_user(username=username, email=email, password=password) user.is_active = False user.save() new_code = str(uuid.uuid4()).replace("-", "") expire_time = datetime.datetime.now() + datetime.timedelta(days=2) code_record = ActivateCode(owner=user, code=new_code, expire_timestamp=expire_time) code_record.save() activate_link = "http://%s%s" % (request.get_host(), reverse("usercenter_activate", args=[new_code])) send_mail( "The Django Forum Activation Email", "To activate: %s" % activate_link, "*****@*****.**", [email], fail_silently=False, ) else: return render_to_response( "usercenter_register.html", {"error": error}, context_instance=RequestContext(request) ) return redirect(reverse("login"))
def register(request): if request.method == "GET": return render(request, "usercenter_register.html") else: error = '' username = request.POST["username"].strip() password = request.POST["password"].strip() email = request.POST["email"].strip() re_password = request.POST["re_password"].strip() if password != re_password: error = u'两次的密码不一致' if not request.POST["username"] or not request.POST[ "password"] or not request.POST["email"]: error = u'字段不能空' if error: messages.add_message(request, messages.INFO, error) return redirect(reverse('usercenter_register')) new_user = User.objects.create_user(username=username, password=password, email=email) new_user.is_active = False new_user.save() new_code = str(uuid.uuid4()).replace('-', '') expire_time = datetime.datetime.now() + datetime.timedelta(days=2) code_record = ActivateCode(owner=new_user, code=new_code, expire_timestamp=expire_time) code_record.save() activate_url = "http://%s%s" % (request.get_host(), reverse("usercenter_activate", args=[new_code])) send_mail(u'激活邮件', u'你的激活链接为: %s' % activate_url, '*****@*****.**', [email], fail_silently=False) return redirect(reverse('login'))
def register(request): error = "" if request.method == "GET": return render_to_response("usercenter_register.html", {}, context_instance=RequestContext(request)) else: username = request.POST['username'].strip() email = request.POST['email'].strip() password = request.POST['password'].strip() re_password = request.POST['re_password'].strip() if not username or not email or not password: error = u'用户名,邮箱,密码,都不能为空!' if password != re_password: error = u'两次密码输入不一致' if User.objects.filter(username=username).count() > 0: error = u'用户名已存在' if User.objects.filter(email=email).count() > 0: error = u'此邮箱已注册' if not error: user = User.objects.create_user(username=username, email=email, password=password) user.is_active = False user.save() new_activate_code = str(uuid.uuid4()).replace("-", "") expire_time = datetime.datetime.now() + datetime.timedelta(days=2) activate_code_record = ActivateCode(owner=user, code=new_activate_code, expire_timestamp=expire_time) activate_code_record.save() activate_link = "http://{}{}".format(request.get_host(), reverse("usercenter_activate", args=[new_activate_code])) send_mail(u'[Python家园]激活邮件', u'您的激活链接为:{}'.format(activate_link), '*****@*****.**', [email], fail_silently=False) # send_mail(subject, message, from_email, recipient_list, fail_silently=False) else: return render_to_response("usercenter_register.html", {"error": error}, context_instance=RequestContext(request)) return render_to_response("usercenter_register_done.html", {"user": user}, context_instance=RequestContext(request))
def register(request): error='' if request.method=="GET": return render_to_response("register.html",{},context_instance=RequestContext(request)) else: username=request.POST['username'].strip() email =request.POST['email'].strip() password=request.POST['password'].strip() re_password=request.POST['re_password'].strip() if not username or not password or not email: error=u'不能为空' if password!= re_password: error=u'密码不一致' if User.objects.filter(username=username).count() >0: error=u'用户已经存在' if not error: user=User.objects.create_user(username=username,email=email,password=password) user.is_active =False user.save() profile = UserProfile(owner=user,avatar = "") profile.save() new_code = str(uuid.uuid4()).replace("-","") expire_time = datetime.datetime.now()+datetime.timedelta(days=2)#过期时间=当前时间加2天 code_record=ActivateCode(owner=user,code=new_code,expire_timestamp=expire_time) code_record.save() activate_link = "http://%s%s"%(request.get_host(),reverse("usercenter_activate",args=[new_code]))#激活链接,域名加激活码 send_mail(u'激活邮件',u'您的激活链接为:%s'%activate_link,'*****@*****.**', [email],fail_silently=False) #最后一个参数是发生错误时是否选择静默,false就是要报错 else: return render_to_response('register.html',{'error':error},context_instance=RequestContext(request)) return redirect(reverse("login"))