コード例 #1
0
ファイル: user.py プロジェクト: zhuhj89/DRMS
def signin():

    flag = request.args.get('flag')

    if current_user.is_authenticated():
        if flag:
            return redirect(url_for('admin.index'))
        return redirect(url_for('site.index'))

    form = LoginForm(login=request.args.get('login',None),
                     next=request.args.get('next',None))
    if form.validate_on_submit():
        user, authenticated = authenticate(form.email.data,
                                                      form.password.data)
        if user and authenticated:
            # session.permanent = form.remember.data
            remberme = form.remember.data
            # identity_changed.send(current_app._get_current_object(),
            #                       identity=Identity(user.id))
            login_user(user, remberme)

            next_url = form.next.data
            user.is_login = 1

            if not next_url or next_url == request.path:
                if flag:
                    next_url = url_for('admin.index', username=user.nickname)
                else:
                    next_url = url_for('site.index', username=user.nickname)
            return redirect(next_url)

        else:
            pass
            # flash(_("Sorry, invalid login"), "error")
    return render_template("user/signin.html", form=form, flag=flag)
コード例 #2
0
def login():
    # 用户已登录
    if current_user.is_authenticated:
        return redirect(url_for('home.index'))
    # 用户未登录
    else:
        form = LoginForm()
        if request.method == 'POST':
            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, remember=form.remember_me.data)
                    next = request.args.get('next')
                    if next is None or not next.startswith('/'):
                        next = url_for('home.index')
                    return redirect(next)
                else:
                    flash('用户名或密码无效')
                    return render_template('user/login.html', form=form)
            else:
                return render_template('user/login.html', form=form)
        else:
            return render_template('user/login.html', form=form)
コード例 #3
0
ファイル: user.py プロジェクト: gye-tgm/trackit
def login():
    form = LoginForm(request.form)
    if form.validate_on_submit():
        login_user(form.user)
        flash("Login successful", category="info")
        return redirect(request.args.get("next") or url_for('.index'))
    return render_template('user/login.html', form=form)
コード例 #4
0
def login():
    form = LoginForm()
    next = request.args.get('next')
    if form.validate_on_submit():
        user = User.query_one_user(form.name.data)
        if user is not None and user.confirm_password(form.password.data):
            login_user(user, True)  #flask内置函数
            flash("登录成功")
            return redirect(next or url_for('web.index'))
        else:
            flash("登录失败")

    return render_template('user/login.html', form=form)
コード例 #5
0
def login():
    form= LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        user = User.query.filter_by(username=username).first()
        if user.verify_password(password):
            login_user(user = user,remember=form.remember.data)
            flash('登录成功')
            return redirect(request.args.get('next') or url_for('main.index'))
        else:
            flash('重新登录')
            return redirect(url_for('user.login'))

    return render_template('user/login.html',form=form)
コード例 #6
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        user = User.query.filter(User.username == username).first()
        if not user:
            flash('用户名或密码错误')
        elif not user.verify_password(form.password.data):
            flash('用户名或密码错误')
        else:
            login_user(user, remember=form.remember.data)
            flash('登录成功')
            return redirect(
                url_for('gene.message', next=request.args.get('next')))
    return render_template('login.html', form=form)
コード例 #7
0
def login():

    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()

    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("SORRY Invalid password or username")
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('index'))

    return render_template('User/login.html', title='Sign In', form=form)
コード例 #8
0
ファイル: user.py プロジェクト: BasementCat/badgegenerator
def login():
    form = LoginForm()

    if form.validate_on_submit():
        if form.submit_login.data:
            user = User.query.filter(User.username.like(
                form.username.data)).first()
            if user and user.password == form.password.data:
                login_user(user,
                           remember=True if form.remember_me.data else False)
                return redirect(url_for('index.index'))
            else:
                flash("Invalid username or password", 'danger')
        else:
            flash("No action", 'danger')

    return render_template('user/login.jinja.html', form=form)
コード例 #9
0
ファイル: user.py プロジェクト: abdelrahman-elkady/flask-todo
def login():

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

        # Login and validate the user.
        if(user is not None and crypt.check_password_hash(user.password, form.password.data)):
            login_user(user)
            flash('Logged in successfully')
            next = request.args.get('next')
            if not validate_next(next):
                return abort(400)
            else:
                return redirect(next or url_for('user.index'))
        else:
            flash('Username or password is not correct')
            return redirect(url_for('user.login'))

    return render_template('login.html', form=form)
コード例 #10
0
def login():
  """
  Login form
  """
  if 'user_id' in session:
      return redirect(url_for('home'))

  form = LoginForm(request.form)
  # make sure data are valid, but doesn't validate password is right
  if form.validate_on_submit():
    user = User.query.filter_by(email=form.email.data).first()
    # we use werzeug to validate user's password
    if user and check_password_hash(user.password, form.password.data):
      # the session can't be modified as it's signed, 
      # it's a safe place to store the user id
      session['user_id'] = user.id
      flash('Welcome %s' % user.name)
      return redirect(url_for('home'))
    flash('Wrong email or password', 'error-message')
  return render_template("user/login.html", form=form)