Exemplo n.º 1
0
def login():
     
    error = None
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit():
        #grab user based on email 
            user = User.query.filter_by(email=form.email.data).first()

        #check if correct password and user found in table
            if user  is not None and user.check_password(form.password.data):   
                login_user(user)

                flash("logged in Successfully")

                #figure out if user was somewhere else 

                next = request.args.get('next')


                #user wasn;t redirected to login  
                if next == None or not next[0] ==  '/':
                    next = url_for('welcome_user')

                #user was redirected 
                
                return redirect(next)

     
        error = "Incorrect Email and/or Password !!"
        return render_template("login.html" , form = form , error = error)
   
    return render_template("login.html" , form = form , error = error)
Exemplo n.º 2
0
def login():
    #FB login check db
    if request.method == 'POST':
        email = request.form['email']
        user = User.query.filter_by(email=email).first()
        if user is None:
            user = User(email=email, username=email, password='******')
            db.session.add(user)
            db.session.commit()
            user = User.query.filter_by(email=email).first()
        login_user(user)
        print(email)

    ##normal login##
    form = LoginForm()
    if form.validate_on_submit():
        # Grab the user from our User Models table
        user = User.query.filter_by(email=form.email.data).first()
        if user.check_password(form.password.data) and user is not None:
            # Log in the user
            login_user(user)
            flash('Logged in successfully.')
            next = request.args.get('next')
            if next == None or not next[0] == '/':
                next = url_for('welcome_user')
            return redirect(next)
    return render_template('login.html', form=form)
Exemplo n.º 3
0
def login():

    form = LoginForm()

    if form.validate_on_submit():

        user = User.query.filter_by(email=form.email.data).first()

        if user is None:
            flash('You are not in the database, please register')
            # return render_template('cond.html')
            return redirect(url_for('register'))


        elif user.check_password(form.password.data) and user is not None:

            login_user(user)
            session["user"] = user
            flash('Logged in successfully!')

            next = request.args.get('next')

            if next == None or not next[0]=='/':
                next = url_for('welcome_user')

            return redirect(next)

        else:
            flash('Login is ok, password is WRONG - please check your password...')
            return redirect(url_for('login'))



    return render_template('login.html', form=form)
Exemplo n.º 4
0
def login():

    form = LoginForm()
    if form.validate_on_submit():

        user = User.query.filter_by(email=form.email.data).first()
        try:
            if user.check_password(form.password.data) and user is not None:

                login_user(user)
                flash('Logged in successfully')

                next = request.args.get('next')

                if next == None or not next[0] == '/':
                    next = url_for('index')

                return redirect(next)
            else:
                flash("Incorrect Password!")
                return redirect(url_for('login'))
        except AttributeError:
            flash("Email doesn't exist. Kindly register.")
            return redirect(url_for('login'))

    return render_template('login.html', form=form)
Exemplo n.º 5
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        # Grab the user from our User Models table
        user = User.query.filter_by(email=form.email.data).first()
        # Check that the user was supplied and the password is right
        # The verify_password method comes from the User object
        # https://stackoverflow.com/questions/2209755/python-operation-vs-is-not

        if user.check_password(form.password.data) and user is not None:
            #Log in the user
            login_user(user)
            flash('Logged in successfully.')

            # If a user was trying to visit a page that requires a login
            # flask saves that URL as 'next'.
            next = request.args.get('next')

            # So let's now check if that next exists, otherwise we'll go to
            # the welcome page.
            if next == None or not next[0]=='/':
                next = url_for('welcome_user')

            return redirect(next)
    return render_template('login.html', form=form)
Exemplo n.º 6
0
def login():

    form = LoginForm()

    if form.validate_on_submit():
        email = form.email.data
        password = form.password.data
        user = User.query.filter_by(email=email).first()

        if user.check_password(password) and user is not None:
            login_user(user)
            flash('Login Success!')
            """
                if a user trying to visit a page that requires login, we can
                save that as 'next'. for instance, if a user trying to access
                the welcome_user page and login was reuired, Flask saves that
                actual request for that page as next. we grabbing it from
                request. and redirecting to that page.
            """
            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('welcome_user')

            return redirect(next)

    return render_template('login.html', form=form)
