Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dmccormi
project-base
Commits
2b2c135e
Commit
2b2c135e
authored
Sep 12, 2015
by
William Billingsley
Browse files
Added sample solution
parent
0e38fae4
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/controllers/Application.java
View file @
2b2c135e
package
controllers
;
import
model.BCryptExample
;
import
model.Captcha
;
import
play.mvc.Controller
;
import
play.mvc.Result
;
import
java.util.Arrays
;
public
class
Application
extends
Controller
{
public
static
Result
index
()
{
return
internalServerError
(
"Not implemented yet..."
);
int
arrayLength
=
5
;
int
[]
indexes
=
new
int
[
arrayLength
];
for
(
int
i
=
0
;
i
<
arrayLength
;
i
++)
{
indexes
[
i
]
=
(
int
)(
Captcha
.
numPhotos
()
*
Math
.
random
());
}
return
ok
(
views
.
html
.
application
.
index
.
render
(
indexes
));
}
private
static
int
countBeagles
(
String
[]
indexes
)
{
int
i
=
0
;
for
(
String
s
:
indexes
)
{
if
(
Captcha
.
isCorrect
(
Integer
.
valueOf
(
s
)))
{
i
++;
}
}
return
i
;
}
public
static
Result
matches
()
{
return
internalServerError
(
"Not implemented yet..."
);
String
[]
sent
=
request
().
body
().
asFormUrlEncoded
().
get
(
"sent"
);
String
[]
beagles
=
request
().
body
().
asFormUrlEncoded
().
get
(
"beagle"
);
int
numBeagles
=
countBeagles
(
sent
);
int
numFound
=
countBeagles
(
beagles
);
return
ok
(
views
.
html
.
application
.
matches
.
render
(
numBeagles
,
numFound
));
}
}
app/model/Captcha.java
View file @
2b2c135e
...
...
@@ -58,7 +58,7 @@ public class Captcha {
/**
* Whether a photo selected by the user was in the "yes" set
*/
public
boolean
isCorrect
(
int
idx
)
{
public
static
boolean
isCorrect
(
int
idx
)
{
return
idx
>=
0
&&
idx
<
yesPhotos
.
length
;
}
...
...
app/views/application/index.scala.html
View file @
2b2c135e
...
...
@@ -11,8 +11,16 @@
<body>
<h1>
Tick all the beagles:
</h1>
<!-- TODO: This form probably has the wrong method... -->
<form
action=
"captcha"
>
<form
action=
"matches"
method=
"POST"
>
@for(idx
<-
indexes
)
{
<
div
>
<input
name=
"sent"
value=
"@idx"
type=
"hidden"
/>
<input
name=
"beagle"
value=
"@idx"
type=
"checkbox"
/>
<img
src=
"@model.Captcha.getPhoto(idx)"
style=
"max-width: 400px; max-height: 200px;"
/>
</div>
}
<!--
TODO: For each index in the array, show a checkbox with the value of the index, and the relevant img
-->
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment