Ejemplo n.º 1
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['name']).first()
            if user is None:
                error = 'Invalid username or password.'
                return render_template(
                    "login.html",
                    form=form,
                    error=error
                )
            elif bcrypt.check_password_hash(
                user.password, request.form['password']
            ):
                session['logged_in'] = True
                session['user_id'] = user.id
                session['role'] = user.role
                session['name'] = user.name
                flash('Welcome!')
                return redirect(url_for('tasks.tasks'))
        else:
            return render_template(
                "login.html",
                form=form,
                error=error
            )
    if request.method == 'GET':
        return render_template('login.html', form=form)
Ejemplo n.º 2
0
def default():
    form = LoginForm(request.form)
    error = None
    if request.method == 'POST':
        if request.form['submit'] == 'login':
            if form.validate_on_submit():
                user = User.query.filter_by(
                    username=request.form['username']).first()
                print user
                if user is not None and bcrypt.check_password_hash(
                        user.password, request.form['password']):
                    login_user(user)
                else:
                    error = 'Invalid username or password.'
        elif request.form['submit'] == 'signup':
            return redirect(url_for('users.login'))
        elif request.form['submit'] == 'logout':
            logout_user()
            return render_template("index.html",
                                   name="index",
                                   title="Chinese Cooking",
                                   form=form,
                                   user=current_user)

    return render_template("index.html",
                           name="index",
                           title="Chinese Cooking",
                           error=error,
                           form=form,
                           user=current_user)
Ejemplo n.º 3
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            # sqlalchemy query
            user = User.query.filter_by(email=form.email.data).first()

            if user is not None and not user.email_confirmed:
                flash('Please confirm your email first.', 'error')

            elif user is not None and user.is_correct_password(
                    form.password.data):
                user.authenticated = True
                user.last_logged_in = user.current_logged_in
                user.current_logged_in = datetime.now()

                db.session.add(user)
                db.session.commit()
                login_user(user)
                # current_user is a proxy to the current user's object from the User class
                flash(f"Hi {current_user.email}.", 'success')
                return redirect(url_for('user.home'))
            else:
                flash('Error, incorrect login credentials.', 'error')
    return render_template('form_login.html', form=form)
Ejemplo n.º 4
0
def login():

    # Defining the form
    form = LoginForm()

    # Checking if form is valid
    if form.validate_on_submit():
        finalizedData = signInFunc(form.email.data, form.password.data)
        print(finalizedData)
        try:
            if finalizedData['message'] == 'success':
                session['account'] = finalizedData['account']
                session['user'] = finalizedData['user']
                if finalizedData['account']['provider']['is_provider'] == True:
                    print('is provider')
                    print('fixed session')
                    return redirect(
                        url_for('profile.home',
                                username=session['account']['username']))
                else:
                    print('not provider')
                    return redirect(
                        url_for('profile.home',
                                username=session['account']['username']))

            else:
                flash(f'Login failed')
        except Exception as e:
            print(e)
            flash(f'Login failed')

    # Different view for user if provider or consumer
    return render_template('users/login.html', form=form)
Ejemplo n.º 5
0
def login():

    # Defining a variable equal to a form
    form = LoginForm()

    # Checking if form is valid
    if form.validate_on_submit():

        # Running sign in function with form data
        finalizedData = signInFunc(form.email.data, form.password.data)
        print(finalizedData)
        if finalizedData != 'failed':
            try:
                print('aaaaaa\n\n\n')
                print(finalizedData)

                # Putting data in recieved data in sessions
                session['email'] = form.email.data
                session['user'] = finalizedData['user']
                session['tips'] = finalizedData['tips']
                session['websiteData'] = finalizedData['website']
                session['competition'] = finalizedData['competition']

            except Exception as e:
                print(e)
                return redirect(url_for('users.login'))
                flash(f'signin failed')

        return redirect(url_for('dashboard.home'))
    return render_template('users/login.html', title="Login", form=form)
def login():
    current_app.logger.debug('Inside login route of users blueprint')
    user_details = Users.get_current_user()
    user_error_message = None
    pass_error_message = None
    loginform = LoginForm()

    if loginform.validate_on_submit():
        username = loginform.username.data
        password = loginform.password.data
        hashed_password = generate_password_hash(password, method='sha256')
        user_result = Users.get_by_name(name=username)
        if user_result:
            returned_password = user_result.password
            if check_password_hash(returned_password, password):
                session['username'] = user_result.name
                return redirect(url_for('questions.index'))
            else:
                current_app.logger.error('passwords are not matching')
                pass_error_message = "Passwords don't match"
        else:
            current_app.logger.error('User does not exist')
            user_error_message = "User does not exist!"

    return render_template('login.html',
                           user=user_details,
                           user_error=user_error_message,
                           pass_error=pass_error_message,
                           form=loginform)
Ejemplo n.º 7
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = Users.query.filter_by(email=form.email.data).first()
        if user is not None and user.check_password(form.password.data):
            login_user(user)
            return redirect(url_for("core.home", user=user))
    return render_template("login.html", form=form)
Ejemplo n.º 8
0
def login():
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.data['username']).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.data['password']):
            flash('You have successfully logged in!')
            login_user(user)
            return redirect(url_for('hunts.index', user_id=user.id))
        flash('Invalid credentials')
    return render_template('users/login.html', form=form)
Ejemplo n.º 9
0
def login():
    form = LoginForm()

    if form.validate_on_submit():  # request is POST
        user = form.username.data
        flash(f'Welcome {user}', 'info')
        session['username'] = user

        return redirect(url_for('classifier.index'))

    # GET
    return render_template('simple_form.html', form=form, url='users.login')
Ejemplo n.º 10
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(mobile=form.mobile.data).first()
        if user is not None and user.checkPassword(form.password.data):
            login_user(user)
            #For the case where user was earlier trying to visit a page that requires login
            next = request.args.get("next")
            if next == None or not next[0] == "/":
                next = url_for("core.index")
            return redirect(next)
    return render_template("login.html", form=form)
Ejemplo n.º 11
0
def login():
    form = LoginForm()
    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=True)
            flash('Login successful!', 'alert-success')
            next = request.args.get('next')
            if next == None or not next[0] == '/':
                next = url_for('core.index')
            return redirect(next)
    return render_template('login.html', form=form)
Ejemplo n.º 12
0
def yuecai(LearningRecipeName):
    error = None
    ingresobj = Ingre.query.filter(Ingre.recipes.any(recipename=LearningRecipeName)).all()
    ingres = []
    ingresurl = []
    ingresorder = Recipe.query.filter_by(recipename=LearningRecipeName).first().ingresorder.split(" ")
    instruction = Recipe.query.filter_by(recipename=LearningRecipeName).first().instruction.split("|")
    print instruction

    for i in ingresorder:
        for obj in ingresobj:

            if obj.id == int(i):
                ingres.append(obj.ingrename)
                ingresurl.append(obj.url)


    form = LoginForm(request.form)
    formR = AddRecipeForm(request.form)
    if request.method == 'POST':
        if request.form['submit'] == 'login':
            if form.validate_on_submit():
                user = User.query.filter_by(username=request.form['username']).first()
                print user
                if user is not None and bcrypt.check_password_hash(
                    user.password, request.form['password']
                ):
                    login_user(user)

                else:
                    error = 'Invalid username or password.'
        elif request.form['submit'] == 'signup':
            return redirect(url_for('users.login'))
        elif request.form['submit'] == 'logout':
            logout_user()
            return redirect(url_for("home.default"))
        else:
            user=User.query.filter_by(username=current_user.username).first()
            recipe = Recipe.query.filter_by(recipename=request.form['submit']).first()
            if recipe is not None:
                recipes = Recipe.query.filter(Recipe.users.any(username=current_user.username)).all()

                if recipe not in recipes:
                    user.add_recipes([recipe])

                    # commit the changes
                    db.session.commit()
            return redirect(url_for("home.personalpage"))
    if LearningRecipeName == "sliced_cold_chicken" or LearningRecipeName == "bitter_shrimp_ball" or LearningRecipeName == "sichuan_fish":
        return render_template("yuecai.html", title = "Cooking", form=form, instruction=instruction, user=current_user, error=error, LearningRecipeName = LearningRecipeName, ingres=ingres, ingresurl=ingresurl)
    else:
        return render_template("coming.html", title = "Cooking", form=form, user=current_user, error=error, LearningRecipeName = LearningRecipeName)