Exemplo n.º 7
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash('Login is succesfully!')
            next = request.args.get('next')
            if next == None or not next[0] == '/':
                next = url_for('welcome_user')
            return redirect(next)
    return render_template('login.html', form=form)
Exemplo n.º 8
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user.check_password(form.password.data) and user is not None:
            login_user(user, remember=True)
            flash("Logged in successfully!")

            next = request.args.get('next')
            if next is None or not next[0] == '/':
                next = url_for('index')
            return redirect(next)
    return render_template('login.html', form=form, current_user=current_user)
Exemplo n.º 9
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        user = User.query.filter_by(username=username).first()
        if user and user.check_password(password):
            login_user(user)
            session['current_user_id_typemaster'] = user.id
            flash('Welcome ' + user.name, 'primary')
            return redirect(url_for('index'))
        else:
            flash('Some error occoured', 'danger')
    return render_template('login.html', form=form)
Exemplo n.º 10
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 username and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
Exemplo n.º 11
0
def login():
    """
	Nos permite loguear un usuario en base al mail y la verificación de la
	contraseña.
	"""
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash("Logged in Successfully!")
            next = request.args.get('next')
            if next is None or not next[0] == '/':
                next = url_for('welcome_user')
            return redirect(next)
    return render_template('login.html', form=form)
Exemplo n.º 12
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        try:
            if check_password_hash(user.password_hash,
                                   form.password.data) and user is not None:
                login_user(user)
                flash("You logged in successfully")
                next = request.args.get('next')
                if next == None or not next[0] == '/':
                    next = url_for('index')
                return redirect(next)
        except AttributeError:
            redirect(url_for('login'))
    return render_template('login.html', form=form)
Exemplo n.º 13
0
def login():
    form = LoginForm()

    if current_user.is_authenticated:
        return redirect(url_for('index'))
    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 email or password')
            return redirect(url_for('login'))
        login_user(user)
        return redirect(url_for('index'))
        next = request.args.get('next')

        if next == None or not next[0] == '/':
            next = url_for('blog')
    return render_template('login.html', form=form)
Exemplo n.º 14
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User_Accounts.query.filter_by(
            email_address=form.email_address.data).first()
        if user is None:
            flash('This user does not exist in our system. Please try again.',
                  'UserLogin')

        elif user.check_password(form.password.data) and user is not None:
            login_user(user)
            next = request.args.get('next')
            if next == None or not next[0] == '/':
                next = url_for('home')
            return redirect(next)
        else:
            flash('Invalid username/password combination')
    return render_template('login.html', form=form)
Exemplo n.º 15
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user.check_password(form.password.data) and user is not None:

            login_user(user)
            flash("Logged in Successfully!")

            next = request.args.get("next")

            if next == None or not next[0] == "/":
                next = url_for("welcome_user")

            return redirect(next)
    return render_template("login.html", form=form)
Exemplo n.º 16
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.check_password(form.password.data) and user is not None:
            login_user(user)  #imported the function
            flash("Logged in successfully!")
            #next holds the actual requested page of the user without logging in
            next = request.args.get(
                'next'
            )  #if a user tries to access the welcome page without logging in then first flask asks the user to login and then saves the welcome bage in next so that after login the user is immediately directed to that page

            if next == None or not next[0] == '/':
                next = url_for('welcome')

            return redirect(next)

    return render_template('login.html', form=form)
Exemplo n.º 17
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            flash("No account exists in that email")

        elif user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash("Logged in Successfully")
            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('welcome_user')
            return redirect(next)
        else:
            flash(f"Please check your password")
    return render_template('login.html', form=form)
Exemplo n.º 18
0
def login():

     form = LoginForm()
     if form.validate_on_submit():
         user = User.query.filter_by(email = form.email.data).first()

         if user.check_password(form.password.data) and user is not None:
             login_user(user)

             flash('Logged in successfully')

             next = request.args.get('next')   #if user is trying to go to page which required login we can use next
# checking if next exist otherwise we go to welcone user page
             if next == None or not next[0] == '/':
                 next = url_for('welcome_user')

             return redirect(next)

     return render_template('login.html',form=form)
Exemplo n.º 19
0
def log_in():
    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user is None:
            flash("The email is wrong!")
            return render_template('login.html', form=form)

        if not user.check_password(form.password.data):
            flash("The password is wrong!")
            return render_template('login.html', form=form)

        login_user(user)
        flash('You logged successfully!')
        return redirect(url_for('home'))

    return render_template('login.html', form=form)
Exemplo n.º 20
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        # Grab the user from our User Models table
        user = User.query.filter_by(email=form.email.data).first()

        if (form.email.data == "*****@*****.**"
                and form.password.data == "admin" and user is None):
            user = User(email=form.email.data,
                        username="******",
                        password=form.password.data,
                        job="admin",
                        name="admin",
                        phone="123",
                        profile_image="default_profile.jpg")

            db.session.add(user)
            db.session.commit()

        if user is not None:

            if user.check_password(form.password.data):
                #Log in the user

                login_user(user)
                flash('Logged in successfully.')

                next = request.args.get('next')

                if next == None or not next[0] == '/':
                    next = url_for('home')

                return redirect(next)

            else:
                flash('Password is not correct')

        else:
            flash('Email is not correct')

    return render_template('login.html', form=form)
def login():
    form = LoginForm(request.form)
    if form.validate():
        user = None
        user = User.query.filter_by(email=request.form['email']).first()
        if user != None:
            if user.check_password(
                    request.form['password']
            ) and request.form['email'] == "*****@*****.**":
                login_user(user)
                return redirect(url_for('adminhome'))

            if user.check_password(request.form['password']):
                login_user(user)
                flash(
                    "Login Successful!! Now you can start shopping. Have a nice day!"
                )
                return redirect(url_for('home'))
        flash("Incorrect E-mail or Password")
    return render_template('login.html', form=form)
Exemplo n.º 22
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        # Grab the user from our User Models table
        user = User.query.filter_by(email=form.email.data).first()

        if user.check_password(form.password.data) and user is not None:
            #Log in the user

            login_user(user)
            flash('Logged in successfully bro.')
            next = request.args.get('next')

            # So let's now check if that next exists or no, otherwise it'll go to
            # the welcome page.
            if next == None or not next[0] == '/':
                next = url_for('welcome_user')

            return redirect(next)
    return render_template('login.html', form=form)
Exemplo n.º 23
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.check_password(
                form.password.data
        ) and user is not None:  #if the password matches, and the user exists
            login_user(user)  # the function logs in the user for us
            flash('logged in successfully')
            # if the user was trying to get to a certain page that needed logging in
            # and was redirected to the login form,
            # that page gets saved in request.args.get('next'),
            # and after logging in the user will be redirected to it
            # if the user entered directly to the login form, then it will be redirected to the 'welcome_user' page
            next = request.args.get('next')
            if next == None or not next[0] == '/':
                next = url_for('welcome_user')
            return redirect(next)

    return render_template('login.html', form=form)
Exemplo n.º 24
0
def login():
    form = LoginForm()

    if current_user.is_authenticated:
        return redirect(url_for('receptionist.index'))

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user is not None and user.check_password(form.password.data):
            login_user(user, remember=form.remember_me.data)

            next = request.args.get('next')
            if next is None or next[0] != '/':
                next = url_for('receptionist.index')

            return redirect(next)

        flash('Incorrect username or password')
        return render_template('receptionist/login.html', form=form)

    return render_template('receptionist/login.html', form=form)
Exemplo n.º 25
0
def login():
    status = True
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user is None:
            status = False
            return render_template('login.html', form=form, status=status)

        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash("You have been logged in successfully")

            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('welcome_user')

            return redirect(next)

    return render_template('login.html', form=form, status=status)
