Ejemplo n.º 1
0
    def post(self, request):
        u_username = request.POST.get("u_username")

        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_username

        user.u_password = u_password

        user.u_email = u_email

        user.u_icon = u_icon

        user.save()
        # 生成token  时间 + ip + 随机数
        # uuid
        token = str(uuid.uuid4())

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

        active_url = "http://localhost:8002/axf/active/?token=" + token

        send_mail_to_asy.delay(u_username, active_url, u_email)

        # request.session["user_id"] = user.id

        response = redirect(reverse("axf:user_login"))

        return response
Ejemplo n.º 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'))
Ejemplo n.º 3
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'))
Ejemplo n.º 4
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')
Ejemplo n.º 5
0
def user_register(request):
    if request.method == "GET":
        return render(request, 'user/user_register.html')
    elif request.method == "POST":
        try:
            username = request.POST.get("username")
            password = request.POST.get("password")
            email = request.POST.get("email")
            icon = request.FILES.get("icon")

            print(username)
            print(password)
            print(email)
            print(icon)

            user = UserModel()
            user.username = username
            # 添加数据安全
            password = generate_password(password)
            print(password)
            user.password = password
            user.email = email
            user.icon = icon
            user.save()
            request.session["user_id"] = user.id

            return redirect(reverse("axf:mine"))
        except Exception as e:
            return redirect(reverse("axf:user_register"))
    else:
        raise Exception("不被支持的请求")
Ejemplo n.º 6
0
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'))
Ejemplo n.º 7
0
def image_field(request):
    if request.method == 'GET':
        return render(request, 'image_field.html')
    elif request.method == 'POST':
        username = request.POST.get('username')
        icon = request.FILES.get('icon')
        user = UserModel()
        user.u_name = username
        user.u_icon = icon
        user.save()
        return HttpResponse('上传成功 %d' % user.id)
Ejemplo n.º 8
0
def user_register(request):
    if request.method == 'GET':
        return render(request, 'UserRegister.html')
    elif request.method == 'POST':
        username = request.POST.get('username')

        user = UserModel()
        user.u_name = username
        token = str(uuid.uuid4())
        user.u_token = token
        user.save()

        return HttpResponse('注册成功%s' % token)
Ejemplo n.º 9
0
def user_register(request):
    if request.method == 'GET':
        return render(request, 'UserRegister.html')
    elif request.method == 'POST':
        username = request.POST.get("username")
        password = request.POST.get("password")
        user = UserModel()
        user.u_name = username
        user.u_password = password
        token = str(uuid.uuid4())
        user.u_token = token
        user.save()

        return HttpResponse('注册成功')
Ejemplo n.º 10
0
def register(request):
    method = request.method
    if method =='GET':
        return render(request, 'user/register.html')
    elif method == 'POST':
        uername = request.POST.get('name')
        password = request.POST.get('password')
        email = request.POST.get('email')
        imgFile = request.FILES.get('imgFile')
        user = UserModel()
        user.u_name = uername
        user.u_password = password
        user.u_email = email
        user.u_img = imgFile
        user.save()
        return HttpResponseRedirect(reverse('axf:login'))
Ejemplo n.º 11
0
def user_zhuce(request):
    if request.method == 'GET':
        return render(request,'user_zhuce.html')
    elif request.method == 'POST':
        username = request.POST.get('username')

        user = UserModel()
        user.u_name = username
        token = genrate_token(request.META.get('REMDTE_ADDR'))
        user.u_token = token

        user.save()

        response = HttpResponse('注册成功')
        response.set_cookie('token',token)
        return response
Ejemplo n.º 12
0
def image_field(request):
    if request.method == "GET":
        return render(request, 'image_field.html')
    elif request.method == "POST":

        username = request.POST.get("username")

        icon = request.FILES.get("icon")

        user = UserModel()

        user.u_name = username
        user.u_icon = icon

        user.save()

        return HttpResponse("上传成功%d" % user.id)
Ejemplo n.º 13
0
def do_user_register(request):
    u_name = request.POST.get('username')
    u_password = request.POST.get('password')
    u_age = request.POST.get('age')
    user = UserModel()
    user.u_name = u_name
    user.u_password = password_sec(u_password)
    user.u_age = u_age

    # u_token 唯一标识
    # 时间 + 随机数 + 公司域名 + ip信息
    # 时间 + 域名
    token = generate_token()
    user.u_token = token
    user.save()
    response = HttpResponseRedirect(reverse("app:user_info"))
    response.set_cookie("utoken", token)
    return response
Ejemplo n.º 14
0
def user_register(request):
    if request.method == "GET":
        return render(request, 'UserRegister.html')
    elif request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = UserModel()
        user.u_name = username
        user.u_password = password

        token = generate_token(request.META.get("REMOTE_ADDR"), username)
        user.u_token = token

        user.save()

        response = HttpResponse('注册成功')
        response.set_cookie('token', token)
        return response
Ejemplo n.º 15
0
    def put(self):
        parser = parse.parse_args()

        username = parser.get("username")
        password = parser.get("password")
        email = parser.get("email")
        user = UserModel()
        user.u_name = username
        user.u_password = generate_password_hash(password=password)
        user.u_email = email
        user.save()
        u_token = str(uuid.uuid4())
        cache.set(u_token, user.id, timeout=60)
        msg = Message(subject="TestTppActive",sender="*****@*****.**",recipients=["*****@*****.**"])
        html = render_template("UserActivate.html", username=username, active_url="http://localhost:5000/users/?action=active&u_token=%s"%u_token)

        msg.html = html
        mail.send(msg)

        return {"msg":"ok","data":user}
Ejemplo n.º 16
0
def user_register(request):
    if request.method == 'GET':
        return render(request, 'user_register.html')
    elif request.method == 'POST':
        icon = request.FILES.get('icon')

        username = request.POST.get('username')
        password = request.POST.get('password')

        user = UserModel()
        user.u_name = username
        password = genart_password(password)
        user.u_password = password
        user.u_icon = icon

        user.save()
        response = HttpResponse('注册成功')

        response.set_cookie('username', username)

        return response
Ejemplo n.º 17
0
def image_field(request):
    if request.method == "GET":
        return render(request, 'image_field.html')
    elif request.method == "POST":

        username = request.POST.get("username")

        icons = request.FILES.getlist("icon")

        for icon in icons:
            user = UserModel()
            user.u_name = username
            user.u_icon = icon
            user.save()


#            destination = open(BASE_DIR + '/static/upload/' + icon.name, 'wb+')
#            for part in icon.chunks():
#                destination.write(part)
#                destination.close()
        return HttpResponse("上传成功")
Ejemplo n.º 18
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'))
Ejemplo n.º 19
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"))