Code Monkey home page Code Monkey logo

play-recaptcha's People

Contributors

amazingdreams avatar chrisnappin avatar gmalouf avatar gmixa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

play-recaptcha's Issues

Migrating => Play 2.6 error: object recaptchaWidget is not a member of package views.html.recaptcha

While migrating a project to Play 2.6 and the latest 2.3 version I get the following error:

error: object recaptchaWidget is not a member of package views.html.recaptcha

This among other errors I didn't have before:

[error] /home/bravegag/code/play-authenticate-usage-scala/app/views/_recaptchaFieldPartial.scala.html:20: value isInternalErrorCode is not a member of object com.nappin.play.recaptcha.RecaptchaErrorCode
[error] @recaptchaError = @{ errorCode.filter(code => !RecaptchaErrorCode.isInternalErrorCode(code)) }
[error] ^
[error] /home/bravegag/code/play-authenticate-usage-scala/app/views/_recaptchaFieldPartial.scala.html:25: object recaptchaWidget is not a member of package views.html.recaptcha
[error] Note: class recaptchaWidget exists, but it has no companion object.
[error]

@recaptcha.recaptchaWidget(tabindex = tabindex, includeNoScript = includeNoScript)

[error] ^
[error] /home/bravegag/code/play-authenticate-usage-scala/app/views/_recaptchaFieldPartial.scala.html:25: reassignment to val
[error]
@recaptcha.recaptchaWidget(tabindex = tabindex, includeNoScript = includeNoScript)

[error] ^
[error] /home/bravegag/code/play-authenticate-usage-scala/app/views/_recaptchaFieldPartial.scala.html:25: reassignment to val
[error]
@recaptcha.recaptchaWidget(tabindex = tabindex, includeNoScript = includeNoScript)

[error] ^

The code I'm working on can be found here:
https://github.com/bravegag/play-authenticate-usage-scala/tree/migrate-play-2.6

More specifically here:
https://github.com/bravegag/play-authenticate-usage-scala/blob/migrate-play-2.6/app/views/_recaptchaFieldPartial.scala.html

Support for AJAX submission

RecaptchaVerifier.bindFromRequestAndVerify takes a Request[AnyContent], but then it calls request.body.asFormUrlEncoded.get. This means it will only actually work with Request[AnyContentAsFormUrlEncoded]. I'm specifically interested in posting a JSON body.

Play's Form.bindFromRequest has logic to convert many different body types into Map[String, Seq[String]]. I'm a bit of a novice when it comes to the forms code, and I couldn't think of any easy way to reuse their logic here.

Exception during startup in Play 2.5 with compile-time DI

During the startup phase, the configuration module crashes with the following exception:

Caused by: java.lang.RuntimeException: There is no started application
    at scala.sys.package$.error(package.scala:27)
    at play.api.Play$$anonfun$current$1.apply(Play.scala:86)
    at play.api.Play$$anonfun$current$1.apply(Play.scala:86)
    at scala.Option.getOrElse(Option.scala:121)
    at play.api.Play$.current(Play.scala:86)
    at com.nappin.play.recaptcha.RecaptchaModule$.checkConfiguration(RecaptchaModule.scala:42)
    at com.nappin.play.recaptcha.RecaptchaVerifier.<init>(RecaptchaVerifier.scala:63)
    at AppComponents$class.recaptchaVerifier(ApplicationLoader.scala:93)
    at AppApplicationLoader$$anon$1.recaptchaVerifier$lzycompute(ApplicationLoader.scala:29)
    at AppApplicationLoader$$anon$1.recaptchaVerifier(ApplicationLoader.scala:29)

It seems to me that the problem is related to using play.api.Play.current inside the RecaptchaModule. I think the recommended way to read configuration in Play 2.5 is via the play.api.Configuration object that can be injected.

Maybe it makes sense to add play.api.Configuration to RecaptchaVerifier's dependencies and then pass it to RecaptchaModule ?

Not working with Play 2.4 Guice DI

It looks like this needs to be updated to be compatible with the Play 2.4 Guice Dependency Injection. I'm getting this error when trying to use it in Play 2.4.

Could not find a suitable constructor in com.nappin.play.recaptcha.RecaptchaPlugin. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
at com.nappin.play.recaptcha.RecaptchaPlugin.class(RecaptchaPlugin.scala:25)
while locating com.nappin.play.recaptcha.RecaptchaPlugin

Integration with Silhouette + option for removing labels

Hi!

I managed to integrate your module with the Silhouette seed example. While this is not a bug, neither your fault, reCaptcha does not work out of the box with Silhoutte. I had a hard time figuring out why, but finally I got it: Silhoutte Content Security Policies disable loading the Google script, you have to add authorizations for this manually. My integrated project's Wiki page has the workaround. I just let you know this in case you want to give a hint in your documentation in this direction.

A little thing which has to do with your project: while the labels for the recaptcha field can be configured, the place holders for them cannot be removed. So even if I use empty labels, they eat up some space. I put the whole recaptcha field in a div and gave it a negative margin but this is not very elegant.

Anyway, your project is amazing, keep it up!

How to unit test the recaptcha upon form submission?

I'm trying to write some unit tests for the form submission that is using the play-recaptcha plugin and having a little bit of a struggle with it. Do you have any examples on how to write tests against the bindFromRequest / form fold code?

Here's an example of what the code looks like. I tried mocking some of the recaptcha methods but it's getting pretty hair pretty quick and I was hoping you had some examples. Thanks!

def submit = Action.async { implicit request =>
implicit val context = scala.concurrent.ExecutionContext.Implicits.global

recaptchaVerifier.bindFromRequestAndVerify(creditCardForm).map { form =>
  form.fold(
    errors => {
      BadRequest(views.html.addCreditCards(errors))
    },
    success => {
      response.status match {
        case "SUCCESS" => Redirect(routes.Success.index)
        case _ => Redirect(routes.Error.index)
      }
    })
}

}

Better customization of the generated HTML

First of all, thank you for this great plugin! it is very well done! I integrated the plugin in this project play-authenticate-usage-scala which I plan to use as template for a new Web App.

In that project we use Twitter Bootstrap which requires customizing the HTML generation of the form fields (and of the reCAPTCHA field). The issue is that I could not find any way to customize the generated HTML e.g. when using recaptchaField.scala.html the only way I found was to copy paste recaptchaField.scala.html in my project and change it to fit the Twitter Bootstrap requirements and it is still not optimal because I can't e.g. add classes form-control to the class of the g-recaptcha div.

See twitterBootstrapRecaptchaField.scala.html and signup.scala.html

A nicer solution would be to create something alla Play where the user has full control of the generated HTML ... this is just an illustrative example taken from the Play for Scala book but of course having a robust componentized recaptcha field that allows its HTML to be customized would be great:

@helper.input(myForm("mydatetime")) { (id, name, value, args) =>
    <input type="datetime" name="@name" id="@id" value="@value" @toHtmlArgs(args)>
 }

I am still learning how to create reusable HTML components in Play and find out whether this can be done better than how I solved it ... so potentially expect a PR too :)

Persian Language

Add persian ("fa") to support language.
Google supports persian language.

Java API

Hi,

Thanks a lot for your amazing work. I would like to know if is it possible to add a Java API ?

Thank you.

Low level recaptcha.recaptchaWidget doesn't use language from Messages

I have a problem with translating recaptcha.recaptchaWidget
I'm passing Messages with Lang code ru but this still shows text in English. As I understand script tag should be with hl argument like this:

<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=es">
But on my page this script doesn't have hl argument

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.