示例#1
0
文件: views.py 项目: Twotiger/iforj
def register(request):
    """注册用户"""
    if request.method == "POST":
        f = RegisterForm(request.POST)

        if f.is_valid():
            vari = request.POST.get('vari')
            if not vari or vari != request.session.get("captcha"):
                # return render(request, "register.html", {'errors': f.errors})
                return render(request, "register.html", {'errors': '错误的验证码'})
            name = f.cleaned_data["name"]    # 用户名
            email = f.cleaned_data["email"]  # 邮箱
            psd = f.cleaned_data["psd"]  # 密码
            real_ip = request.META['REMOTE_ADDR']   # ip
            introduction = f.cleaned_data["introduction"]
            vericode = hashlib.sha1(email+EMAIL_SALT).hexdigest()
            user = User.objects.create(name=name, email=email, psd=hashlib.sha1(psd).hexdigest(),
                                       introduction=introduction, vericode=vericode, real_ip=real_ip,
                                       image=DEFAULT_IMAGE_PATH)

            if sendMail([email], '验证邮箱', u"""{username},你好,IFORJ是致力于python的网络问答社区,帮助你寻找答案,分享知识。iforj是由用户可以根据自身的需
求,有针对性地提出问题;同时,这些答案又将作为搜索结果。你可以搜索类似的问题,问题被分为,爬虫,数据分析,django,scrapy,
python语法等基础分类,你可以按着分类搜索相关的问题。我们以打造最活跃的python问答平台为目的,很高兴为您提供便捷的服务。
如果有好的意见和建议,欢迎联系我们
<a href="http://{HOSTNAME}/validate/{vericode}">验证邮箱</a>""".format(username=name,
                    HOSTNAME=HOSTNAME, vericode=vericode)):
                del request.session['captcha']
                user.save()
            else:
                pass  # 邮件发送失败
            return HttpResponseRedirect("/")
        else:
            return render(request, "register.html", {'errors': f.errors})
    return render(request, "register.html")
示例#2
0
def register(request):
    if request.method == 'GET':
        form = RegisterForm()
        return render_to_response('register.html',RequestContext(request,{'form':form,}))
    #注册提交
    else:
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = request.POST.get('username','')
            password = request.POST.get('password','')
            password1 = request.POST.get('password1','')
            email = request.POST.get('email','')
            user = auth.authenticate(username=username,password=password,email=email)
            user1 = auth.authenticate(username=username)
            if user is  None :
                #取id最大用的port
                port_id = User.objects.values('port').latest('id')
                #新用户post 最大用的port +1
                port = port_id['port']+1
                #将表单写入数据库
                #User.objects.get_or_create(username=username,email=email,password=password,port=port)
                user = User.objects.create_user(username=username,password=password,email=email,port=port)
                #print user.is_staff #True
                user.save()
                #返回注册成功页面
                return render_to_response('success.html',{'username':username})
            else:
                return render_to_response('register.html',RequestContext(request,{'form':form,'password_is_wrong':True}))
        else:
            return render_to_response('register.html',RequestContext(request,{'form':form,}))
        return render_to_response('register.html')
示例#3
0
def register(request):
    error = []
    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']
            password2 = data['password2']
            if not User.objects.all().filter(username=username):
                if form.pwd_validate(password, password2):
                    user = User.objects.create_user(username, email, password)
                    user.save()
                    login_validate(request, username, password)
                    return render_to_response('welcome.html',
                                              {'user': username})
                else:
                    error.append('Please input the same password')
            else:
                error.append(
                    'The username has existed,please change your username')
    else:
        form = RegisterForm()
    return render_to_response('register.html', {'form': form, 'error': error})
示例#4
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            info = form.cleaned_data

            User.objects.create_user(info['email'],email=info['email'],password=info['password'])

            UserProfile.objects.create(first_name = info['first_name'], last_name = info['last_name'],
            birthday = info['birthday'], gender = info['gender'], email = info['email'], create_time=datetime.now() )
            return HttpResponseRedirect(reverse('login'))
    else:
         form =RegisterForm()
    return render_to_response('register.html',{'form':form},RequestContext(request))
示例#5
0
文件: views.py 项目: chengkeai/iforj
def register(request):
    """注册用户"""
    if request.method == "POST":
        f = RegisterForm(request.POST)
        if f.is_valid():
            name = f.cleaned_data["name"]
            email = f.cleaned_data["email"]
            psd = f.cleaned_data["psd"]
            introduction = f.cleaned_data["introduction"]
            user = User.objects.create(name=name, email=email, psd=psd, introduction=introduction)
            user.save()
            return HttpResponseRedirect("/")
        else:
            return render(request, "register.html", {"errors": f.errors})
    return render(request, "register.html")
示例#6
0
文件: views.py 项目: beaulian/iforj
def register(request):
    """注册用户"""
    if request.method == "POST":
        f = RegisterForm(request.POST)
        if f.is_valid():
            name = f.cleaned_data["name"]
            email = f.cleaned_data["email"]
            psd = f.cleaned_data["psd"]
            introduction = f.cleaned_data["introduction"]
            user = User.objects.create(name=name, email=email, psd=psd, introduction=introduction)
            user.save()
            return HttpResponseRedirect("/")
        else:
            return render(request, "register.html", {'errors': f.errors})
    return render(request, "register.html")
