Exemple #1
0
def adminLog():
    form = AdminLoginForm()
    if form.validate_on_submit():
        admin = Admin.query.filter_by(name=form.name.data, pwd=form.password.data).all()
        if admin:
            session['identity']= admin[0].system
            if 'name' in session:
                session.pop('name')
            session['name']=admin[0].name
            flash('登录成功!','success')
            if admin[0].system==1:
                return redirect(url_for('#'))
            if admin[0].system==2:
                session['province']=admin[0].province
                return redirect(url_for('situation.admin'))
            if admin[0].system==3:
                return redirect(url_for('.homeAdmin'))
            if admin[0].system==4:
                return redirect(url_for('transport_admin.index'))
            if admin[0].system==5:
                return redirect(url_for('population_admin.index'))
            if admin[0].system==6:
                return redirect(url_for('goods_admin.admin_open'))
        else:
            flash('登录失败!请重新输入账号密码','warning')
    return render_template('adminLog.html', title='Admin-Login', form=form)
Exemple #2
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = AdminLoginForm()
    if form.validate_on_submit():
        user = Admin.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('admin_dashboard'))
    return render_template('login.html', title='Sign In', form=form)
Exemple #3
0
    def index(self):
        form = AdminLoginForm()

        if form.validate_on_submit():
            username = form.username.data
            password = form.password.data
            if username == ADMIN_USER and password == ADMIN_PASS:
                session["admin_username"] = username
                flash('Login successfully!', category='info')
                return redirect('/admin')
            else:
                flash('username or password Wrong', category='warning')
        return self.render('admin_login.html', form=form)
def m_login(request):
    locals().update(csrf(request))
    if request.method == 'POST':
        form = AdminLoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=request.POST.get('username'), 
                                password=request.POST.get('password'))
            if user and user.is_active:
                auth.login(request, user)
                return redirect("/management/")
    else:
        form = AdminLoginForm()
    return render_to_response("m_login.html", locals())
Exemple #5
0
def m_login(request):
    locals().update(csrf(request))
    if request.method == 'POST':
        form = AdminLoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=request.POST.get('username'),
                                password=request.POST.get('password'))
            if user and user.is_active:
                auth.login(request, user)
                return redirect("/management/")
    else:
        form = AdminLoginForm()
    return render_to_response("m_login.html", locals())
Exemple #6
0
    def admin_login():
        form = AdminLoginForm()

        if form.validate_on_submit():
            user = models.User.query.filter_by(email=form.email.data).first()
            if user and user.check_password(form.password.data):
                session.clear()
                session["user_id"] = user.id
                return redirect(url_for("admin.index"))
            else:
                flash("Invalid email or password")
        return render_template("admin/login.html",
                               title="Admin Login",
                               form=form)
Exemple #7
0
 def login_view(self):
     # handle user login
     form = AdminLoginForm()
     if form.validate_on_submit():
         user = form.user.data
         password = form.password.data
         u = User.query.filter_by(username=user).first()
         # print(user, password,u.username, u.password)
         if u and check_password_hash(u.password, password):
             login.login_user(u)
         else:
             flash('invalid username or password')
     if login.current_user.is_authenticated():
         return redirect(url_for('.index'))
     return self.render('admin/index.html', form=form)
Exemple #8
0
def adminlogin():
    if current_user.is_authenticated:
        return redirect(url_for('adminmenu'))
    form = AdminLoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('adminlogin'))
        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('menu'))

    html = render_template('adminlogin.html', title='Admin Sign In', form=form)
    response = make_response(html)
    return response
Exemple #9
0
 def login_view(self):
     # handle user login
     form = AdminLoginForm()
     if form.validate_on_submit():
         user = form.user.data
         password = form.password.data
         u = User.query.filter_by(username=user).first()
         # print(user, password,u.username, u.password)
         if u and check_password_hash(u.password, password):
             login.login_user(u)
         else:
             flash('invalid username or password')
     if login.current_user.is_authenticated():
         return redirect(url_for('.index'))
     return self.render('admin/index.html', form=form)
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = AdminLoginForm()
    if form.validate_on_submit():
        user = Admin.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash("Falscher Benutzername oder falsches Passwort")
            return redirect(url_for('login'))
        login_user(user)
        next_page = request.args.get('next')
        # The second part prevents from redirecting to some foreign webpage
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template('login.html', title='Admin Login', form=form)
Exemple #11
0
def admin_login():
    form = AdminLoginForm()

    # if "admin" in session:
    #     return redirect(url_for("admin.admin_index"))

    if request.method == "POST":
        if form.validate() == False:
            flash("invalid credentials")
            return render_template("admin/login.html", form=form)
        else:
            session["admin"] = form.email.data
            flash("Anda sudah berhasil masuk, selamat!", category="info")
            return redirect(request.args.get("next") or url_for("admin.admin_index"))
    elif request.method == "GET":
        return render_template("/admin/login.html", form=form)
Exemple #12
0
def admin_login():
    if current_user.is_authenticated:
        return redirect(url_for("admin_home"))
    form = AdminLoginForm()

    # POST: If a valid form was submitted
    if form.validate_on_submit():
        admin = Admin.query.filter_by(username=form.username.data).first()
        if admin is None or not admin.check_password(form.password.data):
            return redirect(
                url_for("admin_login", next=request.args.get("next")))
        login_user(admin, remember=False)
        next_page = request.args.get("next")
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for("admin_home")
        return redirect(next_page)

    # GET: Renders the admin login template.
    return render_template("admin_login.html", form=form)
def adminlogin():
    if current_user.is_authenticated and current_user.is_admin == True:
        return render_template('admin/index.html')
    form = AdminLoginForm()
    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('index'))
        else:
            flash(
                "incorrect credentials, please enter valid email and password",
                'danger')

    return render_template('admin/signupAdmin.html',
                           title="Admin login Page",
                           form=form)
Exemple #14
0
def login():
    '''
    This view allows existing administrators to log in in order to access the admin panel.
    '''
    # If user is logged in, redirect to admin panel
    if current_user.is_authenticated:
        return redirect(url_for('admin_panel'))

    form = AdminLoginForm(request.form)

    if form.validate_on_submit():
        # If user successfully submits login information
        user = Admin.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            # If credentials fail
            flash('Invalid username or password')
            return redirect(url_for('login'))
        # In this case, credentials pass
        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('admin_panel'))
    elif form.errors:
        # Display errors
        flash(form.errors)
    return render_template('login.html', title='Sign In', form=form)