def login_view(request): if request.method == 'POST': form = LoginForm(data=request.POST) if form.is_valid(): user = form.authenticate(request) login(request, user) return redirect('todos:todo-list') else: form = LoginForm() secret = get_secret() naver_request_url = naver_login_url( client_id=secret['NAVER_CLIENT_ID'], redirect_url='http://localhost:8000/naver-login', state='RANDOM_STATE') facebook_request_url = facebook_login_url( client_id=secret['FACEBOOK_CLIENT_ID'], redirect_url='http://localhost:8000/facebook-login', state='RANDOM_STATE') context = { 'login_form': form, 'naver_request_url': naver_request_url, 'facebook_request_url': facebook_request_url, } return render(request, 'members/login.html', context)
def login_view(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): # is_valid() 이후에 self.cleaned_data 가 반환되었다 form.login(request) return redirect('posts:post-list') else: # GET을 할때는 form 형식만 보내주면 되기 때문에 LoginForm 내부에 request.POST를 안넣어 줘도 된다. form = LoginForm() login_base_url = 'https://nid.naver.com/oauth2.0/authorize' login_params = { 'response_type': 'code', 'client_id': SECRETS["NAVER_CLIENT_ID"], 'redirect_url': 'http://localhost:8000/members/naver-login/', 'state': 'RANDOM_STATE', } login_url = '{base}?{params}'.format( base=login_base_url, params='&'.join( [f'{key}={value}' for key, value in login_params.items()])) context = { 'form': form, 'login_url': login_url, } return render(request, 'members/login.html', context)
def login_view(request): if request.user.is_authenticated: return redirect('posts:post-list') elif request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): form.login(request) return redirect('posts:post-list') else: form = LoginForm() login_base_url = 'https://nid.naver.com/oauth2.0/authorize' login_params = { 'response_type': 'code', 'client_id': SECRET['NAVER_CLIENT_ID'], 'redirect_uri': 'http://localhost:8000/members/naver-login/', 'state': 'RANDOM_STATE', } login_url = '{base}?{params}'.format( base=login_base_url, params='&'.join( [f'{key}={value}' for key, value in login_params.items()])) print(login_url) context = {'form': form, 'login_url': login_url} return render(request, 'members/login.html', context)
def test_login_fail_wrong_password(self): member = MemberFactory(username='******') member.set_password('test') member.save() form = LoginForm({ 'username': '******', 'password': '******'}) self.assertFalse(form.is_valid())
def test_login_fail_password_not_set(self): member = MemberFactory(username='******') member.set_password('test') member.save() form = LoginForm({ 'username': '******', 'password': None}) self.assertFalse(form.is_valid())
def test_loging_in_successfully(self): member = MemberFactory(username='******') member.set_password('test') member.save() form = LoginForm({ 'username': '******', 'password': '******'}) self.assertTrue(form.is_valid())
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: # if a user with entered username and password is found: login(request, user) messages.success( request, f'{username}, you have lodged in successfully') return redirect('mysite:show-all-tasks') else: # user not found: either password or username are not found messages.error(request, "Invalid username or password") return render(request, 'registration/login.html', {'form': form}) # I used render instead of redirect because i wanted to show the previous # entered username using form.is_bound else: messages.error(request, "Invalid username or password") return redirect('members:login') # class EditPasswordView(PasswordChangeView): # form_class = PasswordResetForm # template_name = 'registration/change_password.html' # success_url = reverse_lazy('accounts:pass_success') # # # class SignupCreateView(CreateView): # form_class = SignupForm # template_name = 'registration/signup.html' # success_url = reverse_lazy('accounts:login') # # # class EditProfileView(UpdateView): # model = User # form_class = EditProfileForm # template_name = 'registration/edit_profile.html' # success_url = reverse_lazy('questions:all_questions') # # # class PasswordChangeSuccessView(TemplateView): # template_name = 'registration/change-pass-success.html' # # # class ShowProfileView(DetailView): # model = User # template_name = 'accounts/profile_page.html' # class NotificationView(ListView): # model = Notification # template_name = 'accounts/all_notifications.html'
def login_view(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): form.login(request) return redirect('members:index') else: form = LoginForm() context = { 'form': form, } return render(request, 'member/login.html', context)
def login(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): form._login(request) return redirect('posts:post-list') else: form = LoginForm() context = { 'login_form':form, } return render(request, 'members/login.html', context)
def login_page(request): form = LoginForm(request.POST or None) if form.is_valid(): username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') user = authenticate(username=username, password=password) if user is not None: login(request, user) return redirect('members:dashboard') return redirect('members:login') context = { 'form':form } return render(request, 'members/login.html', context)
def login_view(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): login(request, form.user) if request.GET.get('next'): return redirect(request.GET.get('next')) return redirect('posts:post_list') else: form = LoginForm() context = {'form': form, 'FACEBOOK_APP_ID': settings.FACEBOOK_APP_ID} return render(request, 'members/login.html', context)
def connection(request): errors = {'connection': False} if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data["username"] # Nous récupérons le nom d'utilisateur password = form.cleaned_data["password"] # … et le mot de passe user = authenticate(username=username, password=password) #Nous vérifions si les données sont correctes if user: # Si l'objet renvoyé n'est pas None login(request, user) # nous connectons l'utilisateur else: #sinon une erreur sera affichée errors = {'connection': True} return home(request, errors)
def login_view(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.data["username"] password = form.data["password"] user = authenticate(username=username, password=password) if user is not None: login(request, user) return redirect(reverse('projects.views.home')) else: error = u'Les identifiants fornis ne sont pas valides' else: error = u'Veuillez entrer vos identifiants' else: form = LoginForm() return render(request, 'members/login.html', {'form': form})
def login_view(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.data["username"] password = form.data["password"] user = authenticate(username=username, password=password) if user is not None: login(request, user) return redirect(reverse('projects.views.home')) else: error = u'Les identifiants fornis ne sont pas valides' else: error = u'Veuillez entrer vos identifiants' else: form = LoginForm() return render(request, 'members/login.html', {'form': form})
def login_view(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): user = form.user if user is not None: login(request, user) return redirect('posts:post_list') else: form = LoginForm() context = { 'form': form } return render(request, 'members/login.html', context)
def loginRequest(request): if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data.get("username") password = form.cleaned_data.get("password") member = authenticate(username=username, password=password) if member is not None: login(request,member) return HttpResponseRedirect('/members/') else: return render(request, 'members/login.html', {'form':form}) else: return render(request, 'members/login.html', {'form':form}) else: form = LoginForm() return render(request, 'members/login.html', {'form': form})
def login_view(request): if request.method == 'POST': 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) # authenticate -> login, redirect to 'index' if user is not None: login(request, user) return redirect('index') else: form = LoginForm() context = { 'login_form': form, } return render(request, 'members/login.html', context)
def member_signin(request): if request.method == 'POST': form = LoginForm(request, data=request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] hacker = authenticate(username=username, password=password) if hacker is not None: login(request, hacker) return render(request, 'index.html', {'form':form}) else: return render(request, 'index.html', {'form':form}) else: return render(request, 'index.html', {'form':form}) else: form = LoginForm() return render(request, 'index.html', {'form':form})
def login_view(request): """ :param request: :return: """ if request.method == 'POST': form = LoginForm(data=request.POST) if form.is_valid(): user = form.authenticate(request) login(request, user) return redirect('posts:post_list') else: form = LoginForm() context = {'login_form': form} return render(request, 'members/login.html', context)
def login_view(request): # if request.method == 'POST': # username = request.POST['username'] # password = request.POST['password'] # # email = request.POST['email'] # # name = request.POST['name'] # # print(username) # print(password) # user = authenticate(request, username=username, password=password) # # user = authenticate( username=username, password=password) # # return value = kimdooh request없어도 됨 # print(user) # if user is not None: # login(request, user) # return redirect('index') # else: # return redirect('members:login') if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): form.login(request) return redirect('posts:post-list') else: # 입력했던 데이터 안날려먹으려고 이렇게 로직 구 form = LoginForm() login_base_url = 'https://nid.naver.com/oauth2.0/authorize' login_params = { 'response_type': 'code', 'client_id': 'XgjJDOfau4a3p4w7excG', 'redirect_uri': 'http://localhost:8000/members/naver-login/', 'state': 'RANDOM_STATE', } login_url = '{base}?{params}'.format( base=login_base_url, params='&'.join( [f'{key}={value}' for key, value in login_params.items()])) context = { 'form': form, 'login_url': login_url, } return render(request, 'members/login.html', context)
def LoginRequest(request): if request.user.is_authenticated(): return HttpResponseRedirect("/home") if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data["username"] password = form.cleaned_data["password"] member = authenticate(username=username, password=password) if member is not None: login(request, member) return HttpResponseRedirect('/home') else: return render_to_response("login.html", {"form": form, "error": "There is no member with that username and password..."}, context_instance=RequestContext(request)) else: return render_to_response("login.html", {"form": form}, context_instance=RequestContext(request)) else: form = LoginForm() context = {"form": form} return render_to_response("login.html", context, context_instance=RequestContext(request))
def login_view(request): # URL: /members/login/ # config.urls에서 '/members/'부분을 "members.urls'를 사용하도록 include # members.urls에서 '/login/' 부분을 이 view에 연결 # Template: members/login.html # 템플릿에는 아래의 LoginForm인스턴스를 사용 # Form: members/forms.py # LoginForm # username, password를 받을 수 있도록 함 # password는 widget에 PasswordInput을 사용하기. #username, password를 받는 부분 # LoginForm을 사용하도록 수정 # 로그인에 실패했을 경우, Template에 form.non_filed_errors를 사용해서 # 로그인에 실패했다는것을 출력\ context = {} if request.method == 'POST': # username = request.POST['username'] # password = request.POST['password'] # user = authenticate(request, username=username, password=password) form = LoginForm(request.POST) if form.is_valid(): # 주어진 username, password로 # authenticate에 성공했다 # request와 authenticate된 user를 사용해서 # login()처리 후 login(request, form.user) # GET parameter에 'next'가 전달되었다면 # 해당 키의 값으로 redirect # 전달되지 않았으면 'posts:post-list'로 redirect next_path = request.GET.get('next') if next_path: return redirect(next_path) return redirect('posts:post-list') else: form = LoginForm() context['form'] = form return render(request, 'members/login.html', context)
def login_request(request): if request.user.is_authenticated(): return HttpResponseRedirect('/members/profile/') if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] member = authenticate(username=username, password=password) if member is not None: login(request, member) return HttpResponseRedirect('/members/profile/') else: context = {'form': form} else: context = {'form': form} else: form = LoginForm() context = {'form': form} return render_to_response('members/login.html', context, context_instance=RequestContext(request))
def login_view(request): # POST요청일때는 # authentictate -> login후 'index'로 redirect # 실패시에는 다시 GET요청의 로직으로 이동 # # GET요청일때는 # members/login.html파일을 보여줌 # 해당 파일의 form에는 username, password input과 '로그인'버튼이 있음 # form은 method POST로 다시 이 view로의 action(빈 값)을 가짐 # if request.method == 'POST': # # username = request.POST['username'] # password = request.POST['password'] # user = authenticate(request, username=username, password=password) # if user is not None: # login(request, user) # return redirect('index') # return render(request, 'members/login.html') # 2/24 로그인 뷰 form으로 구현해보기 if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): # username = request.POST['username'] # password = request.POST['password'] 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) return redirect('index') else: form = LoginForm() context = { 'login_form': form, } return render(request, 'members/login.html', context)
def login_view(request): context = {} if request.method == 'POST': # 1. request.POST에 데이터가 옴 # 2. 온 데이터 중에서 username에 해당하는 값과 password에 해당하는 값을 각각 # username, password변수에 할당 # 3. 사용자 인증을 수행 # username, password를 밥는 무분을 # LoginForm을 사용하도록 변경 # 로그인에 실패했을경우, Template에 form.non_field_error를 사용해서 로그인이 실패했다는걸 출 form = LoginForm(request.POST) if form.is_valid(): login(request, form.user) next_path = request.GET.get('next') if next_path: return redirect(next_path) return redirect('posts:post-list') else: form = LoginForm() context['form'] = form return render(request, 'members/login.html', context)
def login_request(request): if request.user.is_authenticated(): return HttpResponseRedirect('/members/profile/') if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] member = authenticate(username=username, password=password) if member is not None: login(request, member) return HttpResponseRedirect('/members/profile/') else: context = {'form':form} else: context = {'form':form} else: form = LoginForm() context = {'form':form} return render_to_response( 'members/login.html', context, context_instance=RequestContext(request))
def test_login_fail_wrong_password(self): member = MemberFactory(username='******') member.set_password('test') member.save() form = LoginForm({'username': '******', 'password': '******'}) self.assertFalse(form.is_valid())
def test_loging_in_successfully(self): member = MemberFactory(username='******') member.set_password('test') member.save() form = LoginForm({'username': '******', 'password': '******'}) self.assertTrue(form.is_valid())
def test_login_fail_password_not_set(self): member = MemberFactory(username='******') member.set_password('test') member.save() form = LoginForm({'username': '******', 'password': None}) self.assertFalse(form.is_valid())
def login_view(request): """ Template: templates/members/login.html POST 요청을 처리하는 form 내부에는 input 2개를 가지며, 각각 username, password로 name을 가짐 URL: /members/login/ (members.urls 사용, config.urls에 include해 사용) name: members:login (url namespace 사용) POST 요청시, 예제를 보고 적절히 로그인 처리한 후, index로 돌아갈 수 있도록 함 """ # if request.method == 'POST': # username = request.POST['username'] # password = request.POST['password'] # user = authenticate(request, username=username, password=password) # if user: # login(request, user) # # return render(request, 'index.html') # # return redirect('index') # return redirect('posts:post-list') # else: # return redirect('members:login') # # return render(request, 'members/login.html') # else: # return render(request, 'members/login.html') if request.method == 'POST': # username = request.POST['username'] # password = request.POST['password'] # user = authenticate(request, username=username, password=password) form = LoginForm(request.POST) if form.is_valid(): # user = authenticate(request) # if user: # login(request, user) # return redirect('posts:post-list') # else: # return redirect('members:login') form.login(request) return redirect('posts:post-list') # 아이디 혹은 비밀번호가 잘못되면 members:login 페이지로 다시 load # else: # return redirect('members:login') # # # form.errors가 살아있는 상태 (form 인스턴스가 유지되고 있음) # # 아래 코드와 중복.. # context = { # 'form': form # } # return render(request, 'members/login.html', context) else: form = LoginForm() login_base_url = 'https://nid.naver.com/oauth2.0/authorize' login_params = { 'response_type': 'code', 'client_id': SECRETS['CLIENT_ID'], 'redirect_uri': 'http://localhost:8000/members/naver-login/', 'state': 'RANDOM_STATE' } login_url = '{base}?{params}'.format( base=login_base_url, params='&'.join( [f'{key}={value}' for key, value in login_params.items()])) print('login_url >> ', login_url) context = {'form': form, 'login_url': login_url} return render(request, 'members/login.html', context)