当前位置: 首页>>代码示例>>Python>>正文


Python forms.LoginForm类代码示例

本文整理汇总了Python中app.forms.LoginForm的典型用法代码示例。如果您正苦于以下问题:Python LoginForm类的具体用法?Python LoginForm怎么用?Python LoginForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LoginForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login_view

def login_view(request):
    if request.user.is_authenticated():
        if request.GET.get('next'):
            return redirect(request.GET['next'])
        else:
            return redirect('dashboard')

    if request.method == 'POST':
        form = LoginForm(data=request.POST)
        if form.is_valid():
            user = form.login(request)
            if user:
                if user.is_active:
                    auth_login(request, user)
                    messages.success(request, 'Ingresaste con exito.')
                    if request.GET.get('next'):
                        return redirect(request.GET['next'])
                    else:
                        return redirect('dashboard')
    else:
        form = LoginForm()

    return render(request, 'login.html', {
        'form': form,
    })
开发者ID:nlattessi,项目名称:inspt_tp_final_cpe,代码行数:25,代码来源:views.py

示例2: authenticate

def authenticate(project):
    print "authenticate"
    print current_user, current_user.is_authenticated()

    if not current_user.is_authenticated():
        print "logging in user"
        user = User()
        db.session.add(user)
        db.session.commit()
        login_user(user)

    if project in current_user.projects:
        print "p:", project
        current_user.current_project = project
        db.session.commit()
        return redirect(url_for('.project', project=project))

    form = LoginForm()
    if form.validate_on_submit():
        print "p:", project
        current_user.current_project = project
        current_user.projects.append(project)
        db.session.commit()
        return redirect(url_for('.project', project=project))

    return render_template('authenticate.html',
                           project=project,
                           form=form)
开发者ID:StudioCreate,项目名称:cerberus,代码行数:28,代码来源:main.py

示例3: login

def login():
    form = LoginForm()
    pageTitle = "login"

    if request.method == 'POST':
        if form.validate() is False:
            return render_template('users/login.html',
                                   form=form,
                                   pageTitle=pageTitle)
        else:
            # user = User.get(email=form.email.data.lower().strip())
            user = User.get(email=form.email.data.lower().strip())
            if user and user.roles.can_login is True:
                #add remember_me
                user.last_seen = DATE_TIME_NOW
                user.save()
                login_user(user)
                return redirect(request.args.get('next') or
                                url_for('.profile',
                                        user_id=user.get_id())
                                )
            else:
                flash("Please confirm your email address.")
                return render_template('users/login.html',
                                       form=form,
                                       pageTitle=pageTitle)
    elif request.method == 'GET':
        if request.args.get('next'):
            session['next'] = (request.args.get('next') or
                               request.referrer or None)
        return render_template('users/login.html',
                               form=form,
                               pageTitle=pageTitle)
开发者ID:cldershem,项目名称:homelessgaffer,代码行数:33,代码来源:views.py

示例4: login

def login():
	form = LoginForm()
	if form.validate_on_submit():
		user = User.query.filter_by(email=form.email.data).first()
		login_user(user, remember=True)
		return redirect(url_for("dashboard"))
	return render_template('signup.html', signup_form=SignupForm(), login_form=form)
开发者ID:alexacristina,项目名称:greentea,代码行数:7,代码来源:views.py

示例5: login

def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash('Login requested for user {}, remember_me={}'.format(
            form.username.data, form.remember_me.data))
        return redirect('/index')
    return render_template('login.html', title='Sign In', form=form)
开发者ID:TMc42,项目名称:Flask-Microblog,代码行数:7,代码来源:routes.py

示例6: login

