Esempio n. 1
0
def register_handle(request):
    if request.method == 'POST':
        u_user_name = request.POST.get('user_name')
        u_pwd = request.POST.get('pwd')
        u_email = request.POST.get('email')

    users = UserInfo(uname=u_user_name, upwd=u_pwd, uemail=u_email)
    users.save()
    # return render(request,'df_user/login.html', {'user': UserInfo.objects.all()})
    return HttpResponseRedirect('/user/login/')  #重定向不要request
Esempio n. 2
0
def register_handle(request):
    #接收用户密码
    post = request.POST
    name = post.get('name')
    email = post.get('email')
    userName = post.get('userName')
    passWord = post.get('passWord')
    confirmPwd = post.get('confirmPwd')
    phoneNumber = post.get('phoneNumber')
    #判断两次密码
    if passWord != confirmPwd:
        return redirect('/user/register')
    #密码加密
    s1 = sha1()
    s1.update(str(passWord).encode('utf-8'))
    passwordSha1 = s1.hexdigest()
    #创建对象
    user = UserInfo()
    user.name = name
    user.email = email
    user.userName = userName
    user.passWord = passwordSha1
    user.phoneNumber = phoneNumber
    user.save()
    #注册成功,转到登录页面
    return redirect('/user/login/')
Esempio n. 3
0
def info(request):
    # 查询登录状态
    uname = request.session.get('username')

    # 获取用户信息
    user = UserInfo()
    uphone = user.uphone
    uaddress = user.uaddress

    # print uphone,uaddress

    # 读取最近浏览的商品
    goods = request.COOKIES.get('goods_ids', '')
    goods_L = []
    # 如果读取到了内容
    if goods != '':
        # 拆分字符串
        goodslist = goods.split(',')
        print goodslist
        # 依次读取
        for id in goodslist:
            if id != '':
                goods_L.append(GoodsInfo.objects.get(id=int(id)))

    context = {
        'uname': uname,
        'uphone': uphone,
        'uaddress': uaddress,
        'goodslist':goods_L,
    }
    return render(request,'df_user/user_center_info.html',context)
Esempio n. 4
0
def register_handle(request):
    uname = request.POST['user_name']
    upwd = request.POST['pwd']
    ucpwd = request.POST['cpwd']
    uemail = request.POST['email']
    uallow = request.POST['allow']

    #   print(uemail)
    if upwd != ucpwd:
        return HttpResponse("两次输入的密码不一致")
    '''
    if uname == None:
        context = {'temp':"用户名为空"}
        return render(request, "user_template/register.html", context)
    if upwd == None:
        context = {'temp': "密码为空"}
        return render(request, "user_template/register.html",  context)
    if uemail == None:
        context = {'temp': "邮箱为空为空"}
        return render(request, "user_template/register.html",  context)
'''

    #使用sha1加密密码
    encry = hashlib.sha1()
    encry.update(upwd)
    encry_pwd = encry.hexdigest()

    userInfo = UserInfo()
    userInfo.uname = uname
    userInfo.upwd = encry_pwd
    userInfo.uemail = uemail
    userInfo.save()
    return redirect('/user/login')
Esempio n. 5
0
def register_handler(request):
    post = request.POST
    uname = post.get('user_name')
    upwd = post.get('pwd')
    ucpwd = post.get('cpwd')
    uemail = post.get('email')

    if uname.strip() == '':
        return redirect('user:register')

    if upwd != ucpwd:
        return redirect('user:register')

    if uemail.strip() == '':
        return redirect('user:register')

    # 判断用户是否注册过
    if len(UserInfo.objects.filter(uname=uname)) == 0:
        # 创建对象
        user = UserInfo()
        user.uname = uname

        # 密码加密
        md5 = hashlib.md5()
        md5.update(upwd.encode("utf8"))
        upwd1 = md5.hexdigest()

        user.upwd = upwd1
        user.uemail = uemail
        user.save()

        # 注册成功转到登录页面
        return redirect('user:login')
    else:
        return redirect('user:register')
