예제 #1
0
 def test_loginSuccess(self):
     response = self.testapp.post('/login/',
                                  forms.LoginForm(username='******',
                                                  password='******').data,
                                  status=302,
                                  headers=self.headers)
     self.assertUserLoggedIn(response)
예제 #2
0
파일: views.py 프로젝트: schajee/ekan
 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
     })
예제 #3
0
    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)
예제 #4
0
파일: account.py 프로젝트: shisanjun/django
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})
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
 def form_login(self):
     return forms.LoginForm(self)
예제 #8
0
 def form(self):
     return forms.LoginForm(self.request.POST)