示例#1
0
文件: views.py 项目: ltyjason/AXF
def user_register(request):
    if request.method == "GET":
        data = {
            'title': '用户注册',
        }
        return render(request, 'main/user_register.html', context=data)
    elif request.method == "POST":

        u_name = request.POST.get("u_name")
        u_email = request.POST.get("u_email")
        u_password = request.POST.get("u_password")
        u_icon = request.FILES.get("u_icon")

        user = UserModel()
        user.u_name = u_name
        user.u_email = u_email
        user.u_icon = u_icon
        user.set_password(u_password)

        user.save()

        request.session['user_id'] = user.id

        # 发送邮件
        # token = str(uuid.uuid4())
        token = secrets.token_hex(16)

        cache.set(token, user.id, timeout=60)

        send_mail_learn(u_name, u_email, token)

        return redirect(reverse('axf:mine'))
示例#2
0
def user_register(request):
    if request.method == "GET":
        data = {
            "title": '用户注册',
        }
        return render(request, 'user/user_register.html', context=data)
    elif request.method == "POST":

        u_name = request.POST.get("u_name")
        u_email = request.POST.get("u_email")
        u_password = request.POST.get("u_password")
        print(u_password)
        u_icon = request.FILES.get("u_icon")

        user = UserModel()
        user.u_name = u_name
        user.u_email = u_email
        user.u_icon = u_icon
        user.set_password(u_password)

        user.save()

        request.session['user_id'] = user.id

        # 发送邮件    token生成策略  自己写,使用 uuid, 引入第三方库 ,   secrets库   python 3.6
        token = str(uuid.uuid4())


        cache.set(token, user.id, timeout=60 * 60)

        send_mail_learn(u_name, u_email, token)

        return redirect(reverse('axf:mine'))
示例#3
0
def register(request):
    if request.method == "GET":
        data = {
            'title': '用户注册',
        }
        return render(request, 'register/register.html', context=data)
    elif request.method == "POST":
        u_name = request.POST.get("u_name")
        u_email = request.POST.get("u_email")
        u_password = request.POST.get("u_password")
        u_password2 = request.POST.get("u_password2")
        u_icon = request.FILES.get("u_icon")

        if u_password == u_password2:
            user = UserModel()
            user.u_name = u_name
            user.u_email = u_email
            user.u_icon = u_icon
            user.set_password(u_password)
            print("save")

            user.save()

            request.session['user_id'] = user.id

            token = str(uuid.uuid4())
            cache.set(token, user.id)

            return redirect(reverse('second:home_logined'))
        else:
            return render(request, 'register/register.html')
示例#4
0
def user_register(request):
    if request.method == 'GET':
        return render(request,'App/user/user_register.html')
    elif request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        email = request.POST.get('email')
        icon = request.FILES.get('icon')

        user = UserModel()
        user.u_name = username
        user.u_email = email
        # user.u_password = password
        user.set_password(password)
        user.u_icon = icon

        user.save()

        # temp = loader.get_template('App/active_email.html')
        #
        # token = str(uuid.uuid4())
        #
        # cache.set(token,user.id,timeout=10*60)
        #
        # temp_content = temp.render({'username':username,'active_url':'http://127.0.0.1:8004/app/useractive/?u_token='+token})
        #
        # send_mail('项目激活邮件','','*****@*****.**',[email,],html_message=temp_content)

        request.session['username'] = username

        request.session.flush()

        return redirect(reverse('app:mine'))
示例#5
0
def user_register(request):
    if request.method == "GET":
        data = {
            "title": '用户注册',
        }
        return render(request, 'register.html', context=data)

    elif request.method == "POST":

        u_name = request.POST.get("u_name")
        u_email = request.POST.get("u_email")
        u_password = request.POST.get("u_password")
        u_icon = request.FILES.get("u_icon")

        user = UserModel()
        user.u_name = u_name
        user.u_email = u_email
        user.u_icon = u_icon
        user.set_password(u_password)
        user.save()

        request.session['user_id'] = user.id
        return redirect(reverse('App:home'))
示例#6
0
def user_register(request):
    if request.method == 'GET':
        return render(request, "App/user/user_register.html")
    elif request.method == "POST":
        username = request.POST.get("username")
        password = request.POST.get("password")
        email = request.POST.get("email")
        #上传的文件用File
        icon = request.FILES.get("icon")

        user = UserModel()
        user.u_name = username
        # user.u_password = password
        user.set_password(password=password)
        user.u_email = email
        user.u_icon = icon
        user.save()

        # 发送激活邮件
        token = str(uuid.uuid4())
        cache.set(token, user.id, timeout=10 * 60)
        template = loader.get_template("App/ActiveEmail.html")
        template_content = template.render({
            "username":
            username,
            "active_url":
            "http://127.0.0.1:8000/app/user_active/?u_token=" + token
        })
        send_mail("AXF高级VIP激活",
                  "",
                  "*****@*****.**", [
                      email,
                  ],
                  html_message=template_content)
        # 存入session中
        request.session["username"] = username
        return redirect(reverse("app:mine"))