<commit_before>package controllers

import concurrent.Future
import play.api.data.Form
import play.api.data.Forms.tuple
import play.api.data.Forms.text
import play.api.mvc._
import play.api.mvc.Results.Forbidden

class AuthenticatedRequest[A](val username: String, request: Request[A]) extends WrappedRequest[A](request)

object Authenticated extends ActionBuilder[AuthenticatedRequest] {
  def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[SimpleResult]) : Future[SimpleResult] = {
    request.session.get("username").map { username =>
      block(new AuthenticatedRequest(username, request))
    } getOrElse {
      Future.successful(Forbidden)
    }
  }
}

object Session extends Controller {
  val loginForm = Form(
    tuple(
      "username" -> text,
      "password" -> text
    )
  )

  def login : Action[AnyContent] = Action { implicit request =>
    val data = loginForm.bindFromRequest.data
    // FIXME: Check password
    val username = data("username")
    val session = ("username", username)
    Ok("Hello " + username).withSession(session)
  }

  def logout : Action[AnyContent] = Authenticated { request =>
    Ok("Goodbye " + request.username).withNewSession
  }
}<commit_msg>Make loginForm private.<commit_after>package controllers

import concurrent.Future
import play.api.data.Form
import play.api.data.Forms.tuple
import play.api.data.Forms.text
import play.api.mvc._
import play.api.mvc.Results.Forbidden

class AuthenticatedRequest[A](val username: String, request: Request[A]) extends WrappedRequest[A](request)

object Authenticated extends ActionBuilder[AuthenticatedRequest] {
  def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[SimpleResult]) : Future[SimpleResult] = {
    request.session.get("username").map { username =>
      block(new AuthenticatedRequest(username, request))
    } getOrElse {
      Future.successful(Forbidden)
    }
  }
}

object Session extends Controller {
  private val loginForm = Form(
    tuple(
      "username" -> text,
      "password" -> text
    )
  )

  def login : Action[AnyContent] = Action { implicit request =>
    val data = loginForm.bindFromRequest.data
    // FIXME: Check password
    val username = data("username")
    val session = ("username", username)
    Ok("Hello " + username).withSession(session)
  }

  def logout : Action[AnyContent] = Authenticated { request =>
    Ok("Goodbye " + request.username).withNewSession
  }
}
{'fraction_non_alphanumeric': 0.1191437802907916, 'fraction_numerical': 0.0, 'mean_word_length': 4.149688149688149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2241443', 'n_tokens_mistral': 725, 'n_tokens_neox': 721, 'n_words': 163}