Exemple #1
0
def login():
    form = LoginForm()
    error = None
    
    # if page loads as a GET and with the next then we start a user sessions
    # cookie called session
    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)
        
    if form.validate_on_submit(): #check for author record in db
        author = Author.query.filter_by(
            username=form.username.data
            ).first()
        if author: # if exist create session
            if bcrypt.hashpw(form.password.data, author.password) == author.password:
                session['username'] = form.username.data
                session['is_author'] = author.is_author # true or false
                flash("User %s logged in" % form.username.data)
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:
                error = "Incorrect username and password"
        else:
            error = "Incorrect username and password"
    return render_template('author/login.html', form=form, error=error)
Exemple #2
0
def login():
    error = ''
    form = LoginForm()
    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)
    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data).first()
        if author:
            a = form.password.data
            b = author.password
            c = a.encode('utf8')
            d = b.encode('utf8')
            #if bcrypt.hashpw(form.password.data,author.password)==author.password:
            if bcrypt.hashpw(c, d) == d:
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                session['id'] = author.id
                flash('User %s is loggedin' % (form.username.data))
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:
                error = 'Incorrect username and password'
        else:
            error = 'Incorrect username and password'
    return render_template('author/login.html', form=form, error=error)
def login():
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data, ).first()
        if author:
            if bcrypt.hashpw(form.password.data,
                             author.password) == author.password:
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                flash("User %s logged in" % author.username)
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:
                error = "Incorrect password"
        else:
            error = "Author not found"
    return render_template('author/login.html', form=form, error=error)
Exemple #4
0
def login():
    form = LoginForm()
    error = None
    # if the caling request is GET and next is present
    # create a cookie with the calling url
    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data).first()

        if author:  # ie found records
            if bcrypt.hashpw(form.password.data,
                             author.password) == author.password:
                # Create session
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                flash("User {} logged in".format(form.username.data))
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    # redirect to def index
                    return redirect(url_for('index'))
            else:
                error = "Incorrect username and password"
        else:
            error = "Incorrect username and password"
    return render_template('author/login.html', form=form, error=error)
Exemple #5
0
def login():
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        # looking for author in database with the same username as entered in the form
        author = Author.query.filter_by(
            username=form.username.data
        ).first()  # return first author

        # to check password
        if author:
            if bcrypt.checkpw(form.password.data.encode('utf8'), author.password.encode('utf8')):
                session["username"] = form.username.data  # storing username in the session
                session["is_author"] = author.is_author
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:
                error = "Incorrect username and password"
        else:
            error = "Incorrect username and password"
    return render_template('author/login.html', form=form, error=error)
Exemple #6
0
def login():
    form = LoginForm()
    error = None

    if request.method == get and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data, ).first()
        if author:
            print(
                bcrypt.hashpw(form.password.data.encode('utf8'),
                              author.password.encode('utf8')))
            if bcrypt.hashpw(form.password.data.encode('utf8'),
                             author.password.encode(
                                 'utf8')) == author.password.encode('utf8'):
                session['username'] = form.username.data.encode('utf8')
                session['is_author'] = author.is_author
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                return redirect(url_for('index'))
            else:
                error = '틀린암호/계정임?????'
        else:
            error = '틀린암호/계정임.'

    return render_template('author/login.html', form=form, error=error)
Exemple #7
0
def login():
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    # Verify login details
    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data).first()
        if author:
            if bcrypt.hashpw(form.password.data,
                             author.password) == author.password:

                # Store session data
                session['username'] = form.username.data
                session['is_author'] = author.is_author

                # Redirect to previously attempted page in necessary
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
            else:
                error = "Incorrect username and Password"

            return redirect(url_for('index'))
        else:
            error = "Incorrect username and Password"

    return render_template('author/login.html', form=form, error=error)
Exemple #8
0
def login():
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():

        author = Author.query.filter_by(
            username=form.username.data
        ).first()
        if author:
            # print('count?')
            # author = authors[0]
            # print(author)
            if bcrypt.hashpw(form.password.data.encode('utf8'), author.password.encode()) \
                    == author.password.encode():
                # print('TRUE')
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                if 'next' in session:
                    nexto = session.get('next')
                    session.pop('next')
                    return redirect(nexto)
                else:
                    return redirect(url_for('login_success'))
            else:
                # print('false')
                error = 'incorrect username/passwd'
        else:
            error = 'incorrect username/passwd'

    return render_template('author/login.html', form=form, error=error)
