Beispiel #1
0
def login():
    if 'username' in session:
        return redirect(url_for('home'))
    if 'admin' in session:
        #database connection
        return redirect(url_for('admin'))
    if request.method == 'POST':
        lsadmin =['admin_north','admin_south','admin_east','admin_west']
        if request.form['username'] in lsadmin:
            if dbHandler.authenticate(request):
                session['admin'] = request.form['username']
                msg = "successful login"
                #rows = dbHandler.retrievePerson(session['username'])
                #print(rows)
                return redirect(url_for('admin'))
            else: 
                msg ="login failed"
                return (render_template('login.html',msg=msg))
        if dbHandler.authenticate(request):
            session['username'] = request.form['username']
            msg = "successful login"
            rows = dbHandler.retrievePerson(session['username'])
            print(rows)
            return redirect(url_for('home'))
        else: 
            msg ="login failed"
    return(render_template("login.html"))
def login():
    context = {}
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        try:
            authenticate(server_uri, domain, username, password)
            return redirect("/loggedin")
        except ValueError as err:
            context["error"] = err.message

    return render_template("login.html", **context)
Beispiel #3
0
def login():
    if (request.method == 'GET'):
        if 'username' in session:
            msg = "Welcome " + session['username'] + "!"
            rest = dbHandler.get_all_restaurant()
            render_template("index.html",
                            restaurants=rest,
                            logged_in=True,
                            message=msg)
        else:
            return render_template("login.html")

    elif (request.method == 'POST'):
        if dbHandler.authenticate(request):
            session['username'] = request.form['username']
            row = dbHandler.get_customer_from_username(
                request.form['username'])

            session['id'] = row[0]
            msg = "Welcome " + session['username'] + "!"
            rest = dbHandler.get_all_restaurant()
        else:

            msg = "Incorrect Credentials."
            return render_template("login.html", message=msg)
    return render_template("index.html",
                           restaurants=rest,
                           logged_in=True,
                           message=msg)
Beispiel #4
0
	def POST(self):	
		id = web.input()
		authenticate = models.authenticate(id)
		if authenticate == True:
			web.seeother('/admin/editable')
		else:
			web.seeother('/admin')
Beispiel #5
0
def main(ctx, metadata_system, source_system, file_type, target_url, username,
         password):
    dt = datetime.datetime.utcnow().isoformat(timespec='seconds')
    log_suffix = f'{dt}.log'
    structlog.configure(processors=[
        structlog.stdlib.filter_by_level, structlog.stdlib.add_log_level,
        structlog.stdlib.PositionalArgumentsFormatter(),
        structlog.processors.TimeStamper(fmt="iso"),
        structlog.processors.JSONRenderer()
    ],
                        context_class=dict,
                        logger_factory=structlog.stdlib.LoggerFactory())
    logging.basicConfig(
        format="%(message)s",
        handlers=[logging.FileHandler(f'logs/log-{log_suffix}', 'w')],
        level=logging.INFO)
    logger.info('Application start')
    header = models.authenticate(target_url, username, password)
    logger.info('Authenticated')
    ctx.obj = {}
    ctx.obj['metadata_system'] = metadata_system
    ctx.obj['source_system'] = source_system
    ctx.obj['file_type'] = file_type
    ctx.obj['target_url'] = target_url
    ctx.obj['header'] = header
Beispiel #6
0
    def validate_password(self, field):
        from flask_login import current_user

        user_cache = authenticate(email=current_user.email,
                                  password=field.data)
        if (not user_cache):
            raise ValidationError(
                "The current password that you entered is wrong.")
Beispiel #7
0
 def validate_password(self, field):
     self.user_cache = authenticate(email=self.email.data,
                                    password=field.data)
     if self.user_cache is None:
         raise ValidationError(
             "Please enter correct information. Note that password is case-sensitive."
         )
     elif not self.user_cache.is_email_activated:
         raise ValidationError("This account is inactive.")
Beispiel #8
0
def test_authenticate():
    """"test authenticate function."""
    with requests_mock.Mocker() as m:
        token = '123abc'.encode('utf-8')
        target_url = 'mock://dos.mock'
        username = '******'
        password = '******'
        m.post(f'{target_url}users/signin', content=token)
        header = models.authenticate(target_url, username, password)
        assert 'Bearer 123abc' == header['Authorization']
Beispiel #9
0
def login():
    error = None
    if request.method == 'POST':
        # if request.form['username'] != 'admin' or request.form['password'] != 'admin':
        if authenticate(request.form['username'], request.form['password']):
            return redirect(url_for('swiper'))
        else:
            error = 'Invalid Credentials. Please try again.'

    return render_template('login.html', error=error)
Beispiel #10
0
def login():
    if 'mobile' in session:
        return redirect(url_for('home'))

    elif request.method == 'POST':
        if dbHandler.authenticate(request):
            session['mobile'] = request.form['mobile']
            msg = "successful login"
            return redirect(url_for('home'))
        else:
            msg ="login failed"
            return render_template("result.html", message=msg)

    return render_template('login.html')
