def register(req): if(req.method=='POST'): email=req.POST["email"] username=req.POST["username"] first_name=req.POST["first_name"] last_name=req.POST["last_name"] country=req.POST["country"] phone_number=req.POST["phone_number"] password=req.POST["password"] confirm_password=req.POST["confirm_password"] if(Account.objects.filter(email=email).exists()): messages.error(req,"Email Id already exists") if(Account.objects.filter(username=username).exists()): messages.error(req,"Username already exists") if(password!=confirm_password): messages.error(req,"Passwords doesn't match") else: user1=Account.objects.create_user(email=email,username=username,first_name=first_name,last_name=last_name) user1.country=country user1.phone_number=phone_number user1.set_password(password) user1.save() obj1=SwitchJson(id=user1.id,user=user1) obj1.save() return redirect('/login') else: return render(req,'register.html',navbar(req)) return render(req,'register.html',navbar(req))
def profile(req): if not req.user.is_authenticated : return redirect('%s?next=%s' % (settings.LOGIN_URL, req.path)) obj=list(Account.objects.filter(id=req.user.id).values('id','token'))[0] obj1={ "user" : obj, "switchcounter" : range(1,11)} obj1.update(navbar(req)) return render(req,'demo/index.html',obj1)
def anonymous(req): if (req.method == 'POST'): anonymous = req.POST['anonymous'] obj = AnonymousClass(anonymous=anonymous) obj.save() messages.success(req, "Confession saved") return redirect('/confession') else: return render(req, 'confession.html', navbar(req))
def login(req): if (req.method == 'POST'): email = req.POST['email'] password = req.POST['password'] try: user = authenticate( req, email=Account.objects.get(username=email).email, password=password) except: user = authenticate(req, email=email, password=password) if user is not None: log_in(req, user) return redirect('/profile') else: messages.error(req, "Username or Password does not match") return render(req, 'login.html', navbar(req)) else: return render(req, 'login.html', navbar(req))
def ridikkulus(req): if (req.method == 'POST'): form = RidikkulusForm(req.POST, req.FILES) if (form.is_valid()): form.save() messages.success(req, "Submitted Successfully") else: messages.error(req, 'Submission failed , Enter properly') return redirect('/ridikkulus') else: ob1 = {'form': RidikkulusForm()} ob1.update(navbar(req)) return render(req, 'ridikkulus.html', ob1)