Exemple #1
0
def login():
	form = LoginForm()
	if form.validate_on_submit():
		user = UserModel.find_by_eid(form.eid.data)
		if user is not None and user.check_password(form.password.data):
			return render_template('base.html')
	return render_template('login.html', form = form)
Exemple #2
0
def link():
    form = LoginForm()

    if not session.get("oauth"):
        return redirect(url_for("static.login", next=get_next_url(request.path)))

    if not form.is_submitted():
        form.key.data, form.key.errors = OAuthService.get_potential_name(
            session["oauth"]
        )
        form.password.data = ""

    if form.validate_on_submit() or current_user.is_authenticated:
        if current_user.is_authenticated:
            user, is_authed = current_user, current_user.is_authenticated
        else:
            user, is_authed = form.get_or_create_account()
        if user and is_authed:
            if user["hash"] is not None:
                form.key.errors.append(
                    "Given account is already linked to an OpenID, please use a different account"
                )
                return render_template("oauth_link.tpl", form=form)
            OAuthService.link(user.get_id(), session["oauth"]["sub"])
            del session["oauth"]
            flash("Successfully linked accounts!")
            form.login(user)

    return render_template("oauth_link.tpl", form=form)
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and user.check_password(form.password.data):
            login_user(user)
            token = jwt.encode(
                {
                    'user':
                    user.username,
                    'exp':
                    datetime.datetime.utcnow() +
                    datetime.timedelta(seconds=180)
                }, app.config['SECRET_KEY'])
            #return jsonify({'token':token.decode('utf-8')})
            next_page = request.args.get('next')
            if not next_page or url_parse(next_page).netloc != '':
                next_page = url_for('profile', username=user.username)
            return redirect(next_page)
        elif not user.check_password(form.password.data):
            flash('Incorrect Password. Please try again with valid password')
    elif form.errors:
        flash('Login Failed.Please try again')
        return redirect(url_for('login'))

    return render_template('login.html', form=form, title='Sign In')
Exemple #4
0
def login():
    if current_user.is_authenticated:
        initUser()
        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):
            if str(user.parent_org) != 'None':
                emp = empList.query.filter_by(empname=user.username).first()
                if not emp:
                    flash(
                        "Login Unsuccessful, Your Organization request has not been approved yet.",
                        "warning")
                    return render_template('login.html',
                                           title='Login',
                                           form=form)
            login_user(user, remember=form.remember.data)
            next_page = request.args.get(
                'next'
            )  #args is a dictionary we use get method so that if the next prameter dost not exits it gives none so dont use square brackets with the key
            initUser()
            flash("Login Successful", "success")
            return redirect(next_page) if next_page else redirect(
                url_for('home')
            )  # this is done so that if login page is directed from a restricted page then after login it redirects to that page instead of home page
        else:
            flash("Login Unsuccessful, Please check your email and password",
                  "danger")
    return render_template('login.html', title='Login', form=form)
Exemple #5
0
def login():
    # save the next parameter in the session
    session["next"] = get_next_url()
    form = LoginForm()
    if form.validate_on_submit():
        user, is_authed = form.get_or_create_account()
        if user and is_authed:
            form.login(user)
    return render_template("login.tpl", form=form)