Ejemplo n.º 13
0
def login():
    form = LoginForm(request.form)
    if form.validate_on_submit():
        authenticated_user = User.authenticate(form.username.data,
                                               form.password.data)
        if authenticated_user:
            session['user_id'] = authenticated_user.id
            flash("You are now logged in!")
            return redirect(url_for('users.index'))
        else:
            flash("Invalid Credentials")
            return redirect(url_for('users.login'))
    return render_template('users/login.html', form=form)
Ejemplo n.º 14
0
def login():
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            found_user = User.query.filter_by(email=form.email.data).first()
            if found_user:
                authenticated_user = bcrypt.check_password_hash(
                    found_user.password, request.form['password'])
                if authenticated_user:
                    session["user_id"] = found_user.id
                    return redirect(url_for('posts.new',
                                            user_id=found_user.id))
                flash("Invalid email or password")
    return render_template('users/login.html', form=form)
Ejemplo n.º 15
0
def login():
	form = LoginForm()
	if request.method == "POST":
		if form.validate_on_submit():
			found_user = User.query.filter_by(username = form.username.data).first()
			if found_user:
				authenticated_user = bcrypt.check_password_hash(found_user.password, request.form['password'])
				if authenticated_user:
					login_user(found_user, remember=True)
					flash("You are now logged in!")
					return redirect(url_for('users.index'))
			flash("Invalid credentials. Please try again.")
			return render_template('users/login.html', form=form)		
	return render_template('users/login.html', form=form)	
Ejemplo n.º 16
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['username']).first()
            if user is not None and bcrypt.check_password_hash(
                    user.password, request.form['password']):
                login_user(user)
                flash('You were signed in. Go crazy.')
                return redirect(url_for('home.home'))
            else:
                error = 'Invalid Credentials. Please try again.'
    return render_template('login.html', form=form, error=error)
Ejemplo n.º 17
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is not None and user.check_password(form.password.data):
            login_user(user)
            # flash(f'Welcome {user.first}') # needs jumbotron on index to display properly
            return redirect(url_for('core.index'))
        else:
            flash(
                f'There is no combination of {form.email.data} with that password'
            )
    else:
        pass
    return render_template('login.html', form=form)
Ejemplo n.º 18
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['name']).first()
            if user is not None and bcrypt.check_password_hash(user.password, request.form['password']):
                session['logged_in'] = True
                session['user_id'] = user.id
                session['role'] = user.role
                session['name'] = user.name
                flash('Welcome!')
                return redirect(url_for('tasks.tasks'))
            else:
                error = 'Invalid username or password.'
    return render_template('login.html', form=form, error=error)
Ejemplo n.º 19
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('messages.message'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(mobile_no=form.mobile_no.data).first()
        if user:
            if encrypt.check_password_hash(user.password, form.password.data):
                login_user(user)
                return redirect(url_for('messages.message'))
            else:
                flash("invalid password or username", "danger")
        else:
            flash("You are not a registered user! Register to login", "danger")
            return redirect(url_for('users.signup'))
    return render_template("login.html", form=form)
Ejemplo n.º 20
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first(
        )  #.fist --> there should be only one user, but .fist gives him in the right format (instead of list array of results)

        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash('you are now logged in!')
            next = request.args.get('next')

            if next == None or not next[0] == '/':
                next = url_for('core.index')
            return redirect(next)
    flash('UserName or Password not correct. Try again!')
    return render_template('login.html', form=form)
Ejemplo n.º 21
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        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)
                flash('Logged in!')
                return redirect(url_for('users.home'))
            else:
                error = 'Invalid Credentials. Please try again.'
        else:
            return render_template('login.html', form=form, error=error)
    return render_template('login.html', form=form, error=error)
