예제 #1
0
def login():

    login_form = LoginForm()

    if login_form.validate_on_submit():

        # read values from the login wtform
        username = login_form.username.data
        password = login_form.password.data

        user = User.objects(username=username).first()

        # if user  != None:
        # check if credentials are valid
        if user and user.authenticate(username, password):
            # store the user ID in the session
            session['uid'] = str(user.id)
            session['username'] = user.username
            session['firstname'] = user.first_name
            session['lastname'] = user.last_name
            session['biography'] = user.biography
            session['role'] = user.role

        return redirect("/profile")

    # render the login template
    return render_template('login/login.html', form=login_form)
예제 #2
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.user.data).first()
        if user:
            if try_login(user, str(form.password.data)):
                flash('Logged in successfully!', 'success')
                log.info("User %s logged in", user)
                login_user(user, remember=form.remember_me.data)
                return redirect(request.args.get("next") or url_for("index"))
            else:
                flash('Log in Error', 'danger')
                log.warn("Log in attempt to '%s' from IP %s",
                         user,
                         request.remote_addr)
                form.errors['password'] = [u"Incorrect Password"]
        else:
            log.warn("Log in attempt to '%s' from IP %s",
                     form.user.data,
                     request.remote_addr)
            flash('User not found!', 'danger')
            form.errors['user'] = [u"User not found"]
    return render_template('login.html',
                           title="Log In",
                           form=form)
예제 #3
0
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(url_for('index'))

    return render_template('login.html', title='Sign In', form=form)
예제 #4
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        login_user(user)
        return redirect(url_for('admin.blog_manage'))
    else:
        return render_template('login.html', form=form)
예제 #5
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == '*****@*****.**' and form.password.data == 'password':
            flash('You have been logged in', 'success')
            return redirect(url_for('homepage'))
        else:
            flash('Login failed. Please enter valid details', 'danger')
    return render_template('login.html', title='Login', form=form)
예제 #6
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == "*****@*****.**" and form.password.data == "start":
            flash(f"You have been logged in!", "success")
            return redirect(url_for("home"))
        else:
            flash("Login Unsuccessful. Please check username and password",
                  "danger")
    return render_template("login.html", title="Login", form=form)
예제 #7
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == '*****@*****.**' and form.password.data == 'password':
            flash("You are now logged in!", 'success')
            return redirect(url_for('home'))
        else:
            flash("Login unsuccessful, please check email and password!" ,'danger')
        return redirect(url_for('login'))
    return render_template("login.html", title="Login", form=form)
예제 #8
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == '*****@*****.**' and form.password.data == 'password':
            flash('You have been logged in!', 'success')
            return redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check username and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
예제 #9
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == '*****@*****.**' \
                and form.password.data == 'pass':
            flash('You logged in', 'success')
            return redirect(url_for('home'))
        else:
            flash('login unseccess', 'danger')
    return render_template('login.html', title='Login', form=form)
예제 #10
0
def myaccount():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user)
            flash("You have succssfully logged in")
            return redirect(url_for("home"))
        else:
            flash("Unsuccessful, kindly check your details")
    return render_template("myaccount.html", title="Login", form=form)
예제 #11
0
파일: routes.py 프로젝트: Hadiaj448/Amazon
def login():
    form=LoginForm()
    if form.validate_on_submit():
        user=User.query.filter_by(email=form.email.data,password=form.password.data).first()
        if user:
            login_user(user)
            flash(f'Welcome You Successfully loged in','success')
            return redirect(url_for('index'))
        else:
            flash(f'Login Unsuccessfull Try again','danger')
    return render_template('login.html',form=form,title='Login')
예제 #12
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user_attempt = User.query.filter_by(email=form.email.data).first()
        if user_attempt and user_attempt.check_password(form.password.data):
            login_user(user_attempt)
            flash(f'Success! You are logged in as {user_attempt.username}', category='success')
            return redirect(url_for('blogs'))
        else:
            flash("Username and Password are not match!", category='danger')
    return render_template('login.html', form=form)
예제 #13
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = Users.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user)
            flash('Logged in successfully! ')
            return redirect(url_for('home'))
        else:
            flash('Invalid email address or password.')
    return render_template('login.html', title='Login', form=form)
예제 #14
0
def login():
  """ Login page, shows the login form """
  form = LoginForm()

  if form.validate_on_submit():
      user = User.query.filter_by(username=form.username.data).one()
      login_user(user)

      flash("You've been logged in", "success")
      return redirect(url_for(".index"))

  return render_template("login.html", form=form)
예제 #15
0
def login():
    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
        return open_id.try_login(form.openid.data,
                                 ask_for=['nickname', 'email'])
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
예제 #16
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('homepage'))
    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('username e password non combaciano!')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('homepage'))
    return render_template("login.html", form=form)
예제 #17
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == '*****@*****.**' and form.password.data == 'admin@123':
            flash(f'You have been logged in successfully as {form.email.data}',
                  'success')
            return redirect(url_for('home'))
        else:
            flash(
                'Login Unsuccessful! Please Check email and password and try again',
                'danger')
    return render_template('login.html', title='Login', form=form)
예제 #18
0
def login():
	if current_user.is_authenticated:
		return redirect(url_for('home'))
	form = LoginForm()
	if form.validate_on_submit():
		user = User.query.filter_by(email=form.email.data).first()
		if user and bcrypt.check_password_hash(user.password, form.password.data):
			login_user(user, remember=form.remember.data)
			return redirect(url_for('home'))
		else:
			flash('Login Unsuccessful! Please check email and password', 'danger')
	return render_template("login.html", title = 'Login', form=form)