def login():
    try:
        if 'username' in session:
            return redirect(url_for('main'))
        elif request.method == 'POST':
            if dbHandler.authenticate(request):
                session['username'] = request.form['username']
                return redirect(url_for('main'))
            else:
                return render_template('login1.html',
                                       message="Authentication failed.")
        return render_template('login1.html', message="")
    except Exception as e:
        return str(e)
Beispiel #12
0
def home():
    rowss = []
    if 'admin' in session:
        #database connection
        return redirect(url_for('login'))
    if 'username' in session:
        print "yolo"
        dbHandler.calendarGenerate(session['username'])
        rows = dbHandler.retrievePerson(session['username'])
        mess = dbHandler.retrieveTodaysMess(session['username'])
        north = dbHandler.retrieveMessMenuNorth(session['username'])
        south = dbHandler.retrieveMessMenuSouth(session['username'])
        east = dbHandler.retrieveMessMenuEast(session['username'])
        west = dbHandler.retrieveMessMenuWest(session['username'])
        menu = dbHandler.retrieveTodaysMenu(mess,north,south,east,west)
        # print rows 
        return render_template("home.html", row=rows, tbf = mess[0][0].capitalize()
                                                    , tlu = mess[0][1].capitalize()
                                                    , tsn = mess[0][2].capitalize()
                                                    , tdn = mess[0][3].capitalize(),messt=mess,north=north,south=south,east=east,west=west,menu=menu)
    if request.method=='POST':
        if dbHandler.authenticate(request): 
            session['username'] = request.form['username']
            msg = "successful login"
            dbHandler.calendarGenerate(session['username'])
            rows = dbHandler.retrievePerson(session['username'])
            mess = dbHandler.retrieveTodaysMess(session['username'])
            north = dbHandler.retrieveMessMenuNorth(session['username'])
            south = dbHandler.retrieveMessMenuSouth(session['username'])
            east = dbHandler.retrieveMessMenuEast(session['username'])
            west = dbHandler.retrieveMessMenuWest(session['username'])
            menu = dbHandler.retrieveTodaysMenu(mess,north,south,east,west)
            # print rows
            # print rows
            rowss = rows 
            return render_template("home.html", row=rows, tbf = mess[0][0].capitalize()
                                                    , tlu = mess[0][1].capitalize()
                                                    , tsn = mess[0][2].capitalize()
                                                    , tdn = mess[0][3].capitalize(),messt=mess,north=north,south=south,east=east,west=west,menu=menu)
        # return render_template("home.html", row=rowss, tbf = mess[0].capitalize()
        #                                             , tlu = mess[1].capitalize()
        #                                             , tsn = mess[2].capitalize()
        #                                             , tdn = mess[3].capitalize(),north=north,south=south)
    else: 
        msg ="login failed"
        return render_template("login.html", message=msg)
    
    return redirect(url_for('login'))
Beispiel #13
0
def login():
    # context = {}
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']

        try:
            auth = authenticate(server_uri, domain, username, password)
            print(username)
            display_name = auth
            session['logged_in'] = True
            session['display_name'] = display_name
            session['username'] = username
            return redirect(url_for('query_output'))
        except ValueError as err:
            print(err)

    return render_template("login.html")
Beispiel #14
0
def login():
    blogs_sent = dbHandler.getAll()
    if 'username' in session:
        return render_template("admin.html",
                               logged_in=True,
                               username=session["username"],
                               blogs=blogs_sent)
    elif request.method == 'POST':
        if dbHandler.authenticate(request):
            session['username'] = request.form['username']
            return render_template("index.html",
                                   logged_in=True,
                                   username=session["username"],
                                   blogs=blogs_sent)
        else:
            return render_template("login.html",
                                   logged_in=False,
                                   username=None)
    return render_template('login.html',
                           logged_in=False,
                           username=None,
                           blogs=blogs_sent)
Beispiel #15
0
    def validate_password( self, field):
        from flask_login import current_user

        user_cache = authenticate(email=current_user.email, password=field.data)
        if( not user_cache):
            raise ValidationError( "The current password that you entered is wrong.")
Beispiel #16
0
 def validate_password( self, field):
     self.user_cache = authenticate(email=self.email.data, password=field.data)
     if self.user_cache is None:
         raise ValidationError("Please enter correct information. Note that password is case-sensitive.")
     elif not self.user_cache.is_email_activated:
         raise ValidationError("This account is inactive.")
 def test_1_create_user(self):
     isvalid = models.authenticate(self.usern, self.passw)
     self.failUnless(isvalid.username == self.user.name,
                     'user save did not work')
Beispiel #18
0
def authenticate(username,password):
    return models.authenticate(username,password)