Exemplo n.º 26
0
def login():

    form1 = LoginForm()
    errform = Err()

    if form1.submit.data and form1.validate_on_submit():
        # We 'get' from the database the user that the customer provided.
        # Thats why we use query here. We won't be using query in the registration view... (*)
        user = User.query.filter_by(email=form1.email.data).first()

        # check_password() is the function from our User model from our models.py file
        # the condition before "and" checks if the password is valid.
        # the condition after checks if the user was provided. Basically checking if
        # a user is registered.
        if user.check_password(form1.password.data) and user is not None:
            # This login_user() function is frm the "flask_login" import
            login_user(user)
            flash('Logged in Successfully')

            # this next thing:
            # If a user tries to access a page that requires them to be logged in,
            # but they're currently not logged in then flask can
            # save the page they were requesting as their 'next' request.
            next = request.args.get('next')

            # If next is none, then just go to the welcome page
            if next == None or not next[0] == '/':
                next = url_for('welcome_user')

            # If that oesnt happen, and they DID request something before logging in then...
            # Once they log in, they will be redirected to the page they orginally requested.
            return redirect(next)

    if errform.err.data and errform.validate_on_submit():
        return render_template('error.html')

    # The default view when a person tries to login. I.e: the login page
    # This return statement should be on the top most level of this function. (lined with the first if)
    return render_template('login.html', form1=form1, errform=errform)
Exemplo n.º 27
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        # recebe o user do BD
        user = User.query.filter_by(email=form.email.data).first()

        if user.check_password(form.password.data) and user is not None:

            login_user(user)
            flash('Logged in successfully.')

            # se o user tenta acessar uma pág, mas não está logado, a pág
            # é salva em 'next'
            next = request.args.get('next')

            # se o 'next' n existir, vai para a pág de início
            if next == None or not next[0]=='/':
                next = url_for('welcome_user')

            return redirect(next)
    return render_template('login.html', form=form)
Exemplo n.º 28
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        # Grab the user from our User Models table
        user = User.query.filter_by(email=form.email.data).first()

        # Check that the user was supplied and the password is right
        # The verify_password method comes from the User object
        # https://stackoverflow.com/questions/2209755/python-operation-vs-is-not

        if user is not None and user.check_password(form.password.data):
            #Log in the user

            login_user(user)
            flash('Logged in successfully.')

            mytext = "Welcome to Med Assist " + current_user.username + '.       Logged in successfully.'
            myobj = gTTS(text=mytext, lang=language, slow=False)
            myobj.save("welcome.mp3")
            os.system("mpg123 welcome.mp3")

            # If a user was trying to visit a page that requires a login
            # flask saves that URL as 'next'.
            next = request.args.get('next')

            # So let's now check if that next exists, otherwise we'll go to
            # the welcome page.
            if next == None or not next[0] == '/':

                mongouser = list(
                    mongo.db.user.find({'username': current_user.username}))
                return render_template('welcome_user.html',
                                       mongouser=mongouser)

            return redirect(next)

    return render_template('login.html', form=form)
Exemplo n.º 29
0
def login():

    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user.check_password(form.password.data) and user is not None:

            login_user(user)
            flash('Logged in Successfully!')
            # were flask saves the next page to move
            # if the user trys to enter a page were
            # login status is required
            next = request.args.get('next')

            # If next doesnt exist redirect
            if next is None or not next[0] == '/':
                next = url_for('welcome_user')

            return redirect(next)

    return render_template('login.html', form=form)
def login():

    form = LoginForm()

    if form.validate_on_submit():
        # Get the user by the email provided.
        # first() is used, because emails will be unique.
        user = User.query.filter_by(email=form.email.data).first()

        if user.check_password(
                password=form.password.data) and user is not None:
            login_user(user)
            flash(message='Logged In Succesfully')

            # Next is used when the login view is triggered because tried to visit a page that requires a login.
            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('welcome_user')

            return redirect(next)

    return render_template('login.html', form=form)