コード例 #1
0
def login():
    if request.method == 'POST':
        form = LoginForm(request.form)
        if form.validate():
            login_user(form.user, remember=form.remember_me.data)
            flash('Successfully logged in as %s' % form.user.email, 'success')
            return redirect(request.args.get('next') or url_for('homepage'))
    else:
        form = LoginForm()
    return render_template('user/login.html', form=form)
コード例 #2
0
ファイル: views.py プロジェクト: bshyong/cloudroutes-service
def login_page():
    ''' User login page: This is a basic login page'''
    data = {
        'active': 'login',
        'loggedin': False
    }

    # Define and Validate the form
    form = LoginForm(request.form)
    if request.method == "POST":
        if form.validate():
            email = form.email.data
            password = form.password.data

            # Start user definition
            user = User()
            if user.get('username', email, g.rdb_conn):
                result = user.checkPass(password, g.rdb_conn)
                if result is True:
                    data['loggedin'] = True
                    data['msg'] = 'You are logged in'
                    data['error'] = False
                    print("/login - User login successful")
                    # Start building response
                    resp = make_response(
                        redirect(url_for('member.dashboard_page')))
                    cdata = cookies.genCdata(
                        user.uid, app.config['SECRET_KEY'])
                    timeout = int(time.time()) + \
                        int(app.config['COOKIE_TIMEOUT'])
                    # Set cookie as securely as possible
                    resp.set_cookie(
                        'loggedin', cdata, expires=timeout, httponly=True)
                    print("Setting cookie")
                    return resp
                else:
                    data['msg'] = 'Password does not seem valid'
                    data['error'] = True
                    print("/login - User login error: wrong password")
            else:
                data['msg'] = 'Uhh... User not found'
                print("/login - User login error: invalid user")
                data['error'] = True
        else:
            data['msg'] = 'Form is not valid'
            print("/login - User login error: invalid form")
            data['error'] = True

    # Return Login Page
    page = render_template('user/login.html', data=data, form=form)
    return page
コード例 #3
0
ファイル: views.py プロジェクト: mrommelf/cloudroutes-service
def login_page():
    ''' User login page: This is a basic login page'''
    data = {'active': 'login', 'loggedin': False}

    # Define and Validate the form
    form = LoginForm(request.form)
    if request.method == "POST":
        if form.validate():
            email = form.email.data
            password = form.password.data

            # Start user definition
            user = User()
            if user.get('username', email, g.rdb_conn):
                result = user.checkPass(password, g.rdb_conn)
                if result is True:
                    data['loggedin'] = True
                    data['msg'] = 'You are logged in'
                    data['error'] = False
                    print("/login - User login successful")
                    # Start building response
                    resp = make_response(
                        redirect(url_for('member.dashboard_page')))
                    cdata = cookies.genCdata(user.uid,
                                             app.config['SECRET_KEY'])
                    timeout = int(time.time()) + \
                        int(app.config['COOKIE_TIMEOUT'])
                    # Set cookie as securely as possible
                    resp.set_cookie('loggedin',
                                    cdata,
                                    expires=timeout,
                                    httponly=True)
                    print("Setting cookie")
                    return resp
                else:
                    data['msg'] = 'Password does not seem valid'
                    data['error'] = True
                    print("/login - User login error: wrong password")
            else:
                data['msg'] = 'Uhh... User not found'
                print("/login - User login error: invalid user")
                data['error'] = True
        else:
            data['msg'] = 'Form is not valid'
            print("/login - User login error: invalid form")
            data['error'] = True

    # Return Login Page
    page = render_template('user/login.html', data=data, form=form)
    return page
コード例 #4
0
def login():
    form = LoginForm(request.form)
    error = None
    if request.method == 'POST' and form.validate():
        user = User.objects.filter(email=form.email.data.lower()).first()
        if user:
            if bcrypt.checkpw(form.password.data, user.password):
                session['email'] = user.email
                return redirect(request.args.get('next') or url_for('home'))
            else:
                user = None
                print('user none')
        if not user:
            error = 'Your email or password was entered incorrectly'

    return render_template('user/login.html', form=form, error=error)
