def test_loginSuccess(self): response = self.testapp.post('/login/', forms.LoginForm(username='******', password='******').data, status=302, headers=self.headers) self.assertUserLoggedIn(response)
def login(cls, request): if request.method == 'GET': form = forms.LoginForm() elif request.method == 'POST': form = forms.LoginForm(request.POST) if form.is_valid(): # Authenticate username and password username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate( request, username=username, password=password) # If authenticated if user is not None: # Login user - return back login(request, user) return redirect(reverse('web:home')) return render(request, 'auth/login.html', { 'form': form })
def test_loginInvalid(self): response = self.testapp.post('/login/', forms.LoginForm( username='******', password='******').data, status=302, headers=self.headers) self.assertNotIn(self.cookie_name, response.cookies_set) response = response.follow(status=200, headers=self.headers) self.assertTextInErrorMessage('Login invalid', response)
def login(request): """ 登陆 :param request: :return: """ if request.method == "GET": obj = forms.LoginForm() return render(request, 'login.html', {"obj": obj}) if request.method == "POST": obj = forms.LoginForm(request.POST) if obj.is_valid(): if request.session['CheckCode'].lower() == request.POST.get( 'check_code').lower(): request.session["username"] = obj.cleaned_data.get("username") request.session["is_login"] = True if obj.cleaned_data.get("cookietime"): request.session.set_expiry(30 * 24 * 60 * 60) return redirect(reverse("index")) else: return render(request, 'login.html', {"obj": obj}) else: return render(request, 'login.html', {"obj": obj})
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = forms.LoginForm(request.form) if form.validate(): user = User.get(User.username == form.username.data) if user is None or user.password_hash != hashlib.sha256(form.password.data.encode('UTF-8')).hexdigest(): flash('Invalid username or password') return redirect(url_for('frontend.login')) login_user(user) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('frontend.index') return redirect(next_page) return render_template('login.html', title='Sign In', form=form)
def login(): form = forms.LoginForm() if form.validate_on_submit(): url = "https://localhost:5001/auth" login = {'username': form.email.data, 'password': form.passwd.data} r = requests.post(url, verify=False, data=login) if r.status_code == 200: auth_token = r.json().get('auth_token') url = "https://localhost:5001/users/me" headers = {"Authentication": "JWT " + auth_token} r = requests.get(url, verify=False, headers=headers) user = User(r.json().get("id"), r.json().get("name"), r.json().get("email"), auth_token) login_user(user, remember=form.remember_me.data) return redirect(url_for('index')) elif r.status_code == 401: flash("Invalid username or password") return render_template('login.html', form=form)
def form_login(self): return forms.LoginForm(self)
def form(self): return forms.LoginForm(self.request.POST)