<commit_before>package controllers

import models.User
import com.mohiva.play.silhouette.core.{ LogoutEvent, Environment, Silhouette }
import com.mohiva.play.silhouette.contrib.services.CachedCookieAuthenticator
import scala.concurrent.Future
import javax.inject.Inject
import models.daos.ProductDAO
import forms._
import play.api.Play
import play.api.Logger

/**
 * The basic application controller.
 *
 * @param env The Silhouette environment.
 */
class CardsController @Inject() (implicit val env: Environment[User, CachedCookieAuthenticator])
  extends Silhouette[User, CachedCookieAuthenticator] {

  def add = SecuredAction.async { implicit request =>

    val key = Play.current.configuration.getString("conekta.api_key").getOrElse("")
    Future.successful(Ok(views.html.cards.add(request.identity, CardForm.checkoutForm, key)))

  }

  def create = SecuredAction.async { implicit request =>

    CardForm.checkoutForm.bindFromRequest.fold(
      formWithErrors => {
        Future.successful(Redirect(routes.CardsController.add))
      },
      cardToken => {
        Logger.debug(cardToken)
        
        val user = request.identity
        user.saveCard(cardToken)

        Future.successful(Redirect(routes.ApplicationController.index))
        
      })

  }

}<commit_msg>Flash message added to cards add action.<commit_after>package controllers

import models.User
import com.mohiva.play.silhouette.core.{ LogoutEvent, Environment, Silhouette }
import com.mohiva.play.silhouette.contrib.services.CachedCookieAuthenticator
import scala.concurrent.Future
import javax.inject.Inject
import models.daos.ProductDAO
import forms._
import play.api.Play
import play.api.Logger

/**
 * The basic application controller.
 *
 * @param env The Silhouette environment.
 */
class CardsController @Inject() (implicit val env: Environment[User, CachedCookieAuthenticator])
  extends Silhouette[User, CachedCookieAuthenticator] {

  def add = SecuredAction.async { implicit request =>

    val key = Play.current.configuration.getString("conekta.api_key").getOrElse("")
    Future.successful(Ok(views.html.cards.add(request.identity, CardForm.checkoutForm, key)))

  }

  def create = SecuredAction.async { implicit request =>

    CardForm.checkoutForm.bindFromRequest.fold(
      formWithErrors => {
        Future.successful(Redirect(routes.CardsController.add))
      },
      cardToken => {
        Logger.debug(cardToken)

        val user = request.identity
        user.saveCard(cardToken)

        Future.successful(Redirect(routes.ApplicationController.index).flashing(
          "success" -> "Tarjeta añadida"))

      })

  }

}
{'fraction_non_alphanumeric': 0.10299129117758425, 'fraction_numerical': 0.0, 'mean_word_length': 3.9661654135338344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '2348697', 'n_tokens_mistral': 773, 'n_tokens_neox': 764, 'n_words': 147}