Ejemplo n.º 22
0
def login():
    if current_user.is_authenticated:
        flash('You are already logged in!')
        return redirect(url_for('home.home'))

    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash('Login successful!')
            return redirect(url_for('home.home'))
        else:
            error = "User doesn't exist or password incorrect"

    return render_template('login.html', form=form, error=error)
Ejemplo n.º 23
0
def login():
    form = LoginForm(request.form)
    error = None
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(
                username=request.form['username']).first()
            if user is not None and bcrypt.check_password_hash(
                    user.password, request.form['password']):
                # session['logged_in'] = True
                login_user(user)  # (flask_login) session created
                flash('You are logged in.')
                return redirect(url_for('home.home'))
            else:
                error = 'Invalid Credentials. Please try again.'
    return render_template('login.html', form=form, error=error)
Ejemplo n.º 24
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('posts.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('posts.home'))
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', form=form)
Ejemplo n.º 25
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', 'success')
            next = request.args.get('next')
            if not is_safe_url(next):
                return abort(400)
        else:
            flash("Email and/or password not correct", 'danger')
            return redirect('login.html')
        return redirect(next or url_for('users.account'))
    return render_template('login.html',form=form)
Ejemplo n.º 26
0
def personalpage():
    error = None
    recipes = None
    form = LoginForm(request.form)
    if current_user is None:
        title = 'personalpage'
    else:
        title = current_user.username
    if request.method == 'POST':
        if request.form['submit'] == 'login':
            if form.validate_on_submit():
                user = User.query.filter_by(
                    username=request.form['username']).first()
                print user
                if user is not None and bcrypt.check_password_hash(
                        user.password, request.form['password']):
                    login_user(user)
                    title = user

                else:
                    error = 'Invalid username or password.'
        elif request.form['submit'] == 'signup':
            return redirect(url_for('users.login'))
        elif request.form['submit'] == 'logout':
            logout_user()
            return redirect(url_for('home.default'))

    recipes = Recipe.query.filter(
        Recipe.users.any(username=current_user.username)).all()
    recipesNotLearnt = Recipe.query.filter(~Recipe.users.any(
        username=current_user.username)).all()
    recipesname = []
    recipesNotLearntname = []
    for recipe in recipes:
        recipesname.append(recipe.recipename)
    for recipe in recipesNotLearnt:
        recipesNotLearntname.append(recipe.recipename)
    # recipes = db.session.query(Recipe).all()
    # return render_template('personalpage.html', recipes=recipes, recipesNotLearnt = recipesNotLearnt, form=form, user=current_user)  # render a template

    return render_template('personalpage.html',
                           title=title,
                           recipes=recipesname,
                           recipesNotLearnt=recipesNotLearntname,
                           form=form,
                           user=current_user)  # render a template
Ejemplo n.º 27
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("main.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("main.home"))
        else:
            flash(u"Login Unsuccessful. Please check username and password",
                  "danger")
    return render_template("login.html", title="Login Page", form=form)
Ejemplo n.º 28
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] == '/' or next == '/users/logout':
                next = url_for('users.dashboard')

            return redirect(next)

    return render_template('login.html', form=form)
Ejemplo n.º 29
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['name']).first()
            if user is not None and bcrypt.check_password_hash(user.password, request.form['password']):
                session['logged_in'] = True
                session['user_id'] = user.id
                session['role'] = user.role
                session['name'] = user.name
                flash('You are logged in. Schedule like mad!')
                return redirect(url_for('appointments.appointments'))
            else:
                error = 'Could not find any user with provided user name or password.'
                return render_template('login.html', form=form, error=error)
    return render_template('login.html', form=form, error=error)
Ejemplo n.º 30
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user is not None and user.is_correct_password(
                    form.password.data):
                user.authenticated = True
                db.session.add(user)
                db.session.commit()
                login_user(user)
                #flash(f'Thanks for logging in {current_user.email}!', 'success')
                flash('Thanks for logging in, {}'.format(current_user.email))
                return redirect(url_for('recipes.index'))
            else:
                flash('ERROR! Incorrect login credentials.', 'error')
    return render_template('login.html', form=form)
