Exemple #1
0
def login():
    if not 'username' in session and not 'password' in session and not 'id' in session:
        form = LoginUser()
        error = None
        if form.validate_on_submit() and request.method == 'POST':
            username = form.username.data
            query = User.query.filter_by(username=username).first()

            if query is not None and query.username==username:
                password = sha256((form.password.data).encode())

                if query.password == password.hexdigest():
                    session['id'] = query.id
                    session['username'] = username
                    session['password'] = password.hexdigest()
                    return redirect(url_for('index'))
                else:
                    error = 'Username and/or password incorrect'
            else:
                error = 'Username and/or password incorrect'

        return render_template('auth/login.html', form=form, error=error)

    else:
        abort(404)
Exemple #2
0
def login():
    form = LoginUser()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        login_user = User.authenticate(username, password)
        if login_user:
            session['user_id'] = login_user.id
            return redirect(url_for('user_profile', id=login_user.id))
        else:
            flash('Invalid Username/Password')
    return render_template('login.html', form=form)
Exemple #3
0
def login():
    form = LoginUser()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data

        user = User.authenticate(username=username, password=password)
        session['username'] = user.username
        if session['username'] == user.username:
            return redirect(f'/users/{username}')
    else:
        return render_template("login.html", form=form)
Exemple #4
0
def login():
    form = LoginUser()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            if check_password_hash(user.password, form.password.data):
                login_user(user)
                return redirect(url_for('get_all_posts'))
            else:
                flash("This password is incorrect")
                return redirect(url_for('login'))
        else:
            flash("This email not exist")
            return redirect(url_for('login'))
    return render_template("login.html", form=form, current_user=current_user)
Exemple #5
0
def handle_login():
    """ handles user login """
    form = LoginUser()

    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        authentication = User.log_in_user(form)
        if authentication:
            session["username"] = username
            return redirect(f"/users/{username}")
        else:
            form.username.errors = ["Incorrect username/password"]
    else:
        return render_template("login.html", form=form)
Exemple #6
0
def display_login_form_and_handle_login_form():
    """Displays the login form and handles submitted forms"""

    form = LoginUser()

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and user.validate(form.password.data):
            session['user_id'] = user.id
            return redirect(f'/users/{form.username.data}')
        else:
            form.username.errors.append("Invalid Username/Password")
            return render_template("login.html", form=form)

    else:
        return render_template("login.html", form=form)
def login():
    form = LoginUser()
    if form.validate_on_submit():
        user = db.session.query(User).filter(
            User.email == form.email.data).first()
        if user:
            if check_password_hash(user.password, form.password.data):
                login_user(user)
                return redirect(url_for('get_all_posts'))
            else:
                flash("Password incorrect, please try again.")
                return render_template("login.html", form=form)
        else:
            flash("That email does not exist, please try again.")
            return render_template("login.html", form=form)
    else:
        return render_template("login.html", form=form)
Exemple #8
0
def login():
    form = LoginUser()
    if form.validate_on_submit():
        email = form.email.data
        password = form.password.data
        user = User.query.filter_by(email=email).first()
        if not user:
            flash("That email does not exist, please try again.")
            return redirect(url_for('login'))
        elif not check_password_hash(user.password, password):
            flash('Password incorrect, please try again.')
            return redirect(url_for('login'))
        else:
            login_user(user)

            return redirect(url_for("get_all_posts"))
    return render_template("login.html", form=form, current_user=current_user)
def login():
    """login user to account"""

    form = LoginUser()

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

        user = User.authenticate(username, password)

        if user:
            session["username"] = user.username
            return redirect(f"/users/{user.username}")
        else:
            form.username.errors = ["Bad name/password"]
    else:
        return render_template("login-user-form.html", form=form)
Exemple #10
0
def login_user():
    """process the login form and make sure user is authenticated, redirect to secret"""

    form = LoginUser()

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

        login_user = User.authenticate(username, password)

        if login_user:
            session["username"] = login_user.username  # keep logged in
            return redirect(f"/users/{username}")

        else:
            form.username.errors = ["Bad name/password"]

    return render_template("login.html", form=form)
def login():
    form = LoginUser()

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

        if user:
            if check_password_hash(user.password, form.password.data):
                login_user(user)
                return redirect(url_for('get_all_posts'))
            else:
                flash("Incorrect Credentials.")
                return redirect(url_for('login'))
        else:
            flash("We do not have any account associated with that email.")
            return redirect(url_for('login'))

    return render_template("login.html", form=form)
Exemple #12
0
def login():
    form = LoginUser()
    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, form.remember_me.data)
            flash('ok')
            return redirect(request.args.get('next') or url_for('main.index'))
        else:
            flash('error')
    return render_template('login.html', form=form)
Exemple #13
0
def show_login():

    form = LoginUser()

    if form.validate_on_submit():

        username = form.username.data
        password = form.password.data

        user = User.query.filter(User.username == username).first()

        session[USER_KEY] = user.toJSON()
        session['username'] = user.username

        #        return redirect("/secret")
        if user:
            return redirect(f"/users/{user.username}")
        else:
            form.username.errors = ["Invalid username/password."]
            return render_template("login.html", form=form)

    return render_template("login.html", form=form)
Exemple #14
0
def login():

    form = LoginUser()

    if form.validate_on_submit():

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

        if user is None:
            return render_template('not_registered.html')

        elif user.check_password(form.password.data) == False:
            return render_template('login.html', form=form, flag=True)

        elif user.check_password(form.password.data):
            login_user(user, remember=form.check.data)
            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, flag=False)
Exemple #15
0
def loginUser(request):
    WEB_FILES, LIVE_SITE, totalNumberOfGames, sendBackUrl, startOffset, \
    user, userId, message, topHits, topRated = initialVars(request)

    #the sendbackUrl will be root if they don't process the form.
    sendBackUrl = '/'

    if request.method == "GET":
        loginForm = LoginUser()
        request.session['sendBackUrl'] = request.GET.get('sendBack', '/')
        return render_to_response('login.html', locals())
    elif request.method == "POST":
        loginForm = LoginUser(request.POST)
        sendBackUrl = request.session.get('sendBackUrl', '/')

        if loginForm.is_valid():
            name = loginForm.cleaned_data['name']
            password = loginForm.cleaned_data['password']

            user = authenticate(username=name, password=password)
            if user is not None:
                login(request, user)

                #log(request, 'LOGINUSER', name, 'Successful Log In')

                return HttpResponseRedirect(sendBackUrl)
            else:
                #log(request, 'LOGINUSERERROR', name, 'Invalid Log In')

                message = "Come on, you can try harder. Invalid login."
                return render_to_response('login.html', locals())
        else:
            # form is not valid
            #TODO should display exactly what the error was.
            #log(request, 'LOGINUSERERROR', name, 'Form not Valid')
            return render_to_response('login.html', locals())
Exemple #16
0
def loginUser(request):
   WEB_FILES, LIVE_SITE, totalNumberOfGames, sendBackUrl, startOffset, \
   user, userId, message, topHits, topRated = initialVars(request)

   #the sendbackUrl will be root if they don't process the form.
   sendBackUrl = '/'

   if request.method == "GET":
      loginForm = LoginUser()
      request.session['sendBackUrl'] = request.GET.get('sendBack', '/')
      return render_to_response('login.html', locals())
   elif request.method == "POST":
      loginForm = LoginUser(request.POST)
      sendBackUrl = request.session.get('sendBackUrl', '/')

      if loginForm.is_valid():
         name = loginForm.cleaned_data['name']
         password = loginForm.cleaned_data['password']

         user = authenticate(username=name, password=password)
         if user is not None:
            login(request, user)

            #log(request, 'LOGINUSER', name, 'Successful Log In')

            return HttpResponseRedirect(sendBackUrl)
         else:
            #log(request, 'LOGINUSERERROR', name, 'Invalid Log In')

            message = "Come on, you can try harder. Invalid login."
            return render_to_response('login.html', locals())
      else:
         # form is not valid
         #TODO should display exactly what the error was.
         #log(request, 'LOGINUSERERROR', name, 'Form not Valid')
         return render_to_response('login.html', locals())
Exemple #17
0
def gamePage(request, gameId):
    WEB_FILES, LIVE_SITE, totalNumberOfGames, sendBackUrl, startOffset, \
    user, userId, message, topHits, topRated = initialVars(request)

    sendBackUrl = "/game/" + str(gameId)

    gameId = int(gameId)

    try:
        g = Game.objects.get(id__exact=gameId)
    except ObjectDoesNotExist:
        request.session['message'] = "The Game you requested doesn't exist!"
        return HttpResponseRedirect('/')

    game = GameInfo(g, userId, None)

    #log(request, 'GAMEPAGE', game.name, sendBackUrl)

    comments = [
        CommentInfo(comment.user, comment.whenPosted, comment.text)
        for comment in Comment.objects.filter(
            game=gameId, approved=1).order_by("whenPosted")
    ]

    if request.method == 'GET':
        # comment form is not posted
        commentForm = PostComment(initial={'gameId': gameId})
        loginForm = LoginUser()

    elif request.method == 'POST':
        # Comment form is submitted, POST

        commentForm = PostComment(request.POST)
        if commentForm.is_valid():
            comment = commentForm.cleaned_data['comment']
            gameId = commentForm.cleaned_data['gameId']
        else:
            # need to reload to Game Page with all variables
            return render_to_response('gamepage.html', locals())

        try:
            #gameId = int(request.POST['gameId'])
            game = Game.objects.get(id__exact=gameId)
            if game:
                comment = Comment(game=game,
                                  user=user,
                                  text=comment,
                                  approved=True,
                                  whenPosted=datetime.datetime.utcnow())
                comment.save()

                request.session['message'] = \
                   "Thank you for posting such a brilliant message.  You are really good."

                return HttpResponseRedirect(gamePageUrl(gameId))

            else:  # No game id?!  Just return the user to the home page.
                return HttpResponseRedirect('/')

        except:
            # TODO log that there was an invalid POST
            return HttpResponseRedirect('/')

    # I don't think we get down here
    return render_to_response('gamepage.html', locals())