def post(self, request): # pass filled out HTML-Form from View to LoginForm() form = LoginForm(request.POST) if form.is_valid(): # recaptcha stufff clientkey = request.POST['g-recaptcha-response'] secretkey = '6LdkIcMUAAAAAAn4gObgTiuFtBz8pBHBBpUx3PaSs' capthchaData = {'secret': secretkey, 'response': clientkey} r = requests.post( 'https://www.google.com/recaptcha/api/siteverify', data=capthchaData) response = json.loads(r.text) verify = response['success'] print('your success is', verify) username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(request, username=username, password=password) if verify is not False: if user is not None: # create a new entry in table 'logs' login(request, user) print('success login') return HttpResponseRedirect('/') else: return HttpResponseRedirect('login') elif user is not None: # create a new entry in table 'logs' login(request, user) print('success login') return HttpResponseRedirect('/') else: return HttpResponseRedirect('login') return HttpResponse('This is Login view. POST Request.')
def post(self, request): form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(username=username, password=password) if user is not None: login(request, user) return HttpResponseRedirect('/') else: return HttpResponseRedirect('/youtube/login')
def post(self, request): last_login = datetime.datetime.now() username = request.POST.get('username', '') password = request.POST.get('password', '') print('username:'******'password:'******'/panel/home') else: return HttpResponseRedirect('/login_insta')
def post(self, request): form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(request, username=username, password=password) if user is not None: login(request, user) print('Success Login') return HttpResponseRedirect('/') else: return HttpResponseRedirect('/login') return HttpResponse("This is Login View, Post Request")
def get(self, request): if request.user.is_authenticated == False: #return HttpResponse('You have to be logged in, in order to upload a video.') return HttpResponseRedirect('/register') try: channel = Channel.objects.filter(user__username = request.user).get().channel_name != "" if channel: # print("HHHEEEEE ", Channel.objects.filter(user__username = request.user).get().channel_name) form = NewVideoForm() return render(request, self.template_name, {'form':form, 'channel':channel}) except Channel.DoesNotExist: return HttpResponseRedirect('/')
def post(self, req): form = loginForm(req.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(req, username=username, password=password) if user is not None: login(req, user) print('success login') return HttpResponseRedirect('/') else: return HttpResponseRedirect('/') return HttpResponse('This is login view')
def post(self, request): # pass filled out HTML-Form from View to LoginForm() form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(request, username=username, password=password) if user is not None: # create a new entry in table 'logs' login(request, user) print('success login') return HttpResponseRedirect('/') else: return HttpResponseRedirect('login') return HttpResponse('This is Login view. POST Request.')
def post(self, request): ##form = AddVideoForm(request.POST, request.FILES) form = AddVideoForm(request.POST, request.FILES) ##print(request.POST) print(request.FILES) if form.is_valid(): print("HEELLEEELOO") title = form.cleaned_data['title'] description = form.cleaned_data['description'] file = form.cleaned_data['file'] randomchar = ''.join( random.choices(string.ascii_uppercase + string.digits, k=5)) path = randomchar + file.name new_video = Video(title=title, description=description, path=path, user=request.user, datetime=timezone.now()) print(dir(new_video)) new_video.save() print("VIDEO SAVED") return HttpResponseRedirect('/') else: print("FORM NOTD VALID") return HttpResponse('<h1>THis is the post</h1>')
def post(self, request): form = CommentForm(request.POST) if form.is_valid(): print("FORM IS VALID") text = form.cleaned_data['text'] video_id = request.POST['video'] video = Video.objects.get(id=video_id) new_comment = Comment(text=text, datetime=timezone.now(), video=video, user=request.user) new_comment.save() return HttpResponseRedirect('/video/{}'.format(str(video_id))) else: video_id = request.POST['video'] return HttpResponseRedirect('/video/{}'.format(str(video_id)))
def get(self, request): if request.user.is_authenticated: print('already logged in. Redirecting.') print(request.user) return HttpResponseRedirect('/') form = forms.RegisterForm() return render(request, 'users/register.html', {'form': form})
def post(self, request): form = NewVideoForm(request.POST, request.FILES) if form.is_valid(): title = form.cleaned_data['title'] description = form.cleaned_data['description'] file = form.cleaned_data['file'] random_char = ''.join( random.choices(string.ascii_uppercase + string.digits, k=10)) path = random_char + file.name fs = FileSystemStorage(location=os.path.dirname( os.path.dirname(os.path.abspath(__file__)))) filename = fs.save(path, file) file_url = fs.url(filename) print(fs) print(filename) print(file_url) new_video = Video(title=title, description=description, user=request.user, path=path) new_video.save() return HttpResponseRedirect('/video/{}'.format(new_video.id)) else: return HttpResponse( 'Your form is not valid. Go back and try again.')
def get(self, request): if request.user.is_authenticated == False: return HttpResponseRedirect('/register') form = NewVideoForm() return render(request, self.template_name, {'form': form})
def post(self, request): # pass filled out HTML-Form from View to NewVideoForm() form = NewVideoForm(request.POST, request.FILES) print(form) print(request.POST) print(request.FILES) if form.is_valid(): # create a new Video Entry title = form.cleaned_data['title'] description = form.cleaned_data['description'] file = form.cleaned_data['file'] random_char = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10)) path = random_char+file.name new_video = Video(title=title, description=description, user=request.user, path=path) new_video.save() # redirect to detail view template of a Video return HttpResponseRedirect('/video/{}'.format(new_video.id)) else: return HttpResponse('Your form is not valid. Go back and try again.')
def post(self, request): # pass filled out HTML-Form from View to RegisterForm() form = RegisterForm(request.POST) if form.is_valid(): # create a User account print(form.cleaned_data['username']) username = form.cleaned_data['username'] password = form.cleaned_data['password'] email = form.cleaned_data['email'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] birth = form.cleaned_data['birth'] try: with transaction.atomic(): # All the database operations within this block are part of the transaction user = CustomUser.objects.create_user( email=email, username=username, password=password, first_name=first_name, last_name=last_name, birth=birth) except DatabaseError: # The transaction has failed. Handle appropriately pass return HttpResponseRedirect('/login') return HttpResponse('Введены некорректные данные')
def btn_click(request, id): if request.user.is_authenticated: video = get_object_or_404(Video, pk=id) video.delete() return HttpResponseRedirect('/my_videos') else: return HttpResponse('Вы не являетесь пользователем данной видеотеки')
def get(self, request): if request.user.is_authenticated: #logout(request) return HttpResponseRedirect('/') form = LoginForm() return render(request, 'core/login.html', {'form': form})
def post(self, request): ''' Validate input from edit user and modify entry ''' form = EditUserForm(request.POST, request.FILES) id = request.user.id if form.is_valid(): try: user_by_id = User.objects.get(id=id) except ObjectDoesNotExist: return render( request, "error.html", {'error': "Error: Invalid user ID. User does not exist!"}) password = form.cleaned_data['password'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] if password != '': user_by_id.set_password(password) if first_name != '': user_by_id.first_name = first_name if last_name != '': user_by_id.last_name = last_name user_by_id.save() return HttpResponseRedirect('/') else: return render(request, "error.html", {'error': "Error: Inavlid Form Input!"})
def post(self, request): ''' Post comment on video if user is authenticated ''' form = CommentForm(request.POST) if form.is_valid(): # Create Comment comment = form.cleaned_data['text'] video_id = request.POST['video'] # Throw exception if video does not exist try: video = Video.objects.get(id=video_id) except ObjectDoesNotExist: return render(request, "error.html", { 'error': "Error: Invalid Video URL. Video does not exist!" }) # Handle case if video is private and not owned by user if video.is_private and request.user.id != video.user_id: return render(request, "error.html", { 'error': "Error: Invalid video URL. video does not exist!" }) new_comment = Comment(user=request.user, text=comment, video=video) new_comment.save() return HttpResponseRedirect('/video/{}'.format(str(video_id))) else: return render(request, "error.html", {'error': "Error: Inavlid Form Input!"})
def post(self, request, id): ''' Like/unlike specified video ''' # Throw exception if video does not exist try: video_by_id = Video.objects.get(id=id) except ObjectDoesNotExist: return render( request, "error.html", {'error': "Error: Invalid Video URL. Video does not exist!"}) like = request.POST['like'] # Add/remove userID to liked IDs if like == 'True': if request.user.id not in video_by_id.likes: video_by_id.likes.append(request.user.id) else: video_by_id.likes.remove(request.user.id) # Compute number of likes video_by_id.num_likes = len(video_by_id.likes) video_by_id.save() return HttpResponseRedirect('/video/{}'.format(id))
def post(self, request): # pass filled out html form View to NewVideoForm() form = CommentForm(request.POST) # check if the the form is valid if form.is_valid(): # create a comment entry text = form.cleaned_data['text'] print(dir(request)) print(form.data) print(request.POST) print(dir(form)) video_id = request.POST['video'] video = Video.objects.get(id=video_id) new_comment = Comment(text=text, user=request.user, video=video) new_comment.save() print(new_comment) return HttpResponseRedirect('/video/{}'.format(str(video_id))) return HttpResponse("This is Comment view post request")
def post(self, request): # pass filled out HTML-Form from View to NewVideoForm() form = NewVideoForm(request.POST, request.FILES) if form.is_valid(): # create a new Video Entry title = form.cleaned_data['title'] description = form.cleaned_data['description'] file = form.cleaned_data['file'] random_char = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10)) path = random_char+file.name print("TTTTTTT ",path) fs = FileSystemStorage(location = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) filename = fs.save("youtube/static/videos/"+path, file) file_url = fs.url(filename) print(fs) print(filename) print(file_url) new_video = Video(title=title, description=description, user=request.user, path=path) new_video.save() # redirect to detail view template of a Video return HttpResponseRedirect('/video/{}'.format(new_video.id)) else: return HttpResponse('Your form is not valid. Go back and try again.')
def get(self, request): if request.user.is_authenticated: #logout(request) return HttpResponseRedirect('/') form = LoginForm() return render(request, self.template_name, {'form': form})
def get(self, request): if request.user.is_authenticated: print('already logged in. Redirecting.') print(request.user) return HttpResponseRedirect('/') form = RegisterForm() return render(request, self.template_name, {'form': form})
def get(self, request): if request.user.is_authenticated == False: #return HttpResponse('You have to be logged in, in order to upload a video.') return HttpResponseRedirect('/register') form = NewVideoForm() return render(request, self.template_name, {'form': form})
def get(self, request): variable = "NEWVIDEO" if request.user.is_authenticated: print("USER IS ALREADY LOGGED IN aaaaa") print(request.user) return HttpResponseRedirect('/') form = RegisterForm() return render(request, self.template_name, {'form': form})
def post(self, request): try: username = request.POST.get('username', '') password = request.POST.get('password', '') print(username) print(password) user = authenticate(password=password, username=username) if user is not None: login(request, user) print("login is true") return HttpResponseRedirect('/login_insta') else: return HttpResponseRedirect('/view_login') return render(request, 'website/view_login.html') except Exception as e: print(e)
def get(self, request): variable = "NEWVIDEO" if request.user.is_authenticated: form = AddVideoForm() return render(request, self.template_name, {'form': form}) else: print("USER NOT LOGGED IN ") return HttpResponseRedirect('/login')
def get(self, req): if req.user.is_autehnticated: print('already logged in') print(req.user) return HttpResponseRedirect('/') form = registerForm() context = {'form': form} return render(req, self.template_name, context)
def get(self, request): variable = "NEWVIDEO" if request.user.is_authenticated: print('already logged in ..... ') print(request.user) return HttpResponseRedirect('/') form = LoginForm() return render(request, self.template_name, {'form': form})
def get(self, request): if request.user.is_authenticated: print("User already logged in, redirecting.") print(request.user) return HttpResponseRedirect('/') form = SignInForm() return render(request, self.template_name, {'form': form})