Esempio n. 1
0
def admin_login():
    """
    logs admins in the session and redirects to their own interface
    """
    if current_user.is_anonymous:
        pass
    else:
        if current_user.is_admin:
            return redirect(url_for("admin_page"))
    form = AdminLoginForm()
    if form.validate_on_submit():
        nickname = form.data["username"]
        user = get_user(user_id=nickname)
        if user is not None:
            password = form.data["password"]
            if hasher.verify(password, user.password):
                i_am_in = login_user(user, force=True, fresh=False)
                if i_am_in:
                    flash("You have logged in.")
                    next_page = request.args.get("next", url_for("admin_page"))
                return redirect(next_page)
        flash("Invalid credentials.")
    return render_template("admin_login.html",
                           title='Sign In as Admin',
                           form=form)
Esempio n. 2
0
def adminlogin():
    form = AdminLoginForm()
    if form.validate_on_submit():
        if form.admin_id.data == '090078601' and form.password.data == 'niggachu':
            flash('Welcome Admin', 'success')
            return redirect('/admin')
        else:
            flash('Login Unsuccessful. Please check Admin ID or password', 'danger')
    return render_template('adminlogin.html', form=form)
Esempio n. 3
0
def admin_login():
    form = AdminLoginForm()
    if form.validate_on_submit():
        # temporary 'test'/'test'
        if form.login.data == 'test' and form.pswd.data == 'test':
            authorize_admin()
            return redirect(url_for('homepage'))
        else:
            flash('NOPE')
    flash_errors(form)
    return render_template('admin_login.html', form=form)
Esempio n. 4
0
def admin_login():
    form = AdminLoginForm()
    if form.validate_on_submit():
        admin = Admin.query.filter_by(username=form.username.data).first()
        if admin and admin.check_password(password=form.password.data):
            login_user(admin)
            next_page = request.args.get('next')
            return redirect(next_page or url_for("web_admin.view_users"))
        flash("Invalid username and password")
        return redirect(url_for("web_admin.admin_login"))
    return render_template("user_login.html", form=form)
Esempio n. 5
0
def admin_login_page():
    admin_form = AdminLoginForm()
    if admin_form.validate_on_submit():
        username = admin_form.username.data
        password = admin_form.password.data
        if password == 'pass':
            session['logged_in'] = True
            session['role'] = 'admin'
            return redirect(url_for('admin_ui.admin_page', username=username))

    return render_template('roles/admin/admin_login_page.html',
                           form=admin_form)
Esempio n. 6
0
def adminlogin():
    form = AdminLoginForm()
    if form.validate_on_submit():
        if request.method == 'POST':
            name1 = form.name.data
            pass1 = form.password.data
            if name1 == "admin" and pass1 == "admin":
                session['user'] = True
                return redirect(url_for('adminprofile'))
            else:
                flash('Invalid username or password', 'danger')
                return redirect(url_for('adminlogin'))
    return render_template('adminlogin.html', form=form)
Esempio n. 7
0
def login():
    #在template文件夹下创建auth文件夹
    form = AdminLoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is not None and user.verify_password(form.password.data):
            #成功
            login_user(user, form.remember_me.data)
            if user.role.id == 1:
                return redirect(url_for('admin.post'))
            else:
                return redirect(url_for('main.index'))
    return render_template('auth/login.html', form=form), 200
Esempio n. 8
0
def login():
	#在template文件夹下创建auth文件夹
	form = AdminLoginForm()
	if form.validate_on_submit():
		user = User.query.filter_by(username = form.username.data).first()
		if user is not None and user.verify_password(form.password.data):
			#成功
			login_user(user,form.remember_me.data)
			if user.role.id == 1:
				return redirect(url_for('admin.post'))
			else:
				return redirect(url_for('main.index'))
	return render_template('auth/login.html',form = form),200
def adminlogin(): 
    form=AdminLoginForm()
    if form.validate_on_submit():
        reg_password = engine.execute("select Password from Admin_Tab where Name = :a",{'a':form.name.data})
        for row in reg_password:
            reg_details=row
        print(reg_details)
        if bcrypt.check_password_hash(reg_details[0] , form.password.data) :
            flash('Login successful.', 'success')
            current_user = form.name.data
            return redirect(url_for('profile',current_user= current_user,Type_of_User="******"))
        else:
            flash('Login Unsuccessful. Please check EnrollNo and password', 'danger')  
    return render_template('adminlogin.html',title='adminLogin', form=form)
Esempio n. 10
0
def adminlogin():

    form = AdminLoginForm()
    if form.validate_on_submit():
        user = Admin.query.filter_by(email=form.email.data).first()
        if 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('welcome_admin')
                global admin
                admin = True
            return redirect(next)

    return render_template('adminlogin.html', form=form, admin=admin)
Esempio n. 11
0
def login():
    if current_user.is_authenticated:
        flash('Already logged in', 'info')

        return redirect(url_for('landing_page'))

    cur = conn.cursor()
    form = AdminLoginForm()

    if form.validate_on_submit():
        cpf = form.cpf.data
        input_password = form.password.data

        cur.execute(f"""SELECT administrator.cpf, person_name, admin_password
                    FROM administrator, person
                    WHERE administrator.cpf = '{cpf}'
                    AND administrator.cpf = person.cpf;""")
        query_results = cur.fetchall()

        conn.commit()
        cur.close()

        if len(query_results) == 0:
            flash(f'Invalid CPF', 'error')
        else:
            cpf, name, password = query_results[0]

            if input_password == password:
                login_user(admin(cpf, name, password))
                flash(f'You are logged as admin', 'success')

                return redirect(url_for('landing_page'))
            else:
                flash(f'Wrong password', 'error')
    else:
        if form.errors:
            errors = list(form.errors.keys())
            error = errors[0]
            flash(f'Error in {error}: {form.errors[error][0]}', 'error')

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