<commit_before>package com.softwaremill.bootzooka.rest

import com.softwaremill.bootzooka.service.PasswordRecoveryService
import org.apache.commons.lang3.StringUtils
import org.scalatra.BadRequest
import com.softwaremill.bootzooka.common.JsonWrapper
import com.softwaremill.bootzooka.service.user.UserService

/**
 * Servlet handling requests related to password recovery.
 */
class PasswordRecoveryServlet(passwordRecoveryService: PasswordRecoveryService, userService: UserService) extends JsonServlet {

  post("/") {
    val login = (parsedBody \ "login").extractOpt[String].getOrElse("")
    passwordRecoveryService.sendResetCodeToUser(login)
  }

  post("/:code") {
    val code = params("code")
    val password = (parsedBody \ "password").extractOpt[String].getOrElse("")
    if (!StringUtils.isBlank(password)) {
      passwordRecoveryService.performPasswordReset(code, password) match {
        case Left(e) => halt(403, JsonWrapper(e))
        case _ =>
      }
    } else {
      halt(400, JsonWrapper("missingpassword"))
    }
  }
}<commit_msg>PasswordRecoveryServlet now checks if user exists, #78<commit_after>package com.softwaremill.bootzooka.rest

import com.softwaremill.bootzooka.service.PasswordRecoveryService
import org.apache.commons.lang3.StringUtils
import org.scalatra.BadRequest
import com.softwaremill.bootzooka.common.JsonWrapper
import com.softwaremill.bootzooka.service.user.UserService
import com.typesafe.scalalogging.slf4j.Logging

/**
 * Servlet handling requests related to password recovery.
 */
class PasswordRecoveryServlet(passwordRecoveryService: PasswordRecoveryService, userService: UserService) extends JsonServlet {

  post("/") {
    val login = (parsedBody \ "login").extractOpt[String].getOrElse("")

    userService.checkUserExistenceFor(login, login) match {
      case Right(e) => JsonWrapper("No user with given login/e-mail found.")
      case _ => {
        passwordRecoveryService.sendResetCodeToUser(login)
        JsonWrapper("success")
      }
    }
  }

  post("/:code") {
    val code = params("code")
    val password = (parsedBody \ "password").extractOpt[String].getOrElse("")
    if (!StringUtils.isBlank(password)) {
      passwordRecoveryService.performPasswordReset(code, password) match {
        case Left(e) => halt(403, JsonWrapper(e))
        case _ =>
      }
    } else {
      halt(400, JsonWrapper("missingpassword"))
    }
  }
}
{'fraction_non_alphanumeric': 0.11600831600831601, 'fraction_numerical': 0.007068607068607069, 'mean_word_length': 4.346666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1798166', 'n_tokens_mistral': 728, 'n_tokens_neox': 699, 'n_words': 127}