Exemple #9
0
def login():
    """Homepage for user."""
    form = LoginForm()
    error = ""

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():

        authors = Author.query.filter_by(
            username=form.username.data, ).limit(1)
        if authors.count():
            author = authors[0]
            if bcrypt.hashpw(form.password.data,
                             author.password) == author.password:
                session['username'] = form.username.data
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(url_for(next))
                return redirect(url_for('login_success'))
            else:
                error = 'Incorrect username and password'
        else:
            error = 'Incorrect username and password'
    return render_template('author/login.html', form=form, error=error)
Exemple #10
0
def login():
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data).first()

        if author:
            if bcrypt.hashpw(form.password.data,
                             author.password) == author.password:
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                if 'next' in session:
                    next_url = session.get('next')
                    session.pop('next')
                    return redirect(next_url)
                else:
                    return redirect(url_for('login_success'))
            else:
                error = 'Incorrect username and password'
        else:
            error = 'Incorrect username and password'

    return render_template('author/login.html', form=form, error=error)
Exemple #11
0
def login():
    form = LoginForm()
    error = None
    #Check if login page has been an effect of redirection from other page
    if request.method == 'GET' and request.args.get('next'):
        #Save redirection for post login action
        session['next'] = request.args.get('next', None)
    if form.validate_on_submit():
        author = Author.query.filter_by(
            username=form.username.data,
            ).first()
        if author:
            #Interesting stuff you hash form data with salt of author password
            #in order to compare two hashed passwords
            if bcrypt.hashpw(form.password.data,author.password)==author.password:
                #If login was successful save username to the session
                session['username']=form.username.data
                session['is_author']=author.is_author
                if 'next' in session:
                    #If session has set next field perform return back after login
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:#Otherwise return error message
                error = "Incorrect username and password"
        else:#Otherwise return error message
            error = "Incorrect username and password"
    return render_template('author/login.html', form=form, error=error)
Exemple #12
0
def login():
    form = LoginForm()
    data = request.form
    error = None

    username = data.get('username')
    password = data.get('password')

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        author = Author.query.filter_by(username=username,
                                        password=password).limit(1)

        if author.count():
            session['username'] = username
            if 'next' in session:
                next = session.get('next')
                session.pop('next')
                return redirect(next)

            return (redirect(url_for('login_success')))

    return render_template("author/login.html", form=form, error=error)
Exemple #13
0
def login():
    form = LoginForm()
    error = ''

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        salt = bcrypt.gensalt()
        author = Author.query.filter_by(username=form.username.data).first()
        if author:
            if bcrypt.hashpw(form.password.data,
                             author.password) == author.password:
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                flash('User %s logged in' % form.username.data)
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:
                error = 'Invalid username or passowrd'
        else:
            error = 'Invalid username or passowrd'
    return render_template('author/login.html', form=form, error=error)
Exemple #14
0
def login():
    form = LoginForm()
    error = None
    
    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)
    
    if form.validate_on_submit():
        # After password has been hashed, need to change the validation
        # filter_by is like a select with a where
        author = Author.query.filter_by(
            username = form.username.data
        ).first()
        if author:
            # Checking the hashed password
            if bcrypt.hashpw(form.password.data, author.password) == author.password:
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                flash("User %s logged in" % form.username.data)
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    # return redirect(url_for('login_success'))
                    return redirect(url_for('index'))
            else:
                error = "Incorrect username or password"
        else:
            error = "Incorrect username or password"
    return render_template('author/login.html', form=form, error=error)
Exemple #15
0
def login():
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data).first()
        if author:
            spassword = str(form.password.data)
            bpassword = spassword.encode()
            shash_password = author.password
            bhash_password = shash_password.encode()
            if bcrypt.hashpw(bpassword, bhash_password) == bhash_password:
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:
                error = "Incorect username and password"
        else:
            error = "Incorect username and password"
    return render_template('author/login.html', form=form, error=error)
def login():
    form = LoginForm()
    error = None
    
    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)
    if form.validate_on_submit():
        author = Author.query.filter_by(
           username=form.username.data).first()
        if author:
            if bcrypt.hashpw(form.password.data, author.password) == author.password:
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                flash("User %s logged in" % form.username.data)
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:
                error = "Incorrect username and password"
        else:
            error = "Incorrect username and password"
    return render_template('author/login.html', form=form, error=error)