コード例 #5
0
def login():
    form = LoginForm(request.form)
    error = None
        # si request es post y el formato ha sido validado compara el hash en la base de datos
    if request.method == 'POST' and form.validate():
        user = User.objects.filter(email=form.email.data.lower()).first()
        if user:
            if bcrypt.checkpw(form.password.data, user.password):
                session['email'] = user.email
                #return redirect(request.args.get('next') or url_for('home'))
                return redirect(url_for('complaint_page.explore'))
            else:
                user = None
        if not user:
            error = 'Your email or password was entered incorrectly'
    return render_template('user/login.html', form=form, error=error)
コード例 #6
0
def login():
    form = LoginForm(request.form)
    error = None

    if request.method == 'POST' and form.validate():
        user = User.objects.filter(email=form.email.data).first()
        if user:
            if bcrypt.checkpw(form.password.data, user.password):
                session['email'] = user.email
                return '{} has succesfully logged in!'.format(session['email'])
            else:
                user = None
        if not user:
            error = 'Your email or password was entered incorrectly'


    return render_template('user/login.html', form=form, error=error)
コード例 #7
0
ファイル: view.py プロジェクト: wuzeshixp/Happy
def login():

    # user = User(name = 'zeshi', password='******',email= '*****@*****.**')
    # user.save
    #return "HI,{}!, Your email is {}".format(user.name,user.email)
    form = LoginForm(request.form)
    error = None

    if request.method == 'POST' and form.validate():
        user = User.objects.filter(email=form.email.data).first()
        if user: # if exit then verify psw
            if bcrypt.checkpw(form.password.data, user.password):
                session['email'] = user.email
                #session['username'] = user.name
                return redirect(request.args.get('next') or url_for('user_page.edit'))
            else:
                user = None
        if not user:
            error = 'Your email or psw was incrorect'

    return render_template('user/login.html', form=form)
コード例 #8
0
ファイル: views.py プロジェクト: pathcl/runbook
def login_page():
    """ User login page: This is a basic login page"""
    data = {"active": "login", "loggedin": False}

    # Define and Validate the form
    form = LoginForm(request.form)
    if request.method == "POST":
        if form.validate():
            email = form.email.data
            password = form.password.data

            # Start user definition
            user = User()
            user.config = app.config
            if user.get("username", email, g.rdb_conn):
                result = user.checkPass(password, g.rdb_conn)
                if result is True:
                    data["loggedin"] = True
                    print("/login - User login successful")
                    flash("You are logged in.", "success")
                    # Start building response
                    resp = make_response(redirect(url_for("member.dashboard_page")))
                    cdata = cookies.genCdata(user.uid, app.config["SECRET_KEY"])
                    timeout = int(time.time()) + int(app.config["COOKIE_TIMEOUT"])
                    # Set cookie as securely as possible
                    resp.set_cookie("loggedin", cdata, expires=timeout, httponly=True)
                    print("Setting cookie")
                    return resp
                else:
                    print("/login - User login error: wrong password")
                    flash("Password does not seem valid.", "danger")
            else:
                print("/login - User login error: invalid user")
                flash("Uhh... User not found.", "danger")
        else:
            print("/login - User login error: invalid form")
            flash("Form is not valid.", "danger")

    # Return Login Page
    return render_template("user/login.html", data=data, form=form)
コード例 #9
0
 def test_validate_invalid_email_format(self):
     # Ensure invalid email format throws error.
     form = LoginForm(email='unknown', password='******')
     self.assertFalse(form.validate())
コード例 #10
0
 def test_validate_success_login_form(self):
     # Ensure correct data validates.
     form = LoginForm(email='*****@*****.**', password='******')
     self.assertTrue(form.validate())
コード例 #11
0
ファイル: tests.py プロジェクト: bshyong/cloudroutes-service
 def test_validate_invalid_email_format(self):
     # Ensure invalid email format throws error.
     form = LoginForm(email='unknown', password='******')
     self.assertFalse(form.validate())
     pass
コード例 #12
0
ファイル: tests.py プロジェクト: bshyong/cloudroutes-service
 def test_validate_success_login_form(self):
     # Ensure correct data validates.
     form = LoginForm(email='*****@*****.**', password='******')
     self.assertTrue(form.validate())
     pass