예제 #1
0
 def post(self, request, *args, **kwargs):
     form = Loginform(request.POST)
     username = request.POST.get('username')
     password = request.POST.get('password')
     user = authenticate(username=username, password=password)
     if user or form.is_valid():
         if user.is_active:
             login(request, user)
             return HttpResponseRedirect(reverse('home'))
     return render(request, 'login.html', {'form': form})
예제 #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    form = Loginform()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash("Invalid username or password")
            return redirect(url_for("index"))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template("login.html", title="Sign In", form=form)
예제 #3
0
def login():
    log = Loginform()
    if request.method == 'GET':
        return render_template('login.html', form=log)

    elif request.method == 'POST':
        username = log.Username.data
        password = log.Password.data
        messageFail = 'INVALID USERNAME OR PASSWORD'
        messagePass = '******'
        user = Login.query.filter_by(Username=username).first()
        if user:
            if (user.Password == password):
                # return redirect(url_for('details'))
                return render_template("login.html",
                                       form=log,
                                       message=messagePass)
            else:
                return render_template("login.html",
                                       form=log,
                                       message=messageFail)
                print(messageFail)

        # if user and user.Password:
        #     # return redirect(url_for('details'))
        #     return render_template("login.html", form=log, message=messagePass)
        else:
            return render_template("login.html", form=log, message=messageFail)
            print(messageFail)
예제 #4
0
def login():
    log = Loginform()

    if request.method == 'GET':
        return render_template('login.html', form=log, title='Login!')
    elif request.method == 'POST':
        Username = log.Username.data
        password = log.Password.data
        user = Login.query.filter_by(username=Username).first()
        if user:
            if (user.password == password):
                flash('You have successfully logged in!')
                session['user'] = user.id
                return redirect(url_for('registeredbusinesses'))

            else:
                flash('INVALID USERNAME OR PASSWORD')
                return render_template('login.html', form=log)
        else:
            flash('INVALID USERNAME OR PASSWORD')
            return render_template('login.html', form=log)
    else:
        return 'WRONG REQUEST'
예제 #5
0
 def get(self, request, *args, **kwargs):
     form = Loginform()
     return render(request, 'login.html', {'form': form})