def adduser(request):
    if request.method=="POST":
        #form=NewUserForm(request.POST)
        reg=models.Register.objects.filter(email=request.POST['email'])
        #n=ToastNotifier()
        if len(reg)!=0:
            res=render(request,'shop/signup.html',{'msg': n.show_toast("Register","You Have Already Registered with This Account",duration=2,icon_path="shop/adduser/")})
            return res
        else:
            try:
                #movile no validation
                Pattern = re.compile("(0/91)?[7-9][0-9]{9}")
                s = str(request.POST['mobile'])
                if Pattern.match(s):
                    #n=ToastNotifier()
                    print("valid")
                else:
                    #n=ToastNotifier()
                    #n.show_toast("Mobile no","Invalid mobile no",duration=2,icon_path="shop/adduser/")
                    raise SyntaxError("invalid mobile no")
                #send registration mail to user
                sender_email="*****@*****.**"
                password="******"
                rec_email=request.POST['email']
                body="You Have Successfully Registered on E-marketPlace"
                subject = 'Registration'
                message = MIMEMultipart()
                message['sender_email']=sender_email
                message['rec_email']=rec_email
                message['subject']=subject
                message.attach(MIMEText(body, 'plain'))
                text = message.as_string()
                mail = smtplib.SMTP('smtp.gmail.com', 587)
                mail.ehlo()
                mail.starttls()
                mail.login(sender_email,password)
                print("login successful")
                mail.sendmail(sender_email,rec_email, text)
                print("email has been sent")

                reg=models.Register()#create object of register table(model)
                reg.username=request.POST['username']#get username from html form
                reg.email=request.POST['email']#get email from html form
                reg.password=request.POST['password']#get password from html form
                reg.mobile=request.POST['mobile']#get mobile no from html form
                reg.save()
            except SyntaxError:
                return HttpResponseRedirect('../register')
            except:
                #n=ToastNotifier()
                #n.show_toast("Registration","oops! Something went Wrong! Check Your Internet Connection",duration=2,icon_path="shop/adduser/")
                return HttpResponseRedirect('../register')
            #n=ToastNotifier()
            #n.show_toast("Register","You Have Successfully Registered on E-MarketPlace",duration=2,icon_path="shop/adduser/")
            return HttpResponseRedirect('../loginPage')
    else:
        s1="not reg"
        return HttpResponse(s1)
Exemple #2
0
def updatePro(request):
    if request.method == "POST":
        form = NewUserForm(request.POST)
        res = models.Register()
        res.id = request.POST['cid']
        res.password = request.POST['password']
        res.username = form.data['username']
        res.email = form.data['email']
        res.mobile = form.data['mobile']
        res.save()
        uname = res.username.split()
        request.session['username'] = uname[0].capitalize()
        print("username is: ", request.session['username'])
        return HttpResponseRedirect("../profile/")