Ejemplo n.º 1
0
def login():
    form = LoginForm(request.form)

    if request.method == 'POST' and form.validate():
        username = form.username.data
        password = form.password.data

        error = None
        user = User.query.filter_by(username=username).first()

        if user is None:
            error = 'Incorrect username.'
        #elif not check_password_hash(user.password, password):
        elif not (user.password == password):
            error = 'Incorrect password.'

        if error is None:
            session.clear()
            session['user_id'] = user.id

            return redirect(url_for('index'))

        flash(error)

    return render_template('user/login.html', form=form)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def index(page=1):
    target = request.args.get('target', None)
    if not target:
        pagination = Info.query.order_by(Info.avgScore.desc()).paginate(
            page, per_page=5, error_out=False)
        infos = pagination.items
    else:
        pagination = Info.query.filter(
            Info.realName.like('%{}%'.format(target))).order_by(
                Info.avgScore.desc()).paginate(page,
                                               per_page=2,
                                               error_out=False)
        infos = pagination.items
        flash('搜索结果')
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User.query_by_login(form.username.data, form.password.data)
        if type(user) != str:
            session['userId'] = user.id
            flash('Logged in as {}'.format(form.username.data))
            return redirect(url_for('home.index'))
        else:
            errorMsg = user
            flash(errorMsg, category='login_error')
            return redirect(url_for('home.index'))
    # 传入form用于显示error信息
    return render_template('home/index.html',
                           form=form,
                           infos=infos,
                           round=round,
                           pagination=pagination)
Ejemplo n.º 5
0
Archivo: user.py Proyecto: 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)
Ejemplo n.º 6
0
def login():
    form = LoginForm()
    if request.method == "POST" and form.validate():
        if form.email.data == "*****@*****.**" and form.password.data == "admin":
            flash('You have been logged in!', 'success')
            return redirect(url_for('home'))
        else:
            flash('Login Unsuccessfull. Please check your email and password!',
                  'danger')

    return render_template("login.html", title="Login", form=form)
Ejemplo n.º 7
0
def login():
    form = LoginForm()
    if request.method == "POST" and form.validate():
        flash(
            f"Login request form user {form.username.data} with password {form.password.data}"
        )
        return redirect(url_for("users"))

    return render_template("login.html",
                           title="Log In",
                           form=form,
                           username="******")
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if user and user.check_password(form.password.data):
            current_app.logger.warning(user.nickname + '登录了网站')
            login_user(user)
            next = request.args.get('next')
            if not next or not next.startswith('/'):
                next = url_for('web.index')
            return redirect(next)
        else:
            flash('账号不存在或密码错误!')
    return render_template('auth/login.html', form=form)
Ejemplo n.º 10
0
def login():
    form = LoginForm(request.form)
    print(form.data, type(form.data))
    if request.method == 'POST' and form.validate():
        print(form.password.data)
        user = User.query.filter_by(phone=form.phone.data).first()
        if user and user.check_password(form.password.data):
            login_user(user)
            pass
        else:
            flash('账号不存在或密码错误')
        return render_template('index.html')
    print(form.errors)
    return render_template('login.html')
Ejemplo n.º 11
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)
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
def login():
    if current_user.is_authenticated:
        flash("You already logged in", "info")
        return redirect(url_for("home"))
    form = LoginForm()
    if request.method == "POST" and form.validate():
        user = User.query.filter_by(email=form.email.data).first()
        if user and user.check_password(form.password.data):
            login_user(user, remember=form.remember.data)
            flash('You have been logged in!', 'success')
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for("home"))
        else:
            flash('Login Unsuccessfull. Please check your email and password!',
                  'danger')

    return render_template("login.html", title="Login", form=form)
Ejemplo n.º 16
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('homepage'))
    form = LoginForm()
    if request.method == "POST" and form.validate():
        # Пытаемся найти пользвоателя с таким username в бд
        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("login"))
        # Добавляем пользователя в сессию
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get("next")
        if not next_page:
            next_page = url_for("homepage")

        return redirect(next_page)
    return render_template("login.html", title="Log In", form=form)
Ejemplo n.º 17
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)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
def login():
    form = LoginForm().validate_for_api()
    appid = current_app.config['APPID']
    secret = current_app.config['WX_SECRET']
    code = form.code.data
    wx_auth = WXAuth(appid, secret, code)
    token, openid = wx_auth.get_token_openid()
    with db.auto_commit():
        user = User()
        user.openid = openid
        db.session.add(user)
    return Success()
Ejemplo n.º 20
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate:
        user = User.query.filter_by(student_id=form.student_id.data).first()
        if user and user.check_password(form.password.data):
            # 写入cookie,默认一次性的,即,浏览器关闭就失效
            login_user(user)
            # 登陆后自动跳回原来到原来的页面
            return_next = request.args.get('next')

            if not return_next or not return_next.startswith('/'):
                return_next = url_for('web.recent')
            return redirect(return_next)
        else:
            flash('账号不存在或密码错误!')
    return render_template('login.html', form=form)
Ejemplo n.º 21
0
def login():
    title = 'identifier'
    form = LoginForm()
    if request.method == 'GET':
        return render_template('auth/login.html', title=title, form=form)

    email = request.form.get('email')
    password = request.form.get('password')
    remember = True if request.form.get('remember') else False

    user = User.query.filter_by(email=email).first()

    # check if user actually exists
    # take the user supplied password, hash it, and compare it to the hashed password in DB
    if not user or not check_password_hash(user.password, password):
        flash('Please check your login details and try again.')
        return redirect(url_for('auth.login'))

    # if the above check passes, then we know the user has the right credentials
    login_user(user, remember=remember)
    session['email'] = email
    return redirect(url_for('home.index'))