Esempio n. 6
0
def register(request):
    """用户注册页面"""
    if request.method == "GET":
        return render(request, "df_user/register.html")

    if request.method == "POST":
        uname = request.POST.get("user_name")
        upwd = request.POST.get("pwd")
        ucpwd = request.POST.get("cpwd")
        uemail = request.POST.get("email")

        # 后台验证两次密码的一致性
        if upwd != ucpwd:
            return render(request, "df_user/register.html")

        # 密码加密
        encrypt_pwd = sha1()
        encrypt_pwd.update(upwd.encode("utf-8"))
        encryption_pwd = encrypt_pwd.hexdigest()

        # 创建User对象
        user = UserInfo()
        user.uname = uname
        user.upwd = encryption_pwd
        user.uemail = uemail
        user.save()
        # 46d65d3bc3673eafb1a8642368085adb641e447e
        # ddec849f673af24de347bf89d6595733cf5a1086
        return HttpResponseRedirect("/user/login")
Esempio n. 7
0
def register_handle(requert):
    """
    1. 接收用户输入 request.POST
    2. 判断两次密码是否一致
    3. 密码加密
    4. 写入数据库
    5. 跳转到登录界面
    :param requert:
    :return:
    """
    # 1. 接收用户输入
    userinfo = requert.POST
    username = userinfo['user_name']
    user = UserInfo.objects.filter(uname=username)
    if len(user) == 0:
        upwd = userinfo['pwd']
        #  upwd2 = userinfo['cpwd']
        uemail = userinfo['email']

        # 3. 密码加密
        s1 = sha1()
        s1.update(upwd.encode('utf8'))  # 一定要加utf8
        upwd3 = s1.hexdigest()  # 转换后要写入数据库的密码

        # 4. 写入数据库
        newuser = UserInfo()
        newuser.uname = username
        newuser.upwd = upwd3
        newuser.uemail = uemail
        newuser.save()
        return redirect('/user/login/')
    else:
        return render(requert, 'df_user/register.html')
Esempio n. 8
0
def site(request):
    userId = request.session['user_id']
    u_shou = request.POST.get('ushou')
    u_address = request.POST.get('uaddress')
    u_youbian = request.POST.get('uyoubian')
    u_phone = request.POST.get('uphone')
    userin = UserInfo()
    userin.id = userId
    userin.ushou = u_shou
    userin.uaddress = u_address
    userin.uyoubian = u_youbian
    userin.uphone = u_phone
    userin.save()

    user = UserInfo.objects.filter(id=userId)
    return render(request, 'df_user/user_center_site.html', {'user': user})
Esempio n. 9
0
def login_handler(request):
    username = request.POST.get("username", "")
    password = request.POST.get("pwd", "")

    if username is None or username.strip() == "" or password is None or password.strip() == "":
        result = toResult(code=205, msg="用户名与密码不能为空")
        return HttpResponse(simplejson.dumps(result))

    user_count = len(UserInfo.objects.filter(uname=username))

    if user_count == 1:

        # 密码加密
        md5 = hashlib.md5()
        md5.update(password.encode("utf8"))
        md5pwd = md5.hexdigest()

        userResult = UserInfo.objects.filter(uname=username, upwd=md5pwd)
        if len(userResult) == 1:

            print("密码正确")
            print(md5pwd)
            print(password)

            userInfo = UserInfo()
            userInfo.uname = userResult[0].uname
            userInfo.uemail = userResult[0].uemail
            retult = toResult(msg="登录成功")
            return HttpResponse(simplejson.dumps(retult))
        else:
            result = toResult(code=201, msg="密码错误")
            print("密码错误")
            print(md5pwd)
            print(password)
            return HttpResponse(simplejson.dumps(result))

    else:
        retult = toResult(code=202, msg="用户名错误")
        return HttpResponse(simplejson.dumps(retult))