def login():

    # if user is already logged in, send them to the homepage
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    # create login form object
    form = LoginForm()

    # if login form has been validly submitted
    if form.validate_on_submit():

        db = get_db()
        # set up db cursor
        mycursor = db.cursor()

        # query the Users mySQL table for the userID, email address and password
        query = """SELECT userID, userEmail, userPW from Users WHERE userEmail=%s"""
        mycursor.execute(query, (form.email.data, ))
        user = mycursor.fetchone()
        mycursor.close()

        # if the user exists, store the info provided by the query in separate variables
        if user:
            userID = user[0]
            email = user[1]
            password = user[2]

            # then verify that the entered password matches the password stored in the db
            if user and bcrypt.check_password_hash(password,
                                                   form.password.data):

                # if so, create the a user object (this is necessary for Flask-Login)
                user = User(userID, email, password)

                # call Flask-Login login_user function to create the session for the user
                login_user(user, remember=form.remember.data)

                # if there is a next parameter in the url, grab it to forward the user to the appropriate name.
                next_page = request.args.get('next')

                # now that the user has logged in, send her to either the next page or the account page
                return redirect(next_page) if next_page else redirect(
                    url_for('requests'))

            # if email address is found but password doesn't match, display error message
            else:
                flash('Incorrect password.', 'danger')

        # if email address is not found, display error message
        else:
            flash('Email address not found. Have you registered?', 'danger')

    return render_template('login.html', title='Login', form=form)
Exemple #7
0
def loginPage():
    form = LoginForm()
    if form.validate_on_submit():
        student = Student.query.filter_by(rollno=form.rollno.data).first()
        if student is not None and student.check_password(form.password.data):
            flash('Logged in successfully.')
            login_user(student)
            return redirect(url_for('admin.dashboard', rollno=student.rollno))
        else:
            flash('User is not registered.')
            return render_template('login.html', form=form)
    return render_template('login.html', form=form)
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash('Başarıyla giriş yaptınız!')
            next = request.args.get('next')
            if next == None or not next[0] == '/':
                next = url_for('welcome')
            return redirect(next)
    return render_template('login.html', form=form)
Exemple #9
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email = form.email.data).first()
        if user and user.checkPassword(form.password.data) and user is not None:
            login_user(user)
            flash("Logged in successfully!")
            next = request.args.get('next')
            if next == None or not next[0]=='/':
                next = url_for('index')
            return redirect(next)
    return render_template('login.html', form = form)
Exemple #10
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash('Login Successful')
            next = request.args.get('next')
            if next == None or not next[0] == '/':
                next = url_for('login')
            return redirect(next)
    return render_template('login.html', form=form)
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 Unsuccessful. Please check email and password', 'danger')
    return render_template('login.html', title='Login', form=form)
Exemple #12
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        print(user)
        if user.check_password(form.password.data) and user is not None:
            login_user(user)
            flash('Logged Successfully', 'success')
            next = request.args.get('next')
            if not is_safe_url(next):
                return abort(400)
        return redirect(next or url_for('index'))
    return render_template('login.html', form=form)