def login():
    '''###############################
    Log to the system
    ##################################
    '''
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('.index'))
    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data

        user = User.query.filter_by(email=form.openid.data).first()
        if user is None:
            #flash('Invalid login. Please try again.')
            #return redirect(url_for('.login'))
            user = add_user(form.openid.data)
        
        remember_me = False
        if 'remember_me' in session:
            remember_me = session['remember_me']
            session.pop('remember_me', None)
        login_user(user, remember = remember_me)
        return redirect(request.args.get('next') or url_for('.index'))

    return render_template('login.html', 
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
开发者ID:emawind84,项目名称:flasktest,代码行数:28,代码来源:views.py

示例7: login_view

def login_view(request):
    elem = {
        'title':'Login',
    }
    #inloggade användare behöver inte se login view
    if request.user.is_authenticated():
        return HttpResponseRedirect('/home/')
    if request.method == 'POST':
        loginform = LoginForm(request.POST)
        loginAuth(request)
        if loginform.is_valid():
            if request.user.is_authenticated():
                #endast för admin, som saknar user profile från början, underlättar testning
                up = UserProfile.objects.filter(user=request.user)
                if not up.exists():
                    new_profile = UserProfile(user=request.user, description=16*"admin")
                    new_profile.save()
                return HttpResponseRedirect('/home/')
        else:
            return HttpResponseRedirect('')    
            loginform = LoginForm()
            elem.update({'error':'inloggning misslyckades','login_form':loginform})
            print "aha"
            return render_to_response("login.html",elem,context_instance=RequestContext(request))
    else:
        loginform = LoginForm()
    elem.update({'login_form':loginform})
    return render_to_response("login.html",elem,context_instance=RequestContext(request))
开发者ID:130n,项目名称:Django-project,代码行数:28,代码来源:views.py

示例8: login

def login():
    form = LoginForm()
    rForm = RegisterForm()
    ref = {'key': request.args.get('key'), 'token': request.args.get('token') }
    if current_user.is_authenticated:
        if ref['key'] and ref['token']:
            try:
                consume_token(ref['token'])
                group = Group.objects.get(referrals__key=ref['key'])
                group.add_to_group(current_user, ref['key'])
            except ValueError as e:
                return(e)
        return redirect(url_for('index'))
    if request.method == 'POST' and form.validate_on_submit():
        user = User.objects.get(username__iexact=form.username.data)
        if user and check_password_hash(user.password, form.password.data):
            if request.form.get('key') and request.form.get('token'):
                try:
                    consume_token(request.form.get('token'))
                    group = Group.objects.get(referrals__key=request.form.get('key'))
                    group.add_to_group(current_user, request.form.get('key'))
                except ValueError as e:
                    return(e)
            user.authenticated = True
            login_user(user)
            return redirect(url_for('index'))
    return render_template('login.html', title='login', form=form, rForm=rForm, ref=ref)
开发者ID:exactassembly,项目名称:cerise,代码行数:27,代码来源:cerise.py

示例9: login

def login():
    form = LoginForm(login=request.args.get("login", None),
                     next=request.args.get("next", None))

    # TBD: ensure "next" field is passed properly
    if form.validate_on_submit():
        user, authenticated = \
            User.query.authenticate(form.login.data,
                                    form.password.data)

        if user and authenticated:
            # Flask-Login
            login_user(user, remember = form.remember.data)
            
            # change identity
            identity=Identity(user.username)
            identity_changed.send(current_app._get_current_object(),
                                identity = identity)
            # next_url
            next_url = form.next.data
            if not next_url or next_url == 'home.index':
                next_url = url_for('user.jobs', username=user.username)
                flash(u"登录成功", "successfully")
            return redirect(next_url)
        else:
            flash(u"账号或密码错误", "error")
    return render_template("account/login.html", form=form)
开发者ID:beachmg,项目名称:raychen,代码行数:27,代码来源:account.py

示例10: login

def login():
    if not current_user.is_anonymous:
        return redirect(url_for('home.index'))

    form = LoginForm()
    if form.validate_on_submit():
        email = form.email.data.lower()
        user = User.query.filter_by(email=email).first()
        if user is None:
            logging.error("User %s is not found" % (email))
            return render_template(
                    'login.html',
                    login_form=form,
                    error="Invalid email or password")

        if not user.verify_password(unicode(form.password.data)):
            logging.error("Invalid password")
            return render_template(
                    'login.html',
                    login_form=form,
                    error="Invalid email or password")

        login_user(user)

        flash('Logged in successfully.')

        return redirect(url_for('home.index'))
    return render_template('login.html', login_form=form)
开发者ID:GopyDev,项目名称:neighborme,代码行数:28,代码来源:__init__.py

示例11: login

def login():
    """Logging in the user."""

    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        # Do not allow user who registered with a social account to log
        # via the login form. Use the social login buttons instead
        if user is not None and user.register_with_provider:
            flash('Please login with your social account')
            return redirect(url_for('mod_auth.login'))

        if user is not None and user.verify_password(form.password.data):
            # The user must be activated
            if not user.confirmed:
                flash('You need to activate your account first')
                return redirect(url_for('mod_auth.login'))

            # Log the user in
            login_user(user, remember=form.remember.data)
            return redirect(request.referrer or url_for('mod_feed.index'))

        # Redirect to login page with an error message
        flash('Invalid email, password')

    return render_template('auth/login.html', form=form)
开发者ID:phamminh91,项目名称:feedreader,代码行数:28,代码来源:controller_login.py

示例12: index

def index():
    login = LoginForm()#login objekti
    if request.method == 'GET':#29.1.2016 lisätty alla oleva
        return render_template('template_index.html',form=login,isLogged=False)
    else:
        #check if form data is valid
        if login.validate_on_submit():#tsekkaa onko formit valideja
            #3.2.2016 Check if correct username or password
            #user = Users.query.filter_by(email=login.email.data).filter_by(passw=login.passw.data)
            #yllä oleva luo SQL-lauseen: Select email passw From User Where email="?" And passw="?"
            
            #4.2.2016 passw on kryptattu
            # Check if correct username
            user = Users.query.filter_by(email=login.email.data)
            print(user)
            #if user.count() == 1:#3.2.2016 jos palautetun taulukon koko on yksi
            #4.2.2016: user[0].passw = kryptattu salasana
            if (user.count() == 1) and (check_password_hash(user[0].passw,login.passw.data)):
                print(user[0])
                session['user_id'] = user[0].id#tallennetaan käyttäjän ID
                session['isLogged'] = True
                print(session['user_id'])
                #Haetaan ystävät
                #tapa 1 listata ystävät
                friends = Friends.query.filter_by(user_id =user[0].id)
                print(friends)
                return render_template('template_user.html',isLogged=True,friends=friends)
            else:
                flash('Wrong email or password')
                return render_template('template_index.html',form=login,isLogged=False)
        #form data was not valid
        else:
            flash('Give proper information to email and password fields!')#näyttö toteutettu base.html:ssä (kalvo s.56)
            return render_template('template_index.html',form=login,isLogged=False)
开发者ID:timoparv65,项目名称:PythonFlask,代码行数:34,代码来源:routers.py

示例13: login

def login():
    # if user is logged in, redirect them to index
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = LoginForm()
    # tries to login user
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        session['remember_me'] = form.remember_me.data
        registered_user = User.query.filter_by(username=username).first()
        if registered_user is not None:
            if registered_user.check_password(password):
                remember_me = False
                if 'remember_me' in session:
                    remember_me = session['remember_me']
                    session.pop('remember_me', None)
                login_user(registered_user, remember = remember_me)
                flash('Logged in successfully')
                return redirect(request.args.get('next') or url_for('index'))
            else:
                form.password.errors.append("Invalid password!")
        else:
            form.username.errors.append("Invalid username!")
    return render_template('login.html', title = 'Sign In', form = form)
开发者ID:tdietert,项目名称:Program_A_Bull,代码行数:25,代码来源:views.py

示例14: login

def login():
    """
    登录
    """
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            from user_auth import get_user_auth_row
            condition = {
                'auth_type': 'email',
                'auth_key': form.email.data,
                'auth_secret': form.password.data
            }
            user_auth_info = get_user_auth_row(**condition)
            if user_auth_info is None:
                flash(u'%s, You were logged failed' % form.email.data, 'warning')
                return render_template('login.html', title='login', form=form)
            if user_auth_info.verified == 0:
                flash(u'%s, Please verify email address in mailbox' % form.email.data, 'warning')
                return render_template('login.html', title='login', form=form)
            # session['logged_in'] = True
            # 用户通过验证后,记录登入IP
            from user import edit_user
            edit_user(user_auth_info.user_id, {'last_ip': request.headers.get('X-Forwarded-For', request.remote_addr)})
            # 用 login_user 函数来登入他们
            from user import get_user_row_by_id
            login_user(get_user_row_by_id(user_auth_info.user_id))
            flash(u'%s, You were logged in' % form.email.data, 'success')
            return redirect(request.args.get('next') or url_for('index'))
        flash(form.errors, 'warning')  # 调试打开
    return render_template('login.html', title='login', form=form)
开发者ID:zhanghe06,项目名称:flask_project,代码行数:33,代码来源:views.py

示例15: login

def login():
    if request.method == 'POST' and 'User-Agent' not in request.headers:
        email = request.form['email']
        password = request.form['password']
        if email and password:
            user = Users.query.filter_by(email=email).first()
            if user and user.verify_password(password):
                g.user = user
                token = user.generate_auth_token(600)
                return jsonify({'error':'null', 'data':{'token': token.decode('ascii'), 'expires': 600, 'user':{'id': user.id, 'email': user.email, 'name': user.name}, 'message':'success'}})
            return jsonify({'error': '1', 'data':{}, 'message':'Bad user name or password'})
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if request.method == 'POST' and 'User-Agent' in request.headers:
        if form.validate_on_submit():
            uname = request.form['username']
            pword = request.form['password']
            user = Users.query.filter_by(email=uname).first()
            if user is None:
                return redirect(url_for('login'))
            login_user(user)
            return redirect(request.args.get("next") or url_for('wishlist',id=g.user.id))
    
    return render_template(
        'login.html',
        title='User Login',
        year=datetime.now().year,
        form=form,
        user=g.user
    )
开发者ID:smartkode,项目名称:info3180-project3-4,代码行数:31,代码来源:views.py


注:本文中的app.forms.LoginForm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。