-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
164 changed files
with
3,624 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
logs | ||
project/project | ||
project/target | ||
target | ||
tmp | ||
.history | ||
dist | ||
/.idea | ||
/*.iml | ||
/out | ||
/.idea_modules | ||
/.classpath | ||
/.project | ||
/RUNNING_PID | ||
/.settings | ||
/.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Offline-webshop-with-interface.com | ||
Admin login: | ||
username = admin - password = admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
body { | ||
padding: 70px; | ||
background-image: url(http://subtlepatterns.com/patterns/tweed.png); | ||
} | ||
|
||
a:hover,.col-sm-3 a:hover,.glyphicon:hover { | ||
color: #e7a61a; | ||
text-decoration: none; | ||
} | ||
|
||
hr { | ||
color: white; | ||
} | ||
|
||
|
||
|
||
.menu { | ||
padding: 10px; | ||
padding-top: 5px; | ||
width: 150px; | ||
float: right; | ||
background-color: rgba(0, 0, 0, 0.3); | ||
color: #D9D9D9; | ||
text-align: left; | ||
} | ||
|
||
.menuButtons { | ||
text-align: center; | ||
} | ||
|
||
.contentBox { | ||
width: 880px; | ||
min-height: 300px; | ||
padding: 50px; | ||
padding-top: 25px; | ||
background-color: white; | ||
float: left; | ||
} | ||
|
||
.loginInput,.blacktext { | ||
color: black; | ||
} | ||
|
||
.alert-warning { | ||
text-shadow: 0px 0px 0px rgba(0, 0, 0, 0); | ||
} | ||
|
||
.login { | ||
color: white; | ||
} | ||
|
||
.loginButton { | ||
color: black; | ||
} | ||
|
||
.shortDescription { | ||
-o-text-overflow: ellipsis; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
width: 10px; | ||
} | ||
|
||
.productImgSmall{ | ||
height: 60px; | ||
width: 60px; | ||
} | ||
|
||
.productImgBig{ | ||
height: 450px; | ||
width: 450px; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
package controllers; | ||
|
||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import model.CategoryModel; | ||
import model.OrderModel; | ||
import model.ProductInCartModel; | ||
import model.ProductModel; | ||
import model.UserModel; | ||
import play.db.jpa.JPA; | ||
import play.db.jpa.Transactional; | ||
import play.libs.Json; | ||
import play.mvc.Controller; | ||
import play.mvc.Result; | ||
import play.mvc.Security; | ||
|
||
public class ApiController extends Controller | ||
{ | ||
@Transactional | ||
@Security.Authenticated(AuthenticatorLoggedIn.class) | ||
public static Result showShoppingCart() | ||
{ | ||
final String encodedUser = session().get("username"); | ||
final String email = Login.decodeEmail(encodedUser); | ||
final UserModel user1 = User.getUser(email); | ||
|
||
List<ProductInCartModel> products = new ArrayList<ProductInCartModel>(); | ||
for (ProductInCartModel product : user1.getShoppingCartContents()) | ||
{ | ||
products.add(product); | ||
} | ||
return ok(Json.toJson(products)); | ||
} | ||
|
||
@Transactional | ||
public static Result loginAppUser() | ||
{ | ||
final Map<String, String[]> form = request().body().asFormUrlEncoded(); | ||
|
||
final String email = form.get("email")[0]; | ||
final String password = form.get("password")[0]; | ||
|
||
System.out.println("User: " + email + " password: " + password); | ||
|
||
final boolean usernameIsEmpty = "".equals(email); | ||
final boolean passwordIsEmpty = "".equals(password); | ||
|
||
if (usernameIsEmpty || passwordIsEmpty) | ||
{ | ||
return ok("Bad username or password!"); | ||
} | ||
|
||
final UserModel user = controllers.User.getUser(email); | ||
if (Login.validateUser(email, password)) | ||
{ | ||
final String encoded = Login.encodeEmail(email); | ||
session().put("username", encoded); | ||
session().put("rights", "" + user.getRights()); | ||
|
||
return ok("You were logged in!"); | ||
} else | ||
{ | ||
return ok("Login details not correct!"); | ||
} | ||
|
||
} | ||
|
||
@Transactional | ||
public static Result logoutAppUser() | ||
{ | ||
if (session().containsKey("username")) | ||
{ | ||
session().clear(); | ||
return ok("You were logged out!"); | ||
} else | ||
{ | ||
return ok("You were never logged in!"); | ||
} | ||
} | ||
|
||
@Transactional | ||
public static Result getAllProducts() | ||
{ | ||
List<ProductModel> products = getAllInStoreProducts(); | ||
|
||
return ok(Json.toJson(products)); | ||
} | ||
|
||
@Transactional | ||
public static List<ProductModel> getAllInStoreProducts() | ||
{ | ||
return JPA | ||
.em() | ||
.createQuery("SELECT a FROM ProductModel a WHERE inStore = true", | ||
ProductModel.class).getResultList(); | ||
} | ||
|
||
@Transactional | ||
public static Result getAllCategories() | ||
{ | ||
List<CategoryModel> categories = new ArrayList<CategoryModel>(); | ||
categories = Category.getAllCategories(); | ||
|
||
return ok(Json.toJson(categories)); | ||
} | ||
|
||
@Transactional | ||
@Security.Authenticated(AuthenticatorAdmin.class) | ||
public static Result addCategoryFromApp() | ||
{ | ||
final Map<String, String[]> form = request().body().asFormUrlEncoded(); | ||
final String name = form.get("name")[0]; | ||
System.out.print("name = " + name); | ||
if (name != "") | ||
{ | ||
final CategoryModel category = new CategoryModel(name, 0); | ||
|
||
JPA.em().persist(category); | ||
} | ||
return ok(); | ||
} | ||
|
||
@Transactional | ||
@Security.Authenticated(AuthenticatorAdmin.class) | ||
public static Result addProductFromApp() | ||
{ | ||
final Map<String, String[]> form = request().body().asFormUrlEncoded(); | ||
final String name = form.get("name")[0]; | ||
final String description = form.get("description")[0]; | ||
final String imgUrl = form.get("url")[0]; | ||
final double cost = Double.parseDouble(form.get("cost")[0]); | ||
final double rrp = Double.parseDouble(form.get("rrp")[0]); | ||
final int stock = Integer.parseInt(form.get("stock")[0]); | ||
|
||
final List<CategoryModel> categories = new ArrayList<CategoryModel>(); | ||
if (form.get("categories") != null) | ||
{ | ||
for (int i = 0; i < form.get("categories").length; i++) | ||
{ | ||
categories.add(controllers.Category.getCategory(Integer.parseInt(form | ||
.get("categories")[i]))); | ||
} | ||
} | ||
|
||
final ProductModel product = new ProductModel(name, description, cost, rrp, categories, 0, | ||
stock); | ||
product.setImgUrl(imgUrl); | ||
|
||
JPA.em().persist(product); | ||
|
||
final int id = product.getId(); | ||
return ok(); | ||
} | ||
|
||
@Transactional | ||
@Security.Authenticated(AuthenticatorLoggedIn.class) | ||
public static Result placeOrderApp(String email) | ||
{ | ||
final UserModel user = controllers.User.getUser(email); | ||
final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); | ||
final Date date = new Date(); | ||
|
||
if (user.getShoppingCartContents().size() > 0) | ||
{ | ||
|
||
final OrderModel order = new OrderModel(user.getEmail(), | ||
new ArrayList<ProductInCartModel>(user.getShoppingCartContents()), | ||
dateFormat.format(date)); | ||
|
||
JPA.em().persist(order); | ||
JPA.em().flush(); | ||
|
||
int orderId = 0; | ||
orderId = order.getId(); | ||
|
||
user.emptyShoppingCart(); | ||
|
||
return ok(); | ||
} else | ||
{ | ||
return ok(); | ||
} | ||
} | ||
|
||
@Transactional | ||
@Security.Authenticated(AuthenticatorAdmin.class) | ||
public static Result showAllOrders() | ||
{ | ||
List<OrderModel> orders = Order.getAllOrders(); | ||
return ok(Json.toJson(orders)); | ||
} | ||
|
||
@Transactional | ||
@Security.Authenticated(AuthenticatorAdmin.class) | ||
public static Result showUser(String email) | ||
{ | ||
return ok(Json.toJson(User.getUser(email))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package controllers; | ||
|
||
import play.db.jpa.Transactional; | ||
import play.mvc.Controller; | ||
import play.mvc.Result; | ||
import play.mvc.Security; | ||
import views.html.index; | ||
import views.html.edit.editPage; | ||
|
||
public class Application extends Controller | ||
{ | ||
@Transactional | ||
@Security.Authenticated(AuthenticatorAdmin.class) | ||
public static Result edit() | ||
{ | ||
return ok(editPage.render(null)); | ||
} | ||
|
||
public static Result home() | ||
{ | ||
return ok(index.render(null, null)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package controllers; | ||
|
||
import model.UserModel; | ||
import play.db.jpa.JPA; | ||
import play.db.jpa.Transactional; | ||
import play.mvc.Http.Context; | ||
import play.mvc.Result; | ||
|
||
public class AuthenticatorAdmin extends play.mvc.Security.Authenticator | ||
{ | ||
@Override | ||
@Transactional | ||
public String getUsername(Context ctx) | ||
{ | ||
final String encodedUser = ctx.session().get("username"); | ||
if (encodedUser != null) | ||
{ | ||
final String user = controllers.Login.decodeEmail(encodedUser); | ||
final UserModel userModel = JPA.em().find(UserModel.class, user); | ||
|
||
if (userModel != null && userModel.getRights() > 0) | ||
{ | ||
return userModel.getEmail(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Result onUnauthorized(Context ctx) | ||
{ | ||
return redirect(routes.Application.home()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
webshop-updated/app/controllers/AuthenticatorLoggedIn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package controllers; | ||
|
||
import model.UserModel; | ||
import play.db.jpa.JPA; | ||
import play.db.jpa.Transactional; | ||
import play.mvc.Http.Context; | ||
import play.mvc.Result; | ||
|
||
public class AuthenticatorLoggedIn extends play.mvc.Security.Authenticator | ||
{ | ||
@Override | ||
@Transactional | ||
public String getUsername(Context ctx) | ||
{ | ||
final String encodedUser = ctx.session().get("username"); | ||
if (encodedUser != null) | ||
{ | ||
final String user = controllers.Login.decodeEmail(encodedUser); | ||
final UserModel userModel = JPA.em().find(UserModel.class, user); | ||
|
||
if (userModel != null) | ||
{ | ||
return userModel.getEmail(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Result onUnauthorized(Context arg0) | ||
{ | ||
controllers.Login.flash().put("not-logged-in", "yes"); | ||
return redirect(routes.Application.home()); | ||
} | ||
} |
Oops, something went wrong.