Skip to content

Commit a365907

Browse files
committedOct 2, 2018
added openweathermap api to get temp for the users city
1 parent 02a3c92 commit a365907

File tree

23 files changed

+1907
-91
lines changed

23 files changed

+1907
-91
lines changed
 

‎app/models/users/User.java

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import play.data.format.*;
1010
import play.data.validation.*;
1111

12+
//first add the plugin to build.sbt
1213
import org.mindrot.jbcrypt.BCrypt;
1314

1415

@@ -19,6 +20,7 @@ public class User extends Model {
1920
@Id
2021
public String email;
2122
public String pass;
23+
public String city;
2224
public int points = 0;
2325
public int completed = 0;
2426

@@ -80,6 +82,10 @@ public int getPoints(){
8082
return points;
8183
}
8284

85+
public String getCity(){
86+
return city;
87+
}
88+
8389
public int getCompletedCount(){
8490
//simply divide the current point by 10 to get the num of completed items
8591
//seen as uers get 10 points for each item complated
@@ -102,6 +108,10 @@ public void setPass(String pass){
102108
//this.pass = p;
103109
this.pass = BCrypt.hashpw(pass, BCrypt.gensalt());
104110
}
111+
public void setCity(String city){
112+
113+
this.city = city;
114+
}
105115
public void addPoints(){
106116
points += 10;
107117

‎app/views/index.scala.html

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55

66
@main("home", user) {
77

8+
<script>
9+
var weather = new XMLHttpRequest();
10+
var city = "";
11+
city = "@user.getCity()";
12+
weather.open("GET", "https://api.openweathermap.org/data/2.5/find?q=" + city + "&units=metric&appid=8bbdccfff8927111b6c3cb756294790b", false);
13+
weather.send(null);
14+
15+
var r = JSON.parse(weather.response);
16+
var h = r.list["0"].main.temp;
17+
18+
19+
</script>
20+
821

922
<div class="row">
1023
<div class="col-12">
@@ -14,6 +27,12 @@
1427
@flash.get("emptyMessage");
1528
</div>
1629
}
30+
<h2>
31+
The current temperature is:
32+
<script>document.write(h)</script>
33+
34+
35+
</h2>
1736
<br>
1837
@form(action=routes.HomeController.submit(), 'class -> "form-hotizontal", 'role -> "form") {
1938
@CSRF.formField
@@ -69,7 +88,7 @@ <h5 style="float: center">@a.getMessage()</h5>
6988
} else{
7089
<p>No category selected</p>
7190
}
72-
@a.dateToString()
91+
7392
</div>
7493
<hr />
7594

@@ -121,7 +140,7 @@ <h5 style="float: center">@f.getMessage()</h5>
121140
} else{
122141
<p>No category selected</p>
123142
}
124-
@f.dateToString()
143+
125144

126145
</div>
127146
<hr />

‎app/views/register.scala.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h2>Register</h2>
3131

3232
@inputText(userForm("email"),'_label -> "email", 'size -> 40, 'placeholder -> "email")
3333
@inputPassword(userForm("pass"),'_label -> "password", 'size -> 40, 'placeholder -> "password")
34-
34+
@inputText(userForm("city"),'_label -> "enter your city", 'size -> 40, 'placeholder -> "city")
3535

3636
<input type="submit" value="Register" class="btn btn-secondary">
3737

‎conf/evolutions/default/1.sql

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ create table item (
2323
create table user (
2424
email varchar(255) not null,
2525
pass varchar(255),
26+
city varchar(255),
2627
points integer not null,
2728
completed integer not null,
2829
constraint pk_user primary key (email)

‎conf/evolutions/default/2.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ INSERT INTO Category values (2, 'Housework');
99
INSERT INTO Category values (3, 'Shopping');
1010
INSERT INTO Category values (4, 'Other');
1111

12-
INSERT INTO User values ('carl@gmail.com', 'pass', 0, 0);
12+
INSERT INTO User values ('carl@gmail.com', 'pass', 'dublin', 0, 0);

‎data/toDoApp.mv.db

20 KB
Binary file not shown.

‎data/toDoApp.trace.db

+240-1
Large diffs are not rendered by default.

‎hs_err_pid1828.log

+1,217
Large diffs are not rendered by default.

‎logs/application.log

+310-7
Large diffs are not rendered by default.

‎target/.history

+7
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,10 @@ run
160160
h2-browser
161161
sbt
162162
run
163+
h2-browser
164+
run
165+
sbt
166+
run
167+
sbt
168+
h2-browser
169+
run

‎target/scala-2.12/classes/evolutions/default/1.sql

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ create table item (
2323
create table user (
2424
email varchar(255) not null,
2525
pass varchar(255),
26+
city varchar(255),
2627
points integer not null,
2728
completed integer not null,
2829
constraint pk_user primary key (email)

‎target/scala-2.12/classes/evolutions/default/2.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ INSERT INTO Category values (2, 'Housework');
99
INSERT INTO Category values (3, 'Shopping');
1010
INSERT INTO Category values (4, 'Other');
1111

12-
INSERT INTO User values ('carl@gmail.com', 'pass', 0, 0);
12+
INSERT INTO User values ('carl@gmail.com', 'pass', 'dublin', 0, 0);
708 Bytes
Binary file not shown.
635 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.