Ejemplo n.º 1
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        login = form.login.data
        password = form.password.data
        s = requests.Session()
        login_edu(s, login, password)
        code = check_login(s)
        next = request.args.get('next')
        if code:
            user = User.query.filter_by(login=form.login.data).first()
            if not user:
                user_data = get_home_params(s)
                if not user_data['avatar']:
                    user_data['avatar'] = url_for('static',
                                                  filename='img/grayman.png')
                new_user = User(login=form.login.data,
                                password=password,
                                name=user_data['name'],
                                avatar=user_data['avatar'])
                db.session.add(new_user)
                db.session.commit()
                login_user(new_user, remember=True)
                login_edu(s, login, password)
                sessions[new_user.login] = s
            else:
                login_user(user, remember=True)
            return redirect(next or url_for('index'))
        else:
            return render_template('auth/login.html',
                                   form=form,
                                   message="Неправильный логин или пароль")

    return render_template('auth/login.html', form=form)
def log_in():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = LoginForm()

    if form.validate_on_submit():
        if User.get_by_credentials(
            email=form.email.data, password=form.password.data
        ):
            user = User.get_by_credentials(
                email=form.email.data, password=form.password.data
            )
            login_user(user=user, remember=form.remember.data)

            if request.args.get('next'):
                return redirect(request.args.get('next'))
            return redirect(url_for('home'))
        else:
            flash(
                message='Login unsuccessful, please check email and password.',
                category='danger'
            )

    return render_template('login.html', titile='Log in', form=form)
Ejemplo n.º 3
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == '*****@*****.**' and form.password.data == 'password':
            flash('You have been logged in!', 'success')
            return redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check username and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
def login():
    if current_user.is_authenticated:
        return redirect(url_for('search'))
    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('login'))
        else:
            login_user(user, remember=form.remember_me.data)
            return redirect(url_for('search'))
    return render_template('login.html', title='Sign In', form=form)
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        print("inside login")
        employee = Employee.query.filter_by(emp_id=form.emp_id.data).first()
        if employee and bcrypt.check_password_hash(employee.password, form.password.data):
            print("inside bcrypt")
            login_user(employee, remember=False)
            print("inside login user")
            return redirect(url_for('home'))
    return render_template("login.html", form=form)
Ejemplo n.º 6
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check email and password', 'danger')
    return render_template('login.html', title='Login', form=form)
Ejemplo n.º 7
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 not None and bcrypt.check_password_hash(
                user.password, form.password.data):
            login_user(user)
            return redirect(url_for('account'))

    return render_template('login.html', title='Login', form=form)
Ejemplo n.º 8
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("render_main_page"))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        print(1, form.username.data, user)
        if user is None or not user.check_password(form.password.data):
            # flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        print(2, form.remember_me.data)
        return redirect(url_for("render_main_page"))
    return render_template('login.html', form=form)
Ejemplo n.º 9
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            database_password = user.password
            form_password = form.password.data
            if database_password == form_password:
                login_user(user, remember=form.remember_me.data)
                flash("Successfully logged in", "success")
                return redirect(url_for('home'))
            else:
                flash(f"Password is incorrect", "warning")
        else:
            flash(f"Username is incorrect", "warning")
    return render_template("login.html", form=form)
Ejemplo n.º 10
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('features.index'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.objects(username=form.username.data).first()
        if user is not None and bcrypt.check_password_hash(
                user.password, form.password.data):
            login_user(user)
            return redirect(url_for('users.account'))
        else:
            flash('Login failed. Check your username and/or password')
            return redirect(url_for('users.login'))

    return render_template('login.html', title='Login', form=form)
Ejemplo n.º 11
0
    def login(self, username="******", password="******"):
        login = SimpleNamespace(
            username=username,
            password=password,
            submit="Login",
        )

        form = LoginForm(formdata=None, obj=login)
        response = self._client.post("/login", data=form.data, follow_redirects=True)
        return response
def login():
		if current_user.is_authenticated:
			return redirect(url_for('dashboard'))


		form = LoginForm()
		if form.validate_on_submit():
			if form.email.data == '*****@*****.**' and form.password.data == 'admin':
				flash('You have been logged in!', 'success')
				return redirect(url_for('home'))
			else:
				user = User.query.filter_by(email= form.email.data).first()
			if user and user.password == form.password.data:
				login_user(user, remember=form.remember.data)
				return redirect(url_for('account'))
			else :
				flash('login Unsuccessful. Please check username and password', 'danger')

		return render_template('login.html', title='Login', form=form)
Ejemplo n.º 13
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        try:
            user = User.query.filter_by(username=username).first()
            hash_check = check_password_hash(user.password_hash, password)
            if hash_check:
                session.clear()
                session['user_id'] = user.id
                if request.form.get('next'):
                    return redirect(request.form.get('next'))
                return redirect(url_for('main.index'))
            form.username.errors.append('Username or Password Incorrect')
        except:
            pass
    rdrct = request.args.get('next', None)
    return render_template('auth/login.html' , next=rdrct, form=form)
Ejemplo n.º 14
0
def test_login_input_validation(client, auth, username, password, message):

    # review = SimpleNamespace(text=comment,submit="Enter Comment")
    # form = MovieReviewForm(formdata=None, obj=review)
    # response = client.post(f"/movies/{guardians_id}", data=form.data, follow_redirects=True)

    auth.register()

    login = SimpleNamespace(username=username,
                            password=password,
                            submit="Login")
    form = LoginForm(formdata=None, obj=login)
    response = client.post("login", data=form.data, follow_redirects=True)

    assert message in response.data
Ejemplo n.º 15
0
    def post(self, *args, **kwargs):

        try:
            pdb.set_trace()

            form = LoginForm()
            email = form.email.data
            password = form.password.data
            user = User.query.filter_by(email=email).first()
            if user.is_active == 1:
                user_id = user.id
                # db.session.add(user)

                # login_user(user)
                session['username'] = user.username
                session["email"] = user.email

                return jsonify({'status': True, 'message': 'login suessfull ', 'data': []})
            else:
                pass
        except:
            return flask.Response(status=400)
Ejemplo n.º 16
0
def login():
    form = LoginForm()
    return render_template('login.html', title='sign in', form=form)