Beispiel #1
0
def password_verification():
    """
    Display website with login form. If correct password is submitted redirects to main_page

    :return: form page id failed counter is valid or blocking page if is not
    """
    if failed.is_valid():
        form = LoginForm()
        if form.validate_on_submit():
            user_verification = UserPasswordVerification(
                form.user.data, form.password.data)
            user.name = user_verification.user
            print(user_verification.verified)
            if user_verification.verified:
                user.pass_verified = True
                return redirect(url_for('main_page'))
            else:
                user.pass_verified = False
                failed.add()
        return render_template('password.html',
                               title="PasswordVerification",
                               form=form,
                               log=master_log)
    else:
        return redirect(url_for('block'))
Beispiel #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index.index'))
    else:
        form = LoginForm()
        if form.validate_on_submit():
            with db.connection.cursor() as cursor:
                sql = "SELECT * FROM user WHERE email=%s"
                cursor.execute(sql, (form.email.data, ))
                user = cursor.fetchone()

                if user is None:
                    flash('Invalid username or password')
                    print("no user")
                    return redirect(url_for('user.login'))

                if check_hash(form.passwort.data, user['password']):
                    user_login = LUser(user['id'], user['email'],
                                       user['first_name'], user['last_name'],
                                       user['password'])
                    login_user(user_login, remember=form.remember_me.data)
                    return redirect(url_for('index.index'))

                flash('Invalid username or password')
                print("wrong password")
                return redirect(url_for('user.login'))

    return render_template('login.html', form=form, login=True)
Beispiel #3
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash('Login requested for user {}, remember_me={}'.format(
            form.username.data, form.remember_me.data))
        return redirect('/index')
    return render_template('login.html', title='Sign In', form=form)
Beispiel #4
0
def login():
    form = LoginForm()
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    if request.args.get('error'):
        error = request.args.get('error')
    else:
        error = None
    if request.method == 'POST' and form.validate_on_submit():
        try:
            _id, password = int(form.student_id.data), form.password.data
        except ValueError:
            return redirect(url_for('auth.login', error = "Invalid User ID."))
        if not check_password(password):
            error = "Invalid Password."
        else:
            user = database.find_user_by_id(_id)
            if user:
                if user.validate_password(password):
                    login_user(user, remember=False)
                    return redirect(url_for("home"))
                else:
                    error = "Invalid Password."
            else:
                error = "User not Found."
    return render_template("login.html", form=form, error=error)
Beispiel #5
0
def login():

    # if user is already logged in
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = LoginForm()

    if form.validate_on_submit():
        username = request.form['username']
        password = request.form['password']

        find_user = Database.find_one('users', {'username': username})

        # checks if the login is valid
        if User.login_valid(username, password, bcrypt):

            log_user = User(find_user['username'], find_user['password'],
                            find_user['profile_image'], find_user['_id'])
            login_user(log_user, remember=form.remember.data)
            next_page = request.args.get('next')
            User.login(username)
            flash('Login successful', 'success')

            return redirect(next_page) if next_page else redirect(
                url_for('home'))

        # if login was not valid session['email'] should be None
        else:
            session['username'] = None
            flash('Check your credentials.', 'danger')

    return render_template('login.html', title='Login', form=form)
Beispiel #6
0
def login():
    """
    User login

    A GET request will redirect to the login view.

    A POST request will check for valid login data.
    Valid login data requires existing user instance with
    matching username, password, and email.
    Success/ failure will result in redirect to homepage/ login respectively.
    """
    form = LoginForm()
    if request.method == 'GET':
        if current_user.is_authenticated:
            return redirect('/')
        else:
            return render_template('pages/login.html', form=form)
    elif request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user is None or not user.check_password(form.password.data):
                flash('Invalid username or password')
                return redirect(url_for('pages.login'))
            login_user(user)
            flash('Logged in successfully.')
            return redirect('/')
        else:
            flash('Provided login details not recognized.')
            return render_template('pages/login.html', form=form)