Esempio n. 10
0
def register_handle(request):
    post = request.POST
    uname = post.get("user_name")
    upwd = post.get("pwd")
    ucpwd = post.get("cpwd")
    uemail = post.get("email")
    print(uname,upwd,ucpwd,uemail)
    if upwd!=ucpwd:
        return HttpResponseRedirect('user/register')
    s1=sha1()
    s1.update(upwd.encode())
    passwd2 = s1.hexdigest()
    user = UserInfo()
    user.uname = uname
    user.upwd = passwd2
    user.uemail = uemail
    user.save()
    
    return HttpResponseRedirect('user/login')
Esempio n. 11
0
def registerHandle(request):
    # 接受表单提交的内容
    post = request.POST
    uname = post.get('user_name')
    upwd = post.get('pwd')
    uemail = post.get('email')
    # 查询是否有相同的用户名
    count = UserInfo.objects.filter(uname = uname).count()
    if count == 0:
        user = UserInfo()
        user.uname = uname
        user.upwd = sha1_pwd(upwd)
        user.uemil = uemail
        user.save()
    else:
        # 如果用户名存在,则重新到注册页面
        return redirect('/user/register/')
    # 注册成功,重定向到登录页面
    return redirect('/user/login/')
Esempio n. 12
0
def register_handler(request):
    post = request.POST
    uname = post.get('user_name')
    upwd = post.get('pwd')
    ucpwd = post.get('cpwd')
    uemail = post.get('email')

    if upwd != ucpwd:
        return redirect('/user/register')
    s1 = sha1()
    s1.update(upwd.encode("utf8"))
    upwd3 = s1.hexdigest()

    user = UserInfo()
    user.uname = uname
    user.upwd = upwd3
    user.uemail = uemail
    user.save()

    return redirect('/user/login/')
Esempio n. 13
0
def register_handler(request):
    #接收请求参数
    user_name = request.POST['user_name']
    pwd = request.POST['pwd']
    cpwd = request.POST['cpwd']
    email = request.POST['email']
    if pwd != cpwd:
        return redirect('/user.register')

    #密码加密
    s1 = sha1()
    s1.update(pwd)
    upw3 = s1.hexdigest()
    # 创建对象
    user = UserInfo()
    user.uname = user_name
    user.upwd = upw3
    user.uemail = email
    user.save()
    #转到登陆页面
    return redirect('/user/login')
Esempio n. 14
0
def register_handle(request):
    #接受用户输入
    post = request.POST
    uname = post.get('user_name')
    upwd = post.get('pwd')
    upwd2 = post.get('cpwd')
    uemaile = post.get('email')
    #判断两次密码
    if upwd != upwd2:
        return redirect('/user/register/')
    #密码加密
    # s1 = sha1()
    # s1.update(upwd)
    # upwd3 = s1.hexdigest()
    #创建对象
    user = UserInfo()
    user.uname = uname
    user.upwd = upwd
    user.uemail = uemaile
    user.save()
    #注册成功 转到登录界面
    return redirect('/user/login/')
Esempio n. 15
0
def register_handle(request):
    #接收用户输入
    post=request.POST
    uname=post.get('user_name')
    upwd=post.get('pwd')
    upwd2=post.get('cpwd')
    uemail=post.get('email')
    #判断两次密码
    if upwd!=upwd2:
        return redirect('/user/register/')
    #密码加密
    s1=sha1()
    s1.update(upwd.encode('utf-8'))
    upwd3=s1.hexdigest()
    #创建对象
    user=UserInfo()
    user.uname=uname
    user.upwd=upwd3
    user.uemail=uemail
    user.save()
    #注册成功,转到登录页面
    return redirect('/user/login/')
Esempio n. 16
0
def register(request):
    if request.method == "GET":
        return render(request, 'df_user/register.html', {'title': '天天生鲜-注册'})
    else:
        username = request.POST.get('user_name')
        pwd = request.POST.get('pwd')
        cpwd = request.POST.get('cpwd')
        email = request.POST.get('email')

        # 保存用户之前,对密码进行加密
        s = sha1()
        s.update(pwd)
        # 相同字符串加密结果是一样的
        sha1_pwd = s.hexdigest()

        user = UserInfo()
        user.u_name = username
        user.u_password = sha1_pwd
        user.u_email = email
        user.save()

    # 注册成功,重定向登录页面
    return redirect('/user/login/')