예제 #19
0
def login():
    """ Login page, shows the login form """
    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).one()
        login_user(user)

        flash("You've been logged in", "success")
        return redirect(url_for(".index"))

    return render_template("login.html", form=form)
예제 #20
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user=User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user)
            flash('Congratulations! You logged in!')
            return redirect(url_for('home'))
        if user is not None and not user.verify_password(form.password.data):
            return redirect(url_for('login')), flash('INVALID EMAIL OR PASSWORD')
        if user is None:
            return redirect(url_for('login')), flash('INVALID EMAIL OR PASSWORD')
    return render_template('login.html', title='Login', form=form)
예제 #21
0
def login():
    form = LoginForm()
    errors = None
    next_url = request.args.get('next')
    if request.method == 'POST':
        if form.validate_on_submit():
            session['logged_in'] = True
            session.permanent = True
            flash('You are now logged in.', 'success')
            return redirect(next_url or url_for('index'))
        else:
            errors = form.errors
    return render_template("login_form.html", form=form, errors=errors)
예제 #22
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form=LoginForm()
    if form.validate_on_submit():
        user=User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,form.password.data):
            login_user(user,remember=form.remember.data)
            next_page=request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('home'))
        else:
            flash('Login Unsucessful.Please check email and password',category='danger')
    return render_template('login.html',title='Login',form=form)
예제 #23
0
def login():
    if current_user.is_authenticated:
        return redirect("/")
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and user.password == form.password.data:
            login_user(user)
            flash(f'Login Successful', 'success')
            return redirect("/")
        else:
            flash(f'Incorrect email/password', 'danger')
    return render_template('login.html', form=form)
def login():
    form = LoginForm()
    errors = None
    next_url = request.args.get("next")
    if request.method == "POST":
        if form.validate_on_submit():
            session["logged_in"] = True
            session.permanent = True  # Use cookie to store session.
            flash("You are now logged in.", "success")
            return redirect("/")
        else:
            errors = form.errors
    return render_template("login_form.html", form=form, errors=errors)
예제 #25
0
파일: views.py 프로젝트: mcrisan/blog
def user_login():
        form = LoginForm()
        next = request.args.get('next')
        if form.validate_on_submit():
            flash('Successfully logged in as %s' % form.user.username)
            session['user_id'] = form.user.id
            user = User.query.get(form.user.id)
            login_user(user)
            if next != "None":
                return redirect(next)
            else:
                return redirect(url_for('blog.index'))
        return render_template('login.html', form=form)
예제 #26
0
파일: routes.py 프로젝트: Throupy/Blog
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            flash('You have been logged in!', 'is-success')
            return redirect(url_for('index'))
        else:
            flash('Login unsuccessful, please try again', 'is-danger')
    return render_template('login.html', form=form)
예제 #27
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = (User.query.filter_by(email=form.email.data).first()
                or User.query.filter_by(phone=form.phone.data).first())
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
    return render_template('login.html', title='Login', form=form)
예제 #28
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(email=form.email.data).first()
        if user and check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('index'))
        else:
            flash('Email or Password Uncorrect', 'danger')
    return render_template("login.html", title="Login", form=form)
예제 #29
0
def login():
    form = LoginForm()

    if current_user.is_authenticated:
        flash('you have loged in your account')
        return redirect(url_for('home'))

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user)
            return redirect(url_for('home'))
        else:
            flash('Invalid email address or password.')
    return render_template('login.html', title='Login', form=form)
예제 #30
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        # Check if such a user exists, then check that the passwords match
        if user is None or not bcrypt.check_password_hash(user.password, form.password.data):
            flash(f'Login failed. Username and password do not match', 'danger')
            return render_template('login.html', title='Login', form=form)
        flash('Successfully logged in.', 'success')
        login_user(user, remember=form.remember.data)
        next_page = request.args.get('next')
        return redirect(next_page) if next_page else redirect(url_for('home'))
    return render_template('login.html', title='Login', form=form)
예제 #31
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('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 or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template('login.html', title='Sign In', form=form)
예제 #32
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(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next = request.args.get("next")
            flash("You are successfully log in.", "success")
            return redirect(next) if next else redirect(url_for("index"))
        else:
            flash("Check your email or password.", "danger")
    return render_template("login.html", title="Login", form=form)
예제 #33
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('Subjects'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('Subjects'))
        else:
            flash('Incorrect Email or Passowrd Compination', 'danger')
    return render_template('login.html', form=form)
예제 #34
0
파일: views.py 프로젝트: goodking-bq/zblog
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = LoginForm(request.form)
    if form.validate_on_submit() and request.method == 'POST':
        user = User.user_check(passwd=form.passwd.data, email=form.email.data)
        remember_me = form.remember_me.data
        if user:
            login_user(user, remember=remember_me)
            flash(u'恭喜,登录成功!')
            log = Login_log(email=user.email,
                            ip=request.remote_addr)
            db.session.add(log)
            db.session.commit()
            Blog_info.new_login()
            return redirect(request.args.get("next") or url_for("index"))
        else:
            flash(u'用户名或密码错误')
            return redirect(url_for('login'))
    return render('login.html',
                  title=u'请登陆',
                  form=form)