示例#7
0
def register(request):
	if request.method == 'POST':
		form = RegisterForm(request.POST)
		if form.is_valid():
			username = form.cleaned_data.get('username')
			email = form.cleaned_data.get('email')
			password = form.cleaned_data.get('password')
			User.objects.create_user(username=username, password=password,email=email)
			user = authenticate(username=username, password=password)
			auth_login(request, user)
			return redirect(reverse('home'))

		else:
			return render(request, 'registration/register.html',{'form': form})
	else:
		form = RegisterForm()
		return render(request, 'registration/register.html',{'form': form})
示例#8
0
文件: views.py 项目: NaomiGeng/iforj
def register(request):
    """注册用户"""
    if request.method == "POST":
        f = RegisterForm(request.POST)
        if f.is_valid():
            name = f.cleaned_data["name"]   # 用户名
            email = f.cleaned_data["email"] # 邮箱
            psd = f.cleaned_data["psd"] # 密码
            real_ip = request.META['REMOTE_ADDR']   #ip
            introduction = f.cleaned_data["introduction"]
            vericode = hashlib.sha1(email+EMAIL_SALT).hexdigest()
            user = User.objects.create(name=name, email=email, psd=hashlib.sha1(psd).hexdigest(),
                                       introduction=introduction, vericode=vericode, real_ip=real_ip)
            if sendMail([email], '验证邮箱', '<a href="http://{HOSTNAME}/validate/{vericode}">验证邮箱</a>'.format(HOSTNAME=HOSTNAME, vericode=vericode)):
                user.save()
            else:
                pass# 邮件发送失败
            return HttpResponseRedirect("/")
        else:
            return render(request, "register.html", {'errors': f.errors})
    return render(request, "register.html")
示例#9
0
文件: views.py 项目: orang5/monitor
def register(request):
    error = ''
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            password2 = form.cleaned_data['password2']
            if not User.objects.all().filter(username=username):
                if form.pwd_validate(password, password2):
                    user = User.objects.create_user(username, email, password)
                    user.is_staff = True
                    user.save()

                    return render_to_response('login.html')
                else:
                    error = "Please input the same password"
            else:
                error = "The username has existed,please change you username"
        else:
            error = "The email is invalid,please change your email"
    return render_to_response('register.html', {'error': error})
示例#10
0
def register(request):
    error =[]
    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']
            password2=data['password2']
            if not User.objects.all().filter(username=username):
                if form.pwd_validate(password,password2):
                    user=User.objects.create_user(username,email,password)
                    user.save()
                    login_validate(request,username,password)
                    return render_to_response('index.html',{'user':username},context_instance=RequestContext(request));
                else:
                    error.append('Please input the same password ')
            else:
                error.append('The username is existed,please type anthor  usrename')
    else:
        form=RegisterForm()
    return render_to_response('register.html',{'form':form,'error':error})
示例#11
0
def register(request):
    if request.session.get('is_login', None):
        # 登录状态不允许注册。你可以修改这条原则!
        return redirect("/index/")
    if request.method == "POST":
        register_form = RegisterForm(request.POST)
        message = "请检查填写的内容!"
        if register_form.is_valid():  # 获取数据
            username = register_form.cleaned_data['username']
            password1 = register_form.cleaned_data['password1']
            password2 = register_form.cleaned_data['password2']
            email = register_form.cleaned_data['email']
            sex = register_form.cleaned_data['sex']
            if password1 != password2:  # 判断两次密码是否相同
                message = "两次输入的密码不同!"
                return render(request, 'login/register.html', locals())
            else:
                same_name_user = models.User.objects.filter(name=username)
                if same_name_user:  # 用户名唯一
                    message = '用户已经存在,请重新选择用户名!'
                    return render(request, 'login/register.html', locals())
                same_email_user = models.User.objects.filter(email=email)
                if same_email_user:  # 邮箱地址唯一
                    message = '该邮箱地址已被注册,请使用别的邮箱!'
                    return render(request, 'login/register.html', locals())

                # 当一切都OK的情况下,创建新用户

                new_user = models.User()
                new_user.name = username
                new_user.password = password1
                new_user.email = email
                new_user.sex = sex
                new_user.save()
                return redirect('/login/')  # 自动跳转到登录页面
    register_form = RegisterForm()
    return render(request, 'login/register.html', locals())
示例#12
0
    def post(self, request):
        register_form = RegisterForm(request.POST)  #表单验证
        if register_form.is_valid():
            user_name = request.POST.get("email", "")
            if UserProfile.objects.filter(email=user_name):
                return render(request, "register.html", {
                    "register_form": register_form,
                    "msg": "用户已经存在"
                })
            pass_word = request.POST.get("password", "")
            user_profile = UserProfile()
            user_profile.username = user_name
            user_profile.email = user_name
            user_profile.is_active = False
            user_profile.password = make_password(pass_word)  #加密
            user_profile.save()

            # #写入欢迎注册消息
            user_message = UserMessage()
            user_message.user = user_profile.id
            user_message.message = "欢迎注册慕学在线网"
            user_message.save()
            #
            try:
                send_register_email(user_name, "register")
                return render(request, "login.html")
            except SMTPRecipientsRefused as e:
                print("邮箱不存在")
                return render(request, "register.html", {
                    "register_form": register_form,
                    "msg": "邮箱不存在"
                })

        else:
            return render(request, "register.html",
                          {"register_form": register_form})