These are chat archives for pythonvietnam/Flask

5th
May 2017
khanvuthy88
@khanvuthy88
May 05 2017 13:37
@1rjun could you show your app structure ?
@1rjun If you are using flask, WTForm, you can create your form and import to your view
import your from to your view
` from .forms import * `
@1rjun Simple login function
@app.route('/Helpdesk/Login',methods=['GET','POST'])
def Login():
    form=FKT_LOGIN()

    if "HelpdeskLogin" in session:
        return redirect('Helpdesk/User')
    if request.method=='POST':
        UserName     = request.form['UserName']
        Password     = request.form['Password']
        UserQuery     = MKT_USER.query.filter(MKT_USER.UserName==UserName).first()

        if UserQuery:

            if check_password_hash(UserQuery.Password,Password):
                login_user(UserQuery)
                session['HelpdeskLogin'] = UserQuery.ID
                session['Sidebar'] = UserQuery.UserName
                session['roleID']=UserQuery.RoleID
                return redirect(url_for('home'))
            else:
                flash('Error This is not validate password')
                return render_template('login.html',form=form,title='Login Form')
        else:
            flash('Error This is not in database')
            return render_template('login.html',form=form,title='Login Form')

    return render_template('login.html',form=form,title='Login Form')
khanvuthy88
@khanvuthy88
May 05 2017 13:43
@1rjun Simple login.html
<form method="POST">
            <div class="body bg-white">

                    {% for message in get_flashed_messages() %}
                        {% if contain(message, "Error") %}
                           <div class="alert alert-danger alert-dismissable">
                                <i class="fa fa-ban"></i>
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <b>Error</b>  {{ message }}
                            </div>
                        {% else %}
                          <div class="alert alert-success alert-dismissable">
                                <i class="fa fa-check"></i>
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <b>Success</b>   {{ message }}
                            </div>
                        {% endif %}
                    {% endfor %}

                    <div class="input-group">
                        <span class="input-group-btn">
                            <button class="btn btn-success" type="button">
                                <i class="fontello-user-1"></i>
                            </button>
                        </span>
                        {{ form.UserName(class="form-control",placeholder="User") }}
                    </div>
                    <br/>
                    <div class="input-group">
                        <span class="input-group-btn">
                            <button class="btn btn-success" type="button">
                                <i class="fontello-lock"></i>
                            </button>
                        </span>
                        {{ form.Password(class="form-control",placeholder="Password") }}
                    </div>
                    <br/>                    
                    {{ form.Login(class="pull-right btn btn-success") }}
                    <br/>

                   <hr class="timeline-hr">
            </div>




            </div>
        </form>
Élie
@googley
May 05 2017 13:45
ouch! that's not pep8 compliant :-1: