Example #1
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user_id = form.get_user().user_id
        session['user_id'] = user_id
        return redirect(url_for('user_index', user_id=user_id))
    return render_template('login.html', form=form)
Example #2
0
def signin():
    if current_user is not None and current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            form.email.errors.append('User does not exist')
            return render_template('signin.html', signinpage_form=form)
        if user.password != hash_password(form.password.data):
            return render_template('signin.html', signinpage_form=form)
        login_user(user, remember=form.remember_me.data)
        session['signed'] = True
        session['username'] = user.username
        if session.get('next'):
            next_page = session.get('next')
            session.pop('next')
            return redirect(next_page)
        else:
            return redirect(url_for('index'))
    else:
        session['next'] = request.args.get('next')
        return render_template('signin.html',
                               signinpage_form=LoginForm(),
                               page_title='this is Login route')
Example #3
0
def index(username=None):
    if username is None:
        return render_template("index.html",
                               signin_form=LoginForm(),
                               page_title="Portfolio manager")
    user = User.query.filter_by(username=username).first()

    if user is None:
        user = User()
        user.username = username
        user.firstname = 'Tony'
        user.lastname = 'Adamma'
        user.biography = 'Pleased and Awesome is the day I was born and I have got every \
        reason to be happy for the Lord of Host has made me glad at all times'

        user.avatar = 'http://placekitten.com/350/300'
        db.session.add(user)
        db.session.commit()
        return render_template('themes/water/portfolio.html',
                               signin_form=LoginForm(),
                               portoform=PortoForm(),
                               page_title='This is the new guys in Town: ' +
                               username,
                               user=user)
    return render_template("themes/water/portfolio.html",
                           signin_form=LoginForm(),
                           portoform=PortoForm(),
                           page_title=username,
                           user=user)
Example #4
0
def login():
    form = LoginForm(request.form)
    print json.dumps(request.form, indent=4)

    if form.validate_on_submit():
        print 'form validated'
        user_email = request.form['user_email'].encode('utf-8')
        user_password = request.form['user_password'].encode('utf-8')
        user = User.query.filter(User.user_email == user_email).one_or_none()
        #user = config.db.session.query(User).filter_by(user_email=user_email).first()
        print 'email: %s user: %s' % (str(user_email), str(user))
        if user:
            print 'user found: %s' % user
            if bcrypt.check_password_hash(user.user_password, user_password):
                user.authenticated = True
                user.user_is_authenticated = True
                config.db.session.add(user)
                config.db.session.commit()
                login_user(user, remember=True)
                return Response("Login success", 200)
            else:
                return Response("Username / password incorrect", 401)
        else:
            return Response("Username / password incorrect", 401)

    else:
        print 'form not validated!!'
        print form.errors
        return Response("Authentication failed!", 498)
Example #5
0
def login(): 

    if current_user.is_authenticated:
        return redirect("/dashboard")

    form = LoginForm()

    if form.validate_on_submit():
        print(form.errors)
        uname = request.form['username']
        passwd =  request.form['password']        
    
        if verify_password(uname, passwd):
            print("password correct!")
            user = User(uname)
            login_user(user, remember = True) #this works by calling load_user 
            return redirect("/dashboard")       
        else: 
            print("yer password was wrong")
            flash("bad login")
            return redirect("/login")
    elif request.method == "POST":
        #post, but not validated
        flash("bad login")
        return redirect("/login")
        
    #call LCS endpoint, probably

    print(form.errors)
    return render_template('login.html', form=form)
Example #6
0
def login():
    form = LoginForm()
    error = None

    if request.method == 'GET' and request.args.get('next'):
        session['next'] = request.args.get('next', None)

    if form.validate_on_submit():
        user = User.query.filter_by(
            username=form.username.data
        ).first()
        if user:
            if bcrypt.hashpw(form.password.data.encode('utf8'), salt) == user.password:
                session['username'] = user.username
                if 'next' in session:
                    next = session.get('next')
                    session.pop('next')
                    return redirect(next)
                else:
                    return redirect(url_for('index'))
            else:
                error = "Incorrect password"
        else:
            error = "User not found"
    return render_template('user/login.html', form=form, error=error)
Example #7
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        login_user(form.admin)
        flash("Logged in successfully.")
        return redirect(request.args.get("next") or url_for("index"))
    return render_template("login.html", form=form)
Example #8
0
def login():
    # 判断用户是否存在
    name = None
    forms = LoginForm()
    if request.method == 'POST':
        if forms.validate_on_submit(
        ):  # 数据正确 并且验证csrf通过。这里应该要加上访问数据库并验证登录信息是否合法
            # print(request.form['password'])
            # print(request.form['password'].encode())
            # print(type(request.form['password']))
            # print(type(request.form['password'].encode()))
            # print(type(hashlib.sha1(request.form['password'].encode('utf-8')).hexdigest()))
            # print(db.selectVal(request.form['username']))
            cheaked_useinfo = db.selectVal(request.form['username'])
            print(cheaked_useinfo)
            if hashlib.sha1(request.form['password'].encode(
                    'utf-8')).hexdigest() == cheaked_useinfo[0][4]:
                session['username'] = request.form['username']
                session['private_key'] = db.selectVal(
                    request.form['username'])[0][-2]
                session['address'] = db.selectVal(
                    request.form['username'])[0][2]
                session['userid'] = db.selectVal(
                    request.form['username'])[0][5]
                print('1')
                return redirect(url_for('index'))
            else:
                session['username'] = '******'
                print('2')
                return redirect(url_for('index'))
    return render_template('login.html', form=forms)
Example #9
0
def login():
    if 'user' in session:
        return redirect(url_for('home.user'))
    form = LoginForm()
    if form.validate_on_submit():
        data = form.data

        if User.query.filter_by(name=data['name']).count() == 0:
            flash('账号不存在', 'err')
            return redirect(url_for('home.login'))
        user = User.query.filter_by(name=data['name']).first()
        # if not user.check_pwd(data['pwd']):
        # 验证密码
        from werkzeug.security import check_password_hash
        if not check_password_hash(user.pwd, data['pwd']):
            flash('密码不正确', 'err')

            return redirect(url_for('home.login'))

        session['user'] = user.name
        session['user_id'] = user.id
        userlog = Userlog(user_id=user.id, ip=request.remote_addr)
        db.session.add(userlog)
        db.session.commit()
        return redirect(url_for('home.user'))

    return render_template('home/login.html', form=form)
Example #10
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['username']).first()
            if user is not None and bcrypt.check_password_hash(
                    user.password, request.form['password']):
                # session['logged_in'] = True
                login_user(user)
                flash('You were logged in.')
                return redirect(url_for('home.home'))
            else:
                error = 'Invalid Credentials. Please try again.'

    # TO MAKE THE LOGIN AND REGISTER PAGE ON THE SAME PAGE
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(name=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return redirect(url_for('home.home'))

    return render_template('login.html', form=form, error=error)
Example #11
0
def login():
    if (request.method == "POST"):
        username1 = request.form["username"]
        password1 = request.form["password"]
        cur = con.cursor()
        cur.execute(
            "SELECT password,company,email FROM usertable Where username='******'")
        data = cur.fetchone()
        if (data == None):
            flash(f'Enter Valid Username', 'danger')
            form = LoginForm()
            return render_template("home.html", form=form)
        elif (password1 == data[0]):
            session['user'] = data[1]
            session['email'] = data[2]
            return redirect(
                url_for("first", title="Inventory | Home", name="Hllo"))
        else:
            flash(f'Enter Valid Password', 'danger')
            form = LoginForm()
            return render_template("home.html", form=form)
    else:
        form = LoginForm()
        return render_template("home.html", title='Inventory|Login', form=form)
Example #12
0
def login():
    form = LoginForm()

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data

        # Query 'user' table with username , Get first row only
        user = User.query.filter_by(username=username).first()

        # Check if username is present
        if user is None:
            flash('Username or Password is incorrect')
            return redirect(url_for('login'))

        # Check if user is active
        if not user.active:
            flash("Your account is inactive")
            return redirect(url_for(login))

        # Verify the password for the active user
        if not user.verify_password(password):
            flash('Username or Password Incorrect')
            return redirect(url_for('login'))

        # Flask login :- Establish session for this user
        login_user(user)
        return redirect(url_for('startapp'))

    return render_template('login.html', form=form)
def login():
    """Login function for logging in"""

    # Create an object called "form" to use LoginForm class
    form = LoginForm()
    username = form.username.data
    password = form.password.data

    # Validate a form submitted by a user
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()

        # Check and compare a user's password
        # in a database, if True, log a user in
        if user and user.verify_password(password):

            # Log a user in after completing verifying a password
            # then flash a message "Successful Login"
            login_user(user)
            flash("Successful Login", "success")

            # Redirect to homepage
            return redirect(url_for('home'))

        else:
            flash("Invalid Login", "danger")
    else:
        # You can print or return something such as an error message
        # In this case, do nothing. But you can do it later
        pass

    return render_template('login.html', form=form)
Example #14
0
def login():
    # Here we use a class of some kind to represent and validate our
    # client-side form data. For example, WTForms is a library that will
    # handle this for us, and we use a custom LoginForm to validate.
    form = LoginForm()

    # next = get_redirect_target()
    # next = None

    if form.validate_on_submit():
        # Login and validate the user.
        # user should be an instance of your `User` class
        shasum = hashlib.sha384(form.password.data.encode()).hexdigest()

        try:
            user = User.get(User.username == form.username.data,
                            User.password == shasum)
        except peewee.DoesNotExist:
            flash("Invalid username or password", "error")
            return redirect(url_for('login'))

        login_user(user)

        return render_template('login.html')  # form.redirect('index')

    return render_template('login.html',
                           form=form,
                           next=request.args.get('next'))
Example #15
0
def login():
    form = LoginForm()
    bcrypt = Bcrypt()
    connection = connect()
    if form.validate_on_submit():
        try:
            email = form.email.data
            cursor = connection.cursor()
            sql = "SELECT email, password FROM users WHERE email = (%s)"
            cursor.execute(sql, email)
            data = cursor.fetchone()
            if data is not None and email == data[
                    'email'] and bcrypt.check_password_hash(
                        data['password'], form.password.data):
                flash('You have successfully logged in!', 'success')
                return redirect(url_for('home'))

            else:
                flash('Login unsuccessful! Please check email and password.',
                      'danger')

        finally:
            connection.close()

    return render_template('login.html', title='Login Page', form=form)
Example #16
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        print("in here 1")
        sys.stdout.flush()
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            print("in here 2")
            sys.stdout.flush()
            return redirect(url_for('login'))
        print(login_user(user, remember=form.remember_me.data))
        print(user.is_authenticated)
        sys.stdout.flush()
        next_page = request.args.get('next')
        if not is_safe_url(next_page):
            return flask.abort(400)
        if not next_page or urlparse(next_page).netloc != '':
            next_page = url_for('display_journal')
        print("should redirect")
        user.is_authenticated = True
        sys.stdout.flush()
        db.session.commit()
        return redirect(next_page)
    else:
        print(form.errors)
        sys.stdout.flush()
    return render_template('login.html', title='Sign In', form=form)
Example #17
0
def login(id=0):
    searchform = SearchForm()
    form = LoginForm()

    if form.validate_on_submit():
        if verify_login(form.number.data, form.password.data):
            flash('You have logged in!', 'primary')

            if sql_query("SELECT * FROM PartIn WHERE playerid=? AND eventid=?",
                         (user.number, id)):
                flash('You are already attending that event', 'warning')
            elif id != 0:
                sql_query("INSERT INTO PartIn values(?,?)", (user.number, id),
                          commit=True)
                sql_query("UPDATE Events SET num=num+1 WHERE id=?", (id, ),
                          commit=True)

            return redirect(url_for('account'))
        else:
            flash('Wrong password or number!', 'danger')

    if searchform.is_submitted():
        data = search_for_events(searchform)
        return home_page()

    return render_template("loginpage.html",
                           title='Login page',
                           user=user,
                           form=form,
                           searchform=searchform)
Example #18
0
def basic():
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        flash('Welcome home %s' % username)
        return redirect(url_for('index'))
    return render_template('bootstrap.html', form=form)
Example #19
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash(u'Successfully logged in as %s' % form.user.username)
        session['user_id'] = form.user.id
        return redirect(url_for('index'))
    return render_template('login.html', form=form)
Example #20
0
def login():
    """
    Opens the login.html page.
    If there is a session cookie the user is logged in directly
    and redirected to the createrecipe.html page.
    If there is no cookie, the entered username and password
    is beinged checked against the database on submit and if correct
    the user is redirected to the myrecipes.html page and if
    incorrect the user is flashed a message and requires to login again
    """

    if current_user.is_authenticated:
        return redirect(url_for("create_recipe"))

    form = LoginForm()
    if request.method == "POST" and form.validate_on_submit():
        username = mongo.db.user.find_one({"_id": form.username.data})
        if username and User.validate_login(username["password"],
                                            form.password.data):
            user_obj = User(username["_id"], username["display_name"])
            login_user(user_obj)
            return redirect(request.args.get("next") or url_for("my_recipes"))
        else:
            flash("Invalid username and or password")

    return render_template("login.html", form=form)
Example #21
0
def login_view(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = UserModel.objects.filter(username=username).first()

            if user:

                if check_password(password, user.password):
                    token = SessionToken(user = user)
                    token.create_token()
                    token.save()
                    response = redirect('feed/')
                    response.set_cookie(key='session_token', value=token.session_token)
                    return response


                else:
                    print 'User is invalid'

    elif request.method == 'GET':
        form = LoginForm()

    return render(request, 'login.html')
Example #22
0
def usLogin(request):
    context = {}
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            us = form.cleaned_data['us']
            pwd = form.cleaned_data['pwd']
            if r.exists('us:%s:id' %us):        # 检查是否存在该用户关系键值
                uid = r.get('us:%s:id' %us)     # 获取该用户在user表中对应的id
                if r.exists('user:%s' %uid):    # 检查是否存在该用户键值(如user:1)
                    us_, pwd_ = r.hmget('user:%s' %uid, 'username', 'pwd')  # 获取该用户的用户名密码
                    if us_ == us and pwd_ == pwd:   # 校验成功
                        r.hincrby('user:%s' %uid, 'login_count', 1)     # 登陆次数累加
                        r.hset('user:%s' %uid, 'last_login_date', datetime.datetime.now())  # 添加最近登陆
                        # set Cookies
                        res = HttpResponseRedirect('/')
                        ussys = usSystem(request, res, uid)
                        if ussys.testCookie() and ussys.setCookieAndSession():
                            return res

        context['msg'] = u'账号或密码错误'
        context['form'] = form

    request.session.set_test_cookie()
    form = LoginForm()
    context['form'] = form
    return render(request, 'login.html', context)
Example #23
0
def login():
    """ Returns a form for for user login  """
    # initializes page title
    page_title = "Log in"
    form = LoginForm()
    if form.validate_on_submit():
        # check if username exists in db
        existing_user = mongo.db.users.find_one_or_404(
            {"username": form.Username.data.lower()})
        if existing_user:
            # ensure hashed password matches user input
            if check_password_hash(existing_user["password"],
                                   form.Password.data):
                session["user"] = form.Username.data.lower()
                flash("Welcome, {}".format(request.form.get("Username")))
                return redirect(url_for("profile", username=session["user"]))
            else:
                # invalid password match
                flash("Incorrect Username and/or Password")
            return redirect(url_for("login"))
        else:
            # username doesn't exist
            flash("Incorrect Username and/or Password")
        return redirect(url_for("login"))
    return render_template("login.html", form=form, page_title=page_title)
Example #24
0
def login():
    form = LoginForm()
    if form.validate_on_submit():  #로그인이 됬으면 session 사용됬을꺼
        session['userid'] = form.data.get('userid')
        print('login susccss')
        return redirect('/')
    return render_template('login.html', form=form)
Example #25
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate():
        user_id = form.get_user().user_id
        session['user_id'] = user_id
        return redirect(url_for('user_index', user_id=user_id))
    return render_template('login.html', form=form)
Example #26
0
def enterUsers(request):
    # for lists in coComUser:
    form = LoginForm(request.POST)
    if form.is_valid():
        userName = '******' % request.POST.get('userName')
        userPwd = '%s' % request.POST.get('userPwd')
        sql = "SELECT * FROM vomodel_cocomuser u join vomodel_coptnrinf cp on u.userId = cp.userId_id WHERE u.userName='******' AND u.userPwd='%s'" % (
            userName, userPwd)
        cursor = connection.cursor()
        cursor.execute(sql)
        coComUser = cursor.fetchone()
        cursor.close()
        if coComUser:
            # print (coComUser[0][1])
            request.session["userName"] = coComUser[1]
            request.session['userId'] = coComUser[0]
            request.session['userPwd'] = coComUser[2]
            return HttpResponseRedirect(
                '../UserControl/')  # HttpResponseRedirect这是执行条件的
        else:
            return render_to_response('login.jsp', {
                'list': '用户名或者密码错误',
            })
    else:
        return render_to_response('login.jsp', {
            'list': '用户名或者密码不能为空',
        })
Example #27
0
def login():
    form = LoginForm()
    try:
        if form.validate_on_submit():
            user_name = request.form.get('username', None)
            password = request.form.get('password', None)
            remember_me = request.form.get('remember_me', False)
            if not checkusername(user_name):
                return render_template('error.html',
                                       title='Login Fail',
                                       value='Illegal username')
            user = User(user_name)
            if user.verify_password(password):
                login_user(user, remember=remember_me)
                return redirect(url_for('index'))
            else:
                return render_template('error.html',
                                       title='Login Fail',
                                       value='Wrong username or password')
        else:
            return render_template('error.html',
                                   title='Login Fail',
                                   value='Please fill all part')
    except:
        #print(e)
        return render_template(
            'error.html',
            title='login Fail',
            value=
            'Oops, we encounter some problems, please contact us for details.')
Example #28
0
def index():
    if current_user.is_authenticated:
        logout_user()
    form_login = LoginForm(prefix="form_login")
    sign_form = SignUpForm(prefix="sign_form")
    if form_login.validate_on_submit() and request.method == 'POST':
        user = User.query.filter_by(email=form_login.email.data).first()
        if user is not None and user.verify_password(form_login.password.data):
            if user.admin == 1:
                login_user(user)
                return redirect(request.args.get('next') or url_for('admin'))
            return redirect(request.args.get('next') or url_for('index'))
            login_user(user)
            return redirect(
                request.args.get('next') or url_for('inicio', success=False))
        # flash("Correo o contrasena invalido", category='error')
        return "<script type=\"text/javascript\">\
                alert(\"Correo o contraseña inválido.\");\
                window.location.href = '/'\
                </script>"

    login_inc = False
    reg_inc = False
    if form_login.validate_on_submit() == False and request.method == 'POST':
        login_inc = True
    return render_template('index.html',
                           login_inc=login_inc,
                           reg_inc=reg_inc,
                           form_login=form_login,
                           sign_form=sign_form)
Example #29
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        login_user(form.admin)
        flash("Logged in successfully.")
        return redirect(request.args.get("next") or url_for("index"))
    return render_template("login.html", form=form)
Example #30
0
def login():
	form = LoginForm()
	if form.validate_on_submit():
		flash('Login requested for OpenID="%s", remember_me=%s'% 
			(form.openid.data, str(form.remember_me.data)))
		return redirect('/index')
	return render_template('login.html', title = 'Sign In', form = form)
Example #31
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        name = None
        uni = None
        password = None
        email = None
        phone = None

        user = User(name=form.name.data,
                    uni=form.uni.data,
                    password=form.password.data,
                    email=form.email.data,
                    phone=form.phone.data)
        user.save()

        #session['name'] = user.name
        #session['uni'] = user.uni
        #session['password'] = user.password
        #session['email'] = user.email
        #session['phone'] = user.phone

        session['userid'] = str(user['id'])  #.str??

        redirect(url_for('home'))  #???
    return render_template('login.html',
                           form=form,
                           userid=session.get('userid'))
Example #32
0
def login():
    form = LoginForm(request.form)
    if request.method == "POST" and form.validate():
        if form.username.data == "bsspirit" and form.password.data == "85831923":
            session["login"] = True
            return redirect(url_for("admin"))
    return render_template("login.html")
Example #33
0
def home():
	"""HOMEPAGE"""
	# if user hasn't logged out redirect won't reload login page
	if current_user is not None and current_user.is_authenticated():
		return render_template("main.html")

	message = ""
	message3 = ""
	form = LoginForm()
	
	# following occurs if form conditions are met
	if form.validate_on_submit():
		# query for the user in the database by email. If the user exists then the hashed password
		# is verified. If this password matches the email the user is logged in
		user = model.session.query(model.User).filter_by(email = form.email.data).first()
		if user:
			# salt_unicode = user.salt
			# salt = salt_unicode.encode('utf-8')
			password_unicode = form.password.data
			password = password_unicode.encode('utf-8')
			# hashed = bcrypt.hashpw(password, salt)
			
			if password == user.password_hash:
			# if hashed == user.password_hash:
				login_user(user)
			else:
				message3 = "Incorrect password"
				return render_template("main.html", form=form, message3=message3)

			message = "welcome back %s" % current_user.nickname
			return render_template("main.html", message=message)
		message3 = "It appears we don't have that account on file"
	return render_template("main.html", form=form, message3=message3)
Example #34
0
File: app.py Project: sznote/flask
def login():
    error = None

    form = LoginForm(request.form)

    if request.method == 'POST':
        # if valid_login(
        #         request.form['username'], 
        #         request.form['password']):
        #     return "Welcome Back,  %s" % request.form.get('username')
        # else:
        #     error = "Incorrent username and password"
        if  form.validate_on_submit():
            user = User.query.filter_by(username=form.username.data).first()
            if user:
                if bcrypt.check_password_hash(user.password, form.password.data):
                    session['username'] = form.username.data
                    session['is_author'] = user.is_author
                    return redirect('/login_success')
            error ='Incorrect password'

            # user = User.query.filter_by(
            #  username=form.username.data,
            #  password=form.password.data).limit(1)
            
    return render_template("user/login.html", error=error, form=form)
Example #35
0
def usLogin(request):
    context = {}
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            us = form.cleaned_data['us']
            pwd = form.cleaned_data['pwd']
            if r.exists('us:%s:id' % us):  # 检查是否存在该用户关系键值
                uid = r.get('us:%s:id' % us)  # 获取该用户在user表中对应的id
                if r.exists('user:%s' % uid):  # 检查是否存在该用户键值(如user:1)
                    us_, pwd_ = r.hmget('user:%s' % uid, 'username',
                                        'pwd')  # 获取该用户的用户名密码
                    if us_ == us and pwd_ == pwd:  # 校验成功
                        r.hincrby('user:%s' % uid, 'login_count', 1)  # 登陆次数累加
                        r.hset('user:%s' % uid, 'last_login_date',
                               datetime.datetime.now())  # 添加最近登陆
                        # set Cookies
                        res = HttpResponseRedirect('/')
                        ussys = usSystem(request, res, uid)
                        if ussys.testCookie() and ussys.setCookieAndSession():
                            return res

        context['msg'] = u'账号或密码错误'
        context['form'] = form

    request.session.set_test_cookie()
    form = LoginForm()
    context['form'] = form
    return render(request, 'login.html', context)
Example #36
0
def login():
    """
    Handle requests to the /login route
    Log an Client in through the login form
    """
    if current_user.is_authenticated:
		return redirect(url_for('authentication.area'))
    form = LoginForm()
    if form.validate_on_submit():

        # check whether Client exists in the database and whether
        # the password entered matches the password in the database
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            # log Client in
            login_user(user)

            # redirect to the dashboard page after login
            return redirect(url_for('authentication.area'))

        # when login details are incorrect
        else:
            flash('Invalid email or password.')

    # load login template
    return render_template('users/index.html', form=form, title='Login')
Example #37
0
def login():
    errors = []
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit() == False:
            flash('All fields are required')
            return render_template('login.html', form = form)
        else:
            email = request.form['email']
            password = request.form['password']
            print email , password
            db = connect_db()
            try:
                user_info = auth.authenticate_using_password(email, password, db)
                print user_info
            except BadPasswordError:
                flash("InValid Password")
                response = make_response(redirect(url_for('login')))
                return response
            except NoUserExistsError:
                flash("No User Exists")
                response = make_response(redirect(url_for('login')))
                return response
            session['access_token']= user_info['access_token']
            print "this is sesssion info: %s" %(dir(session))
            response = make_response(redirect(url_for('users')))
            return no_cache(response)


    else:
        return render_template('login.html', form = form)
Example #38
0
 def login(self):
     form = LoginForm(request.form)
     if request.method == 'POST' and form.validate():
         user = form.get_user()
         login_user(user)
         redirect(url_for('.index'))
     self._template_args['form']=form
     return super(MyIndexView,self).index()
Example #39
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash(form.username.data + '|' + form.passwd.data)
        return redirect(url_for('success'))

    else:
        return render_template('login.html', form=form)
Example #40
0
 def login(self):
     form = LoginForm(request.form)
     if request.method == 'POST' and form.validate():
         user = form.get_user()
         login_user(user)
         redirect(url_for('.index'))
     self._template_args['form'] = form
     return super(MyIndexView, self).index()
Example #41
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        flash('Login requested for OpenID="' + form.openid.data + '", remember_me=' + str(form.remember_me.data))
        return redirect('/index')
    return render_template('login.html',
                           title = 'Sign In',
                           form = form,
                           providers = app.config['OPENID_PROVIDERS'])
Example #42
0
def user_register():
    name=None
    form = LoginForm(request.form)
    if request.method=='POST':
        if form.validate_on_submit():
            session['name'] = request.form['username']
            session['logged_in'] = True
            return redirect(url_for('newgame'))
    return render_template('login.html', form=form)
Example #43
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, form.remember_me.data)
            return redirect(url_for('main.index'))
        flash("Invalid username or password")
    return render_template('auth/login.html', form=form)
Example #44
0
File: app.py Project: Elenw/zwiki
def user_login():
    form = LoginForm()
    if form.validate_on_submit():
        user = users.get_user(form.name.data)
        login_user(user)
        user.set('authenticated', True)
        flash('Login successful.', 'success')
        return redirect(request.args.get("next") or url_for('index'))
    return render_template('login.html', form=form)
Example #45
0
def login_in():
    form=LoginForm()
    user=form.name.data
    password=form.password.data
    if form.validate_on_submit():
        if user=="ioiogoo" and password=="1":
            session["name"]=form.name.data
            return redirect(url_for("index"))
        flash("password false!")
        return redirect(url_for("login_in"))
    return render_template("login.html",form=form)
Example #46
0
def login():    
    form = LoginForm(csrf_enabled=False) 
              
    if form.validate_on_submit():
        user = User.query.filter_by(username = form.username.data).first()
        if user is not None and User.query.filter_by(password = form.password.data).first():
            login_user(user)
            return redirect(url_for('admin'))                
        else:
            return redirect(url_for('login')) 
    return render_template('login.html', form = form)
Example #47
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 oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html',
        title='Sign In',
        form=form,
        providers=settings.OPENID_PROVIDERS)
Example #48
0
def login(request):
	param={}
	if request.method=="POST":
		form = LoginForm(request.POST)
		if not form.is_valid():
			return HttpResponseRedirect('/login/')
		else:
			return HttpResponseRedirect('/sample/')
	else:
		form = LoginForm()
	param['form']=form
	param.update(csrf(request))
	return render_to_response('login.html',param)
Example #49
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['username']).first()
            if user is not None and bcrypt.check_password_hash(
               user.password, request.form['password']):
                login_user(user)
                flash('You were just logged in')
                return redirect(url_for('home.home'))  # blueprint.viewfuntion
            else:
                error = 'Invalid credentials, Please try again.'
    return render_template('login.html', form=form, error=error)
Example #50
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['username']).first()
            if user is not None and bcrypt.check_password_hash(user.password, request.form['password']):
                session['logged_in'] = True
                flash('You where logged in!')
                return redirect(url_for('home'))
        else:
             error = 'Invalid credentials. please log again.'

    return render_template('login.html', form=form, error=error)
Example #51
0
def login():

    form = LoginForm()
    if form.validate_on_submit():
        user = UserModel.query.filter_by(email = form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data) #记录登录IP和时间
            db.session.add(UserLoginInfoModel(uid=current_user.id, ip=request.remote_addr, ltime=datetime.now()))
            db.session.commit()
            return redirect(request.args.get('next') or url_for('main.index'))
    else:
        flash_errors(form)

    return render_template('/login.html', form=form)
Example #52
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        m_usr = User.get_by_username(form.username.data)
        # app.logger.debug(m_usr)

        if m_usr is not None and m_usr.check_password(form.password.data):
            # set flask-login to remember the user's ID in HTTP session
            login_user(m_usr, form.remember_me.data)
            flash("{} login successfully!".format(m_usr.username))
            # after login successfully it can direct back add view
            return redirect(request.args.get('next') or url_for('index'))
        flash('User Inputs are not match!')
    return render_template("login.html", form= form)
Example #53
0
def login():
    form = LoginForm(request.form)
    print form.username.data
    if form.validate_on_submit():
        user = form.get_user(current_app)
        if user is None:
            flash("Invalid user")
            return render_template("login.html", form=form)
        if not user.verify(form.username.data, form.password.data):
            flash("Invalid password")
            return render_template('login.html', form=form)
        # success login user
        _login.login_user(user, remember=True)
        return redirect(url_for(".timeline"))
    return render_template("login.html", form=form)
Example #54
0
def login():
    error = None
    form = LoginForm(request.form) #creates istance of form
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['username']).first()
            if user is not None and bcrypt.check_password_hash(user.password, request.form['password']):
                session['logged_in'] = True #session cookie in browser
                #session['name'] = user
                flash('You were logged in.')
                return redirect(url_for('home'))
                error = 'Invalid Credentials. Please try again.'
            else:
                error = 'Invalid Credentials. Please try again.'
    return render_template('login.html',form=form, error=error)
Example #55
0
def login_boss():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            if (request.form['username'] != app.config['USERNAME']) or (request.form['password'] != app.config['PASSWORD']):
                error = 'Invalid Credentials. Please try again.'
            else:
                #login_user(user)
                session['logged_in'] = True

                flash('You were just logged in!')
                return redirect(url_for('welcome_boss'))
            #if not session.get('logged_in'):
                #abort(500) 
    return render_template('login.html', form=form, error=error)
Example #56
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(name=request.form['username']).first()
            if user is not None and bcrypt.check_password_hash(
                user.password, request.form['password']
            ):
                login_user(user)
                flash('You were logged in. Go Crazy.')
                return redirect(url_for('home.home'))

            else:
                error = 'Invalid username or password.'
    return render_template('login.html', form=form, error=error)
Example #57
0
def login():
    if current_user.is_authenticated():
        return redirect(url_for('index'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.login_check(request.form.get('user_name'),
                                request.form.get('password'))
        if user:
            login_user(user)
            flash('welcome!')
            return redirect(url_for('index'))
        else:
            flash('error')
            return redirect('/login')

    return render_template('login.html',form = form)
Example #58
0
def login():
    if g.user is not None:
        return redirect(url_for('index'))
    login_form = LoginForm()
    name = login_form.id.data
    pwd = login_form.pwd.data
    remember = login_form.remenber.data
    if login_form.validate_on_submit():
        user = login_valid(name, pwd)
        if user is not None:
            g.user = user
            session['name'] = user.name
            session['id'] = user.id
            return redirect(url_for('index', name=user.name))
        else:
            flash('error name or password', 'alert-warning')
    return render_template('login.html', form=login_form)
Example #59
0
def login():
  error = None
  form = LoginForm(request.form)
  if request.method == 'POST':
      if form.validate_on_submit():
          # Flask login does not handle authentication so we do this
          # Using Bcrypt to check
          user = User.query.filter_by(name=request.form['username']).first()
          if user is not None and bcrypt.check_password_hash(
            user.password, request.form['password']):
              login_user(user)
              # session['logged_in'] = True
              flash("You were just logged in")
              return redirect(url_for('home.home'))
          else:
            error = 'Invalid Credentials. Please try again.'
  return render_template('login.html',form=form, error=error)
Example #60
0
def login():
    name = None
    password = None
    t_pa = None
    form = LoginForm()
    if  form.validate_on_submit():
        name = form.data['name']
        t_pa = form.data['password']
    cursor = db.zhanghao.find({"username": name})
    for document in cursor:
        password = document["password"]
        if t_pa == password and t_pa is not None:
            session['username'] = form.data['name']
            return  redirect(url_for('index',username=name))
        else:
            flash('Looks like you have typed wrong password!')
    return render_template('login.html', form=form, name=name, password=password)