Beispiel #7
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(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            if request.args.get('next'):
                if "home" in request.args.get('next'):
                    return redirect(
                        url_for('file_and_folders',
                                next_url=request.args.get('next').replace(
                                    "/home", "")))
                else:
                    return redirect(url_for('upload_file'))
            else:
                return redirect(url_for('home'))
        else:
            flash("Login Unsuccessfull, Please check Username or Password",
                  "danger")
    return render_template("login.html",
                           title="File Server | LOGIN",
                           form=form,
                           allow_registractions=allow_registractions)
Beispiel #8
0
def login():
    """
    Login
        Check for valid login information

    Parameters:
        N/A

    Returns:
        Rendered template html

    """
    #handles if someone types in this url when already logged in
    if current_user.is_authenticated:
        return redirect('/')

    current_form = LoginForm()

    if current_form.validate_on_submit():
        user = User.query.filter_by(
            username=current_form.username.data).first()
        if user is None or not user.check_password(current_form.password.data):
            flash('Invalid username or password')
            return redirect('/login')
        login_user(user, remember=current_form.remember_me.data)
        return redirect('/')
    return render_template('Login/login.html',
                           title='Sign In',
                           form=current_form)
Beispiel #9
0
def default_login():
   form = LoginForm()
   if form.validate_on_submit():
      user = User.query.filter_by(user_name = form.user_name.data).first()
      if user is not None and user.password == bcrypt.hashpw(form.password.data, user.password):
         login_user(user, remember = form.remember_me.data)   
         return redirect(request.args.get('next') or url_for('community_page.list'))
         
   return redirect(url_for('account.login'))
Beispiel #10
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == "*****@*****.**" and form.password.data == "password":
            flash("You are logged in!", "success")
            return redirect(url_for("home"))
        else:
            flash("Login failed. Please check username and password.",
                  "danger")
    return render_template("login.html", title="Login", form=form)
Beispiel #11
0
def log_in():
    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 = request.args.get('next')
            return redirect(url_for("home"))
    return render_template("log_in.html", form=form, title="Log in")
Beispiel #12
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        try:
            user = user_service.login_user(form.email.data, form.password.data)
            login_user(user, remember=form.remember.data)
            flash('You have been logged in!', 'success')
            # next_page = request.args.get('next')
            return redirect(url_for('index'))
        except (AttributeError, IntegrityError):
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Beispiel #13
0
def login():
    """Get MAL user credentials and validate through MyAnimeList API"""
    if g.user and g.user.is_authenticated():
        return redirect(url_for('index'))

    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.rememberMe.data
        return after_login(MALB.authenticate(form.username.data, form.password.data))

    return render_template('login.html',
                           title='Sign In',
                           form=form)
Beispiel #14
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).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)
Beispiel #15
0
def signin():
    if current_user.is_authenticated:
        return redirect(url_for('main.main'))

    form = LoginForm()
    if form.validate_on_submit():
        user = form.get_user()
        if user:
            login_user(user)
            return redirect(url_for('main.main'))
    else:
        flash_errors(form)
    return render_template("signin.html", form=form)
Beispiel #16
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('login'))

        # todo: add logging message after user login
        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('index'))
    return render_template("login.html", title="Sign In", form=form)
Beispiel #17
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('login'))
        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)
Beispiel #18
0
def login():
    """
    Login request handler
    """
    if request.method == "GET":
        login_form = LoginForm()
        return render_template("login.html", login_form=login_form)

    elif request.method == "POST":
        login_form = LoginForm(request.form)
        if login_form.validate_on_submit():
            session.update(authenticated=True, username=login_form.email.data)
            return redirect(url_for("content.view"))
        else:
            return render_template("login.html", login_form=login_form)
Beispiel #19
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(username=form.username.data).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')[1:] if request.args.get(
                'next') else 'home'
            return redirect(url_for(next_page))
        else:
            flash("Login Unsuccessfull, Please check Username or Password",
                  "danger")
    return render_template("login.html", title="Flask | LOGIN", form=form)
Beispiel #20
0
def login():
    """
	Login route that authenticates a user with the database using hashed passwords.
	:return: render_template object
	"""
    if current_user.is_authenticated:
        return redirect(
            url_for('main_view.profile', username=current_user.username))
    form = LoginForm()
    if form.validate_on_submit():
        user = login_user_svc(email=form.email.data,
                              password=form.password.data)
        if not user:
            return abort(401, description="Incorrect username and password")
        login_user(user)
        return redirect(url_for('main_view.profile', username=user.username))
    return render_template('login.html', title='login', form=form)
Beispiel #21
0
def login():
    form = LoginForm()
    if form.validate_on_submit():

        attempted_user = User.query.filter_by(
            username=form.username.data).first()

        if attempted_user and attempted_user.check_password_correction(
                attempted_password=form.password.data):
            login_user(attempted_user)
            flash(f"Success! you are logged in as {attempted_user.username}",
                  category='success')
            return redirect(url_for('market'))
        else:
            flash("Username and Password are not match please try again.",
                  category='danger')
    return render_template('login.html', form=form)
Beispiel #22
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).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            next_page = request.args.get('next')

            return redirect(next_page) if next_page else redirect(
                url_for('home'))
        else:
            flash('Email or password are not valid!', 'unsuccess_field')

    return render_template('login.html', title='Login', form=form)
Beispiel #23
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        curr, conn = get_db_connection()
        uid = curr.execute("SELECT user_id FROM users WHERE username = (?)", [
            form.username.data,
        ]).fetchone()
        conn.close()
        if uid:
            uid = uid[0]
        user = load_user(uid)
        if not user 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)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(url_for('index'))

    return render_template('login.html', title='Sign In', form=form)
Beispiel #24
0
def login():
    form = LoginForm()
    if request.method == "POST":
        if form.validate_on_submit():
            email, password = form.data["email"], form.data["password"]
            url = "{}/login".format(USER_MICROSERVICE_URL)
            current_app.logger.debug("URL to user microservice: {}".format(url))
            # Look at https://urllib3.readthedocs.io/en/latest/user-guide.html#certificate-verification
            user, status_code = UserService.login_user(email, password)
            # TODO improve the error code inside the User API
            if user is None and status_code != 404:
                return render_template(
                    "login.html",
                    form=form,
                    _test="error_login",
                    message="Connection refused",
                )

            if user is None and status_code == 404:
                return render_template(
                    "login.html",
                    form=form,
                    _test="error_login",
                    message="User not exist",
                )

            if UserService.log_in_user(user):
                return redirect("/")
            else:
                current_app.logger.error("log in failed")
                return render_template(
                    "login.html",
                    form=form,
                    _test="error_login",
                    message="An error occurred during log in. Please try later",
                )
    return render_template("login.html", _test="first_visit_login", form=form)