<commit_before>package com.softwaremill.codebrag.rest

import com.softwaremill.codebrag.service.user.Authenticator
import org.scalatra
import com.softwaremill.codebrag.activities.{LoginForm, LoginFailedException, LoginUserUseCase}
import com.softwaremill.codebrag.activities.finders.UserFinder

class SessionServlet(val authenticator: Authenticator, loginUseCase: LoginUserUseCase, userFinder: UserFinder) extends JsonServletWithAuthentication {

  post("/") {
    try {
      loginUseCase.execute(LoginForm(login, password, rememberMe)) {
        authenticate()
      } match {
        case Right(user) => scalatra.Ok(user)
        case Left(errors) => scalatra.Unauthorized(errors.fieldErrors)
      }
    } catch {
      case e: LoginFailedException => scalatra.Unauthorized(Map("errors" -> List(e.msg)))
    }
  }

  get("/") {
    haltIfNotAuthenticated()
    userFinder.findLoggedInUser(user)
  }

  delete("/") {
    if (isAuthenticated) {
      // call logout only when logged in to avoid NPE
      logOut()
    }
  }

  // update user details: password, admin, active
  put("/:userId") {

  }

  override def login: String = (parsedBody \ "login").extractOpt[String].getOrElse("")
  override def password: String = (parsedBody \ "password").extractOpt[String].getOrElse("")
  override def rememberMe: Boolean = (parsedBody \ "rememberme").extractOpt[Boolean].getOrElse(false)

}

object SessionServlet {
  val MappingPath = "session"
}<commit_msg>Minor - cleanup unused stuff<commit_after>package com.softwaremill.codebrag.rest

import com.softwaremill.codebrag.service.user.Authenticator
import org.scalatra
import com.softwaremill.codebrag.activities.{LoginForm, LoginFailedException, LoginUserUseCase}
import com.softwaremill.codebrag.activities.finders.UserFinder

class SessionServlet(val authenticator: Authenticator, loginUseCase: LoginUserUseCase, userFinder: UserFinder) extends JsonServletWithAuthentication {

  post("/") {
    try {
      loginUseCase.execute(LoginForm(login, password, rememberMe)) {
        authenticate()
      } match {
        case Right(user) => scalatra.Ok(user)
        case Left(errors) => scalatra.Unauthorized(errors.fieldErrors)
      }
    } catch {
      case e: LoginFailedException => scalatra.Unauthorized(Map("errors" -> List(e.msg)))
    }
  }

  get("/") {
    haltIfNotAuthenticated()
    userFinder.findLoggedInUser(user)
  }

  delete("/") {
    if (isAuthenticated) {
      // call logout only when logged in to avoid NPE
      logOut()
    }
  }

  override def login: String = (parsedBody \ "login").extractOpt[String].getOrElse("")
  override def password: String = (parsedBody \ "password").extractOpt[String].getOrElse("")
  override def rememberMe: Boolean = (parsedBody \ "rememberme").extractOpt[Boolean].getOrElse(false)

}

object SessionServlet {
  val MappingPath = "session"
}
{'fraction_non_alphanumeric': 0.11925640126271483, 'fraction_numerical': 0.0, 'mean_word_length': 4.0837789661319075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3876002', 'n_tokens_mistral': 875, 'n_tokens_neox': 860, 'n_words': 170}