<commit_before>package controllers

import java.util.UUID
import javax.inject.Inject

import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.services.AvatarService
import com.mohiva.play.silhouette.api.util.PasswordHasherRegistry
import com.mohiva.play.silhouette.api.{LoginEvent, LoginInfo, SignUpEvent, Silhouette}
import com.mohiva.play.silhouette.impl.providers.{CommonSocialProfile, CredentialsProvider}
import models.services.UserService
import models.user.{RegistrationData, UserForms}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc.{AnyContent, Controller, Request}
import models.user.User
import utils.auth.DefaultEnv

import scala.concurrent.Future

class RegistrationController @Inject() (
    val messagesApi: MessagesApi,
    silhouette: Silhouette[DefaultEnv],
    passwordHasherRegistry: PasswordHasherRegistry,
    avatarService: AvatarService,
    authInfoRepository: AuthInfoRepository,
    userService: UserService
) extends Controller with I18nSupport {

  def registrationForm = silhouette.UserAwareAction.async { implicit request =>
    Future.successful(Ok(views.html.signIn(UserForms.registrationForm)))
  }

  def register = silhouette.UnsecuredAction.async { implicit request =>
    UserForms.registrationForm.bindFromRequest.fold(
      form => Future.successful(BadRequest(views.html.signIn(form))),
      data => {
        userService.retrieve(LoginInfo(CredentialsProvider.ID, data.email)).flatMap {
          case Some(user) => Future.successful {
            Ok(views.html.signIn(UserForms.registrationForm.fill(data))).flashing("error" -> "That email address is already taken.")
          }
          case None => saveProfile(data)
        }
      }
    )
  }

  private[this] def saveProfile(data: RegistrationData)(implicit request: Request[AnyContent]) = {
    val loginInfo = LoginInfo(CredentialsProvider.ID, data.email)<commit_msg>fix error when creating account<commit_after>package controllers

import java.util.UUID
import javax.inject.Inject

import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.services.AvatarService
import com.mohiva.play.silhouette.api.util.PasswordHasherRegistry
import com.mohiva.play.silhouette.api.{LoginEvent, LoginInfo, SignUpEvent, Silhouette}
import com.mohiva.play.silhouette.impl.providers.{CommonSocialProfile, CredentialsProvider}
import models.services.UserService
import models.user.{RegistrationData, UserForms}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc.{AnyContent, Controller, Request}
import models.user.User
import utils.auth.DefaultEnv

import scala.concurrent.Future

class RegistrationController @Inject() (
    val messagesApi: MessagesApi,
    silhouette: Silhouette[DefaultEnv],
    passwordHasherRegistry: PasswordHasherRegistry,
    avatarService: AvatarService,
    authInfoRepository: AuthInfoRepository,
    userService: UserService
) extends Controller with I18nSupport {

  def registrationForm = silhouette.UserAwareAction.async { implicit request =>
    Future.successful(Ok(views.html.signIn(UserForms.registrationForm)))
  }

  def register = silhouette.UnsecuredAction.async { implicit request =>
    UserForms.registrationForm.bindFromRequest.fold(
      form => Future.successful(BadRequest(views.html.signIn(form))),
      data => {
        userService.retrieve(LoginInfo(CredentialsProvider.ID, data.email)).flatMap {
          case Some(user) => Future.successful {
            Redirect(routes.RegistrationController.registrationForm).flashing("error" -> "That email address is already taken.")
          }
          case None => saveProfile(data)
        }
      }
    )
  }

  private[this] def saveProfile(data: RegistrationData)(implicit request: Request[AnyContent]) = {
    val loginInfo = LoginInfo(CredentialsProvider.ID, data.email)
{'fraction_non_alphanumeric': 0.09762140733399405, 'fraction_numerical': 0.002973240832507433, 'mean_word_length': 4.8934306569343065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '6071650', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1153, 'n_words': 203}