Exemple #13
0
def login():
    form = LoginForm()
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    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 Unsuccesful. Please check email and Password", "danger")
    return render_template("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(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('index'))
        else:
            flash('Login unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', pageTitle='Sign In', 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(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            #can take two arguments, second is for remember
            login_user(user, remember=form.remember.data)
            return redirect(url_for('index'))
        else:
            flash('Login unsuccessful!', 'danger')
    return render_template('login.html', title='Login', form=form)
Exemple #16
0
def login():
    form = LoginForm()
    if current_user.is_authenticated:
        return redirect(url_for('user_show'))
    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)
            flash("Welcome Back, {}!".format(user.email), 'success')
            return redirect(url_for('user_show'))
        else:
            flash('Login Unsuccessful. Please check your email and password', 'danger')
            render_template('/users/login.html', form=form)
    return render_template('users/login.html', form=form)
def login():

    if current_user.is_authenticated:
        return redirect(url_for('welcome'))

    form = LoginForm()

    if form.validate_on_submit():
        #user = User.query.filter_by(username=form.username.data).first()
        user = User.query.filter(User.username == form.username.data).first()

        if user is None or not user.check_password(
                form.password.data) or user.lockout:

            if user is not None:

                user.fail_count = user.fail_count + 1
                db.session.commit()

                if user.fail_count > 5:
                    user.lockout = True
                    db.session.commit()

                    app.logger.info("User[{}]'s account is locked")
                    flash(
                        "Your account has been locked due to excessive failed login attempts,"
                        "please reset your password to log back in")
                    return redirect(url_for('reset_password_request'))

            flash(
                "Apologies but that is an Invalid username/password combination"
            )
            app.logger.info("Login Attempt Failed")
            return redirect(url_for('login'))

        flash('Login Requested for user {}, remember_me={}'.format(
            form.username.data, form.rmbr_user.data))
        login_user(user, remember=form.rmbr_user.data)
        session['username'] = user.username

        ret_page = request.args.get('next')

        if not ret_page:
            ret_page = url_for('welcome')

        app.logger.info("Logging in user[{}]".format(form.username.data))
        return redirect(ret_page)

    return render_template("login.html", title="Log In", form=form)
Exemple #18
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['name']).first()
            if user is not None and user.password == request.form['password']:
                session['logged_in'] = True
                session['user_id'] = user.id
                session['role'] = user.role
                flash('Welcome!')
                return redirect(url_for('tasks'))
            else:
                error = 'Invalid username or password.'
    return render_template('login.html', form=form, error=error)
Exemple #19
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'))
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != "":
            next_page = url_for('index')
        login_user(user, remember=form.remember_me.data)
        return redirect(next_page)
    return render_template('login.html', title="Sign In", form=form)
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is not None:
            if user.check_password(form.password.data):
                login_user(user)
                next = request.args.get('next')
                if next == None or not next[0] == '/':
                    next = url_for('main.home')
                return redirect(next)
        flash(
            'The email or password you entered do not match our records.  Please try again.'
        )
    return render_template('login.html', form=form)
Exemple #21
0
def login():
    if session.get("admin") is True:
        # already authenticated
        return redirect("/admin")

    form = LoginForm()
    if form.validate_on_submit():
        admin = get_setting("admin").get(form.key.data, None)
        if admin and admin == form.password.data:
            # Allow for a persistent login
            session.permanent = True
            session["admin"] = True
            return redirect("/admin")
        flash("There was a problem authenticating you.", "error")
    return render_template("admin_login.tpl", form=form)
def login():
  form = LoginForm()
  if form.validate_on_submit():

  #if request.method == "POST":
    name = form.username.data
    password = form.password.data
    user = db.session.query(User).filter_by(name=name, password=password).first()
    if user:
      login_user(user)
      return redirect(url_for('user_home', username=user.name, userid=user.id))
    else:
      flash("Username or password was incorrect.")
      return redirect(url_for('login'))
  return render_template('login.html', form=form)
def login():
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            email = form.email.data
            password = form.password.data
            user = User.query.filter_by(email=email).first()
            if user is None or not user.check_password(password):
                return Response("<p>Incorrect email or password</p>")
            login_user(user, remember=True)
            return redirect(url_for('browse'))
        else:
            return Response("<p>invalid form</p>")
    else:
        return render_template('login.html', form=form)
Exemple #24
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('lessons'))
    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, remember=form.remember.data)
            next_page = request.args.get('next')
            flash("You have been logged in succesfully", 'success')
            return redirect(next_page) if next_page else redirect(
                url_for('lessons'))
        else:
            flash("Login Unsuccesful.Please check your email and password!",
                  'danger')
    return render_template('login.html', title='Login', form=form)
Exemple #25
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 is not None and user.check_password(password):
            login_user(user, remember=True)
            # 设置session过期时间 过期时间一天
            # session.permanent = True
            # app = current_app._get_current_object()
            # app.permanent_session_lifetime = timedelta(days=1)
            return redirect(url_for('index'))
        return redirect(url_for('login'))
    form.password.data = ''
    return render_template('login.html', form=form)
Exemple #26
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            username = form.username.data
            password = form.password.data
            user = User.query.filter_by(username=username).first()
            if user is None or not user.check_password(password):
                return Response("<p>Incorrect username or password</p>")
            login_user(user, remember=True)
            next_page = request.args.get('next')
            if not next_page or url_parse(next_page).netloc != '':
                next_page = url_for('private_route')
            return redirect(next_page)
        else:
            return Response('<p>Invalid form</p>')
    return render_template('login.html', form=form)
