Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
project-base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AFRAH
project-base
Commits
2b2c135e
Commit
2b2c135e
authored
9 years ago
by
William Billingsley
Browse files
Options
Downloads
Patches
Plain Diff
Added sample solution
parent
0e38fae4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/controllers/Application.java
+27
-2
27 additions, 2 deletions
app/controllers/Application.java
app/model/Captcha.java
+1
-1
1 addition, 1 deletion
app/model/Captcha.java
app/views/application/index.scala.html
+10
-2
10 additions, 2 deletions
app/views/application/index.scala.html
with
38 additions
and
5 deletions
app/controllers/Application.java
+
27
−
2
View file @
2b2c135e
package
controllers
;
package
controllers
;
import
model.BCryptExample
;
import
model.BCryptExample
;
import
model.Captcha
;
import
play.mvc.Controller
;
import
play.mvc.Controller
;
import
play.mvc.Result
;
import
play.mvc.Result
;
import
java.util.Arrays
;
public
class
Application
extends
Controller
{
public
class
Application
extends
Controller
{
public
static
Result
index
()
{
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
()
{
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
));
}
}
}
}
This diff is collapsed.
Click to expand it.
app/model/Captcha.java
+
1
−
1
View file @
2b2c135e
...
@@ -58,7 +58,7 @@ public class Captcha {
...
@@ -58,7 +58,7 @@ public class Captcha {
/**
/**
* Whether a photo selected by the user was in the "yes" set
* 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
;
return
idx
>=
0
&&
idx
<
yesPhotos
.
length
;
}
}
...
...
This diff is collapsed.
Click to expand it.
app/views/application/index.scala.html
+
10
−
2
View file @
2b2c135e
...
@@ -11,8 +11,16 @@
...
@@ -11,8 +11,16 @@
<body>
<body>
<h1>
Tick all the beagles:
</h1>
<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
TODO: For each index in the array, show a checkbox with the value of the index, and the relevant img
-->
-->
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment