Beispiel #1
0
def register(request):
    if request.method == 'GET':

        return render(request, 'register.html')

    elif request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('pwd')
        cpassword = request.POST.get('cpwd')
        email = request.POST.get('email')
        if not (password == cpassword):  #两次密码不正确
            return render(request, 'register.html')
    #如果没有异常存入数据库中
        try:
            user = User()
            user.username = username
            user.password = generate_password(cpassword)
            user.email = email
            user.save()
            token = generate_token()
            cache.set(token, user.id, 60 * 60 * 24 * 20)
            request.session['token'] = token
            return redirect('shop:index')
        except:
            return render(request, 'register.html')
Beispiel #2
0
 def post(self, request):
     try:
         name = request.POST.get('name')
         email = request.POST.get('email')
         password = request.POST.get('password')
         phone = request.POST.get('phone')
         hashedPassword = make_password(password=password)
         user = User(name=name,
                     email=email,
                     password=hashedPassword,
                     phone=phone)
         user.save()
         return render(request, 'login.html')
     except:
         return render(request, 'signup.html',
                       {'error': "User already register "})
Beispiel #3
0
def signup(request):
    if request.method =='POST':
        try:
            name=request.POST.get('name')
            email=request.POST.get('email')
            phone=request.POST.get('phone')
            password=request.POST.get('password')
            confpassword=request.POST.get('repassword')
            if password == confpassword:
                hashpassword=make_password(password=password)
                user=User(name=name, email=email,phone=phone,password=hashpassword )
                user.save()
                return render(request, 'shop/login.html', {'title': 'Login Form'})
        except:
            return render(request, 'shop/signup.html', {'title': 'Signup Form','error':'Email already exists'})
    else:
        return render(request, 'shop/signup.html', {'title': 'Signup Form'})
Beispiel #4
0
def register(request):
    if request.method == 'POST':
        name = request.POST["name"]
        username = request.POST["username"]
        num = request.POST["num"]
        email = request.POST["email"]
        pword = request.POST["pword"]

        info = User(name=name,
                    username=username,
                    num=num,
                    pword=pword,
                    email=email)
        info.save()
        return redirect('login')

    else:
        if request.session.has_key('user'):
            return redirect('product_list')
        else:
            return render(request, 'register.html')
Beispiel #5
0
 def post(self, request):
     try:
         name = request.POST.get('name')
         email = request.POST.get('email')
         phone = request.POST.get('phone')
         password = request.POST.get('password')
         confpassword = request.POST.get('repassword')
         if password == confpassword:
             hashpassword = make_password(password=password)
             user = User(name=name,
                         email=email,
                         phone=phone,
                         password=hashpassword)
             user.save()
             return render(request, 'shop/login.html',
                           {'title': 'Login Form'})
     except:
         return render(
             request, 'shop/signup.html', {
                 'title': 'Signup Foignup Form',
                 'error': 'Email or Password Invalid'
             })
Beispiel #6
0
    def post(self, request):
        print(request.POST)
        try:

            # print(request.POST)
            name = request.POST.get('name')
            email = request.POST.get('email')
            password = request.POST.get('password')
            phone = request.POST.get('phone')
            hashedpassword = make_password(password)
            user = User(name=name,
                        email=email,
                        password=hashedpassword,
                        phone=phone)
            user.save()
            print(user)
            messages.success(request,
                             "Your acccount created successfully login now")
            return render(request, 'login.html')
        except:
            messages.error(request, "User already registered please login ")
            return render(request, 'signup.html')