Exemple #17
0
def login():
    #return "Hello, User!"
    form = LoginForm()
    error = None
    
    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next',None)
        
        
    if form.validate_on_submit():
        #return redirect(url_for('loggedin'))
        salt = bcrypt.gensalt()
        hashed_password = bcrypt.hashpw(form.password.data, salt)
#        author = Author.query.filter_by(
#            username = form.username.data,
#            password = form.password.data
#            ).limit(1)
# changed for hashed password
        author = Author.query.filter_by( 
            username = form.username.data
            ).first()
            

            
        if author:
            # bcrypt form data using salt from database password, if they match then ok
            if bcrypt.hashpw(form.password.data, author.password) == author.password:
                
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                #flash("user %s" % form.username.data )
                flash("user %s " % form.username.data)
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else: 
                    return redirect(url_for('index'))
            else:
                error = "Incorrect username and password1"
        else:
            error = "Incorrect username and password2"
    return render_template('author/login.html', form=form, error=error)
Exemple #18
0
def login():
	form = LoginForm()
	error = None

	if request.method == 'GET' and request.args.get('next'):
		session['next'] = request.args.get('next', None)
	if form.validate_on_submit():
		author = Author.query.filter_by(username=form.username.data, password=form.password.data).first()
		print(author)
		if author.count():
			session['username'] = form.username.data
			session['is_author'] = author.is_author
			if 'next' in session:
				next = session.get('next')
				session.pop('next')
				return redirect(next)
			else:
				return redirect(url_for('login_success'))
		else:
			error = "Incorrect username and password"
	return render_template('author/login.html', form=form, error=error)
Exemple #19
0
def login():
    #return "Hello, User!"
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        #return redirect(url_for('loggedin'))
        salt = bcrypt.gensalt()
        hashed_password = bcrypt.hashpw(form.password.data, salt)
        #        author = Author.query.filter_by(
        #            username = form.username.data,
        #            password = form.password.data
        #            ).limit(1)
        # changed for hashed password
        author = Author.query.filter_by(username=form.username.data).first()

        if author:
            # bcrypt form data using salt from database password, if they match then ok
            if bcrypt.hashpw(form.password.data,
                             author.password) == author.password:

                session['username'] = form.username.data
                session['is_author'] = author.is_author
                #flash("user %s" % form.username.data )
                flash("user %s " % form.username.data)
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:
                error = "Incorrect username and password1"
        else:
            error = "Incorrect username and password2"
    return render_template('author/login.html', form=form, error=error)
Exemple #20
0
def login():
    form = LoginForm()
    error = None
    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)
    if form.validate_on_submit():
        authors = Author.query.filter_by(username=form.username.data).limit(1)
        if authors.count():
            author = authors[0]
            if bcrypt.hashpw(form.password.data,
                             author.password) == author.password:
                session['username'] = author.username
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('login_success'))
            else:
                error = "Invalid username or password"
        else:
            error = "Invalid username or password"
    return render_template('author/login.html', form=form, error=error)
Exemple #21
0
def login():

    error = None

    form = LoginForm()

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next')

    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data).first()
        if author:
            if author.is_active:
                check = bcrypt.checkpw(form.password.data.encode('utf8'),
                                       author.password.encode('utf8'))
                if check:
                    session['username'] = form.username.data
                    session['is_author'] = author.is_author
                    session['is_admin'] = author.is_admin
                    session['is_active'] = author.is_active
                    if 'next' in session:
                        next = session.get('next')
                        session.pop('next')

                        return redirect(next)
                    else:
                        flash('Logged in')
                        return redirect(url_for('admin_app.admin'))
                else:
                    error = 'Incorrect Username and Password'
            else:
                error = 'Admin Account locked! Contact Site-Admin...'
        else:
            error = "Incorrect username or password"
            return render_template('author/login.html', form=form, error=error)

    return render_template('/author/login.html', form=form, error=error)
Exemple #22
0
def login():
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get('next', None):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        author = Author.query.filter_by(username=form.username.data).first()
        if author:
            if bcrypt.check_password_hash(author.password, form.password.data):
                session['username'] = form.username.data
                session['is_author'] = author.is_author
                flash('User %s logged in' % author.username)
                if 'next' in session:
                    next = session['next']
                    session.pop('next')
                    return redirect(next)
                return redirect(url_for('index'))
            else:
                error = "Incorrect username and password"
        else:
            error = "Incorrect username and password"
    return render_template("author/login.html", form=form, error=error)
def success():
    form = LoginForm()
    error = None
    flash("Author registered")
    return render_template('author/login.html', form=form)