Ejemplo n.º 31
0
def login():
    if current_user.is_active:
        return redirect(url_for("posts.home"))
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=form.username.data).first()
            if user and bcrypt.checkpw(form.password.data.encode('utf-8'),
                                       user.password):
                    login_user(user)
                    flash('You were logged in')
                    return redirect(url_for('posts.home'))
            else:
                    error = "Invalid!"
        else:
            return render_template('login.html', form = form, error=error)
    return render_template('login.html', form=form, error=error)
Ejemplo n.º 32
0
def login():
    error = None
    form = LoginForm(request.form)
    # 
    if request.method == 'POST':
        #   
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['name']).first()
            if user is not None and bcrypt.check_password_hash(user.password, form.password.data ):
                login_user(user)
                flash('Logged in!')
                return redirect(url_for('users.dash', id = user.id))
            else:
                error = "Invalid Credentials, please try again."
                return render_template('login.html',form=form,error=error)
        else:
            return render_template('login.html',form=form,error=error)
    # 
    return render_template('login.html',form=form,error=error)
Ejemplo n.º 33
0
def login():
    if current_user.is_authenticated:
        print(current_user.name)
        return redirect(url_for('main.index'))
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user is not None and sha256_crypt.verify(
                    form.password.data, user.password):
                login_user(user)
                next_page = request.args.get('next')
                flash('You are logged in', 'success')
                return redirect(next_page) if next_page else redirect(
                    url_for('main.index'))
            else:
                flash('Login Unsuccessful. Please check email and password',
                      'danger')
    return render_template('login.html', title='Login', form=form)
Ejemplo n.º 34
0
def personalpage():
    error = None
    recipes = None
    form = LoginForm(request.form)
    if current_user is None:
        title = 'personalpage'
    else:
        title = current_user.username
    if request.method == 'POST':
        if request.form['submit'] == 'login':
            if form.validate_on_submit():
                user = User.query.filter_by(username=request.form['username']).first()
                print user
                if user is not None and bcrypt.check_password_hash(
                    user.password, request.form['password']
                ):
                    login_user(user)
                    title = user

                else:
                    error = 'Invalid username or password.'
        elif request.form['submit'] == 'signup':
            return redirect(url_for('users.login'))
        elif request.form['submit'] == 'logout':
            logout_user()
            return redirect(url_for('home.default'))

    recipes = Recipe.query.filter(Recipe.users.any(username=current_user.username)).all()
    recipesNotLearnt = Recipe.query.filter(~Recipe.users.any(username=current_user.username)).all()
    recipesname = []
    recipesNotLearntname = []
    for recipe in recipes:
        recipesname.append(recipe.recipename)
    for recipe in recipesNotLearnt:
        recipesNotLearntname.append(recipe.recipename)
    # recipes = db.session.query(Recipe).all()
    # return render_template('personalpage.html', recipes=recipes, recipesNotLearnt = recipesNotLearnt, form=form, user=current_user)  # render a template

    return render_template('personalpage.html', title=title, recipes=recipesname, recipesNotLearnt = recipesNotLearntname, form=form, user=current_user)  # render a template
Ejemplo n.º 35
0
def default():
    form = LoginForm(request.form)
    error = None
    if request.method == 'POST':
        if request.form['submit'] == 'login':
            if form.validate_on_submit():
                user = User.query.filter_by(username=request.form['username']).first()
                print user
                if user is not None and bcrypt.check_password_hash(
                    user.password, request.form['password']
                ):
                    login_user(user)
                else:
                    error = 'Invalid username or password.'
        elif request.form['submit'] == 'signup':
            return redirect(url_for('users.login'))
        elif request.form['submit'] == 'logout':
            logout_user()
            return render_template("index.html", name = "index", title = "Chinese Cooking", form=form, user=current_user)


    return render_template("index.html", name = "index", title = "Chinese Cooking", error = error, form=form, user=current_user)