Exemple #27
0
def login():
    if current_user.is_authenticated:
        if current_user.type == "user":
            return redirect(url_for('user'))
        if current_user.type == "admin":
            return redirect(url_for('admin'))

    form = LoginForm()

    if form.validate_on_submit():
        email_login = request.form['email_login']
        password_login = request.form['password_login']
        option1 = request.form.get("option1")
        session['type'] = option1

        if option1 == "user":

            user = User.query.filter_by(email=email_login).first()
            if user and bcrypt.check_password_hash(user.password,
                                                   password_login):

                login_user(user, remember=form.remember.data)
                next_page = request.args.get('next')

                return redirect(url_for('user'))
            else:
                flash('Login Unsuccessfull')
        elif option1 == "admin":

            admin = Admin.query.filter_by(email=email_login).first()
            if admin and bcrypt.check_password_hash(admin.password,
                                                    password_login):
                login_user(admin, remember=form.remember.data)
                next_page = request.args.get('next')
                return redirect(next_page) if next_page else redirect(
                    url_for('admin'))
            else:
                flash('Login Unsuccessfull')
        else:
            flash('Pls select one option')

    return render_template('login.html', title='Login', form=form)
Exemple #28
0
def loginPage():
    form = LoginForm()
    if form.validate_on_submit():
        stu = Student.query.filter_by(rollno = form.rollno.data).first()

        if stu is not None and stu.check_password(form.password.data) :

            flash('Logged in successfully.')
            login_user(stu)
            next = request.args.get('next')

            if next == None or not next[0]=='/':
                next = url_for('admin.registerExam')

            return redirect(next)

        else:
            flash('User is not registered.')
            return render_template('login.html', form = form)

    return render_template('login.html', form=form)
Exemple #29
0
def login():
    loginform = LoginForm(request.form)
    if request.method == 'POST':
        if loginform.validate_on_submit():
            email = request.form.get('username')
            password = request.form.get('password')
            user = User.query.filter_by(email=email).first()
            if user is None or not user.check_password(password):
                return Response("<p>Incorrect username or password</p>")
            login_user(user, remember=True)
            next_page = request.args.get('next')
            if not next_page or url_parse(next_page).netloc != '':
                if current_user.account_type == "teacher":
                    next_page = url_for('profile_template')
                else:
                    next_page = url_for('feed')
            return redirect(next_page)
        else:
            return Response("<p>invalid form</p>")
    else:
        return render_template('index.html', loginform=loginform)
Exemple #30
0
def login():
    """ 
    This will rediirect a logged-in user to home-page when they click the login button on our site
    Here, 'current_user.is_authenticated' is a boolean variable.
    """
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    """
    We will create an instance of a login form everytime to send to the application.
    """
    form = LoginForm()
    if form.validate_on_submit():
        """
        Authenticating user to login using manual dummy data
        if form.email.data == '*****@*****.**' and form.password.data == 'password':
            flash('You have been Logged in successfully!', 'success')
            return redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check username and password', 'danger') # category to flash alert in bootstrap.
        """
        """ Authenticating user login using data stored in our database. """
        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)  #logs in the user.
            #now we will check for any redirection query parameter (like next)
            next_page = request.args.get('next')
            """
            Here, 'args' is a dictionary and we don't want to access whole dictionary as well as it is optional
            So, we use the 'get' method in dictionary so that when 'next' is not found, then it returns 'none' instead of throwing errors.
            """
            return redirect(next_page) if next_page else redirect(
                url_for('home'))
            #This is actually an example of using ternary conditional operator in python
            #condition ? if : else
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')  # category to flash alert in bootstrap.
    #After this we will pass this form to our HTML Template
    return render_template('login.html', title='Login', form=form)