Beispiel #1
0
def login():
    if current_user.is_authenticated and current_user.manager == True:
        return redirect(url_for('chooseToDo'))
    formLogin = LoginForm()
    if formLogin.Register.data and formLogin.is_submitted():
        return redirect(url_for('register'))
    elif formLogin.ResetPassword.data and formLogin.is_submitted():
        return redirect(url_for('reset'))

    elif formLogin.validate_on_submit():
        user = Employee.query.filter_by(email=formLogin.Username.data).first()
        if user is None or not user.check_password(formLogin.Password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        elif user.firsttimelogin == True:
            login_user(user, remember=formLogin.RememberMe.data)
            flash(
                'Your password has expired. Setup the security questions and submit your answers'
            )
            return redirect(url_for('reset'))
        elif user.manager == True and user.firsttimelogin == False:
            login_user(user, remember=formLogin.RememberMe.data)
            # return to page before user got asked to login
            next_page = request.args.get('next')
            if not next_page or url_parse(next_page).netloc != '':
                next_page = url_for('chooseToDo')
            return redirect(next_page)

    title = "Shifter Scheduling Application"
    return render_template('login.html', title=title, formLogin=formLogin)
Beispiel #2
0
def login():
    if (current_user.is_authenticated):
        return redirect(url_for('index'))
    form = LoginForm()
    if (form.is_submitted()):
        if (form.validate()):
            uname = form.username.data
            pword = form.password.data
            mfaid = form.mfacode.data
            #print(uname+":"+pword+":"+mfaid)
            #grab the user field, and perform a query by it, and grab the first result
            user = User.query.filter_by(username=uname).first()
            #if we get no user (username mismatch) or password is wrong, say invalid
            if (user == None or not user.checkpw(pword)):
                return render_template(
                    'login_results.html',
                    title='Login Failed',
                    form=form,
                    results="Login failure: Incorrect username or password")
            if (not user.checkmfaid(mfaid)):
                return render_template(
                    'login_results.html',
                    title='Login Failed',
                    form=form,
                    results="Login failure: Two-factor auth failure")
            login_user(user)
            return render_template('login_results.html',
                                   title='Login Success',
                                   form=form,
                                   results="Login success")
    return render_template('login.html', title='Sign In', form=form)
Beispiel #3
0
def login():
    form = LoginForm()
    if form.is_submitted():
        username= form.username.data
        newUser = User(id=16,user=username,email="*****@*****.**")
        db.session.add(newUser)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('login.html',  title='Sign In', form=form)
def login():
    form = LoginForm()
    if form.is_submitted():
        if form.username.data == 'admin' and form.password.data == 'toor':
            flash('You have been logged in.', 'success')
            return redirect(url_for('index'))
        else:
            flash('Login unsuccessful. Incorrect username or password',
                  'danger')
    return render_template("login.html", title='Login', form=form)
Beispiel #5
0
def login():
    route_log()
    print("Current_user: "******"You are already logged in.")
        return redirect(url_for("appuser_home"))
    form = LoginForm()
    pythoncom.CoInitialize()
    if request.method == "POST" and form.validate() and form.is_submitted():
        username = form.username.data
        password = form.password.data
        try: # Try to authenticate the user and handle exceptions if they occour
            res = build_log("Trying login for: " + username)
            print(res)
            User.try_login(username, password)
        except ldap.INVALID_CREDENTIALS: # Invalid username or password
            flash("Invalid username or password", "danger")
            res = build_log("Invalid user credentials for: " + username)
            print(res)
            return render_template("login.html", active=5, head_menu=app.config["head_menu"], form=form)
        except ldap.INVALID_DN_SYNTAX or ldap.INVALID_SYNTAX: # Syntax error
            flash("Invalid syntax for login", "danger")
            res = build_log("Invalid syntax for login, user: "******"login.html", active=5, head_menu=app.config["head_menu"], form=form)
        except pyad.invalidResults: # Unable to get the user from ldap_server
            flash("Invalid username or password", "danger")
            res = build_log("Invalid syntax for login, user: "******"login.html", active=5, head_menu=app.config["head_menu"], form=form)
        except ldap.SERVER_DOWN: # Unable to contact dc
            flash("The Domain Controller could not be contacted at this time, please try again later.")
            res = build_log("Domain Controller could no be contacted!")
            return redirect(url_for('appuser_password'))
        user = User(username)
        #print("User: "******"Current_user: "******", is_auth: " + str(current_user.is_authenticated))
        flash("You have been logged in.", 'success')
        res = build_log("Successful login for: " + username)
        print(res)
        return redirect(url_for("appuser_home"))
    if form.errors:
        flash(form.errors, 'danger')
        res = build_log("Form error.")
        print(res)
    return render_template("login.html", active=5, head_menu=app.config["head_menu"], form=form)
Beispiel #6
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm(data=prepopulate_user)
    if form.is_submitted():
        user_ = User.get_user_by_username(form.username.data)
        if not user_:
            flash('Invalid Username or password or register')
            return redirect(url_for('login'))
        login_user(user_)
        try:
            # request.args.get()
            next_page = request.referrer.split('next=%2F')[1]
            if next_page:
                return redirect(url_for(next_page))
        except:
            return redirect(url_for('index'))
    return render_template('login.html', form=form, title='Sign In', current_user=current_user)
Beispiel #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 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)
        ActivityLog.log_event(user, f"Login {user}")  # removed .id
        return redirect(url_for("index"))
    elif form.is_submitted():
        return redirect(url_for("login"))
    else:
        return render_template("login.html",
                               greeting_name=greeting_name(),
                               title="Login",
                               form=form)
Beispiel #8
0
def login():
    form = LoginForm()
    session['auth'] = False
    if request.method == 'POST':
        if form.is_submitted() and form.validate():
            session['login'] = form.login_fld.data
            session['password'] = form.pass_fld.data
            conf = parseconf.ParseConf()
            conf.set_username(session.get('login'))
            conf.set_pass(session.get('password'))
            try:  # Check login and password...
                cisco = ciscoios.CiscoIOS(conf.get_random_acc_host())
                session['auth'] = True
            except ciscoios.NetMikoAuthenticationException:
                session['auth'] = False
                return render_template('login.html', form=form, user=session)
            priv = cisco.show_priv()
            session['priv'] = priv
            return redirect(url_for('findport'))
        else:
            return render_template('login.html', form=form, user=session)
    return render_template('login.html', user=session, form=form)
Beispiel #9
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.is_submitted():
        user = User.query.filter_by(username=form.username.data).first()
        if user == None:
            flash('Login Unsuccessful. Please check username and password.',
                  'danger')
        else:
            if user.is_active == False:
                flash('Login Unsuccessful. Your account is not yet activated.',
                      'danger')
            elif user and bcrypt.check_password_hash(user.password,
                                                     form.password.data):
                login_user(user, remember=form.remember_me.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 username and password',
                      'danger')
    return render_template('login.html', active='login', form=form)