Advertisement
Guest User

Untitled

a guest
Apr 11th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 KB | None | 0 0
  1.  public byte[] identifyUrl(String url) {
  2.         String resourcesFolder = System.getProperty("user.dir") + "\\src\\resources";
  3.         String staticResourcesFolder = resourcesFolder + "\\assets";
  4.         String dynamicResourcesFolder = resourcesFolder + "\\pages";
  5.  
  6.         if ("/login".equals(url)) {
  7.  
  8.         } else if ("/register".equals(url)) {
  9.             String email = httpRequest.getBodyParameters().get("email");
  10.             String password = httpRequest.getBodyParameters().get("pwd");
  11.             String confirmedPassword = httpRequest.getBodyParameters().get("cpwd");
  12.  
  13.             User existingUser=findUserByEmail(email);
  14.             if(existingUser!=null){
  15.                 return BadRequest("There is already registered user with this email".getBytes());
  16.             }
  17.  
  18.             if (!password.equals(confirmedPassword)) {
  19.                 return BadRequest("Passwords mismatched!".getBytes());
  20.             }
  21.  
  22.             try (BufferedWriter bw = new BufferedWriter(new FileWriter(pathToDatabase))) {
  23.                 bw.write(UUID.randomUUID().toString()+"|"+email+"|"+password+System.lineSeparator());
  24.             } catch (IOException e) {
  25.                 e.printStackTrace();
  26.             }
  27.             httpResponse.addHeader("Location", "resources/assets/html/login.html");
  28.             return Redirect(new byte[0]);
  29.  
  30.  
  31.         } else if ("/index".equals(url) || "/".equals(url)) {
  32.             try {
  33.                 byte[] fileContent = Files.readAllBytes(Paths.get(staticResourcesFolder + "\\html\\index.html"));
  34.                 return Ok(fileContent);
  35.             } catch (IOException e) {
  36.                 e.printStackTrace();
  37.             }
  38.         }else if("/register.html".equals(url)) {
  39.             try {
  40.                 byte[] fileContent = Files.readAllBytes(Paths.get(staticResourcesFolder + "\\html\\register.html"));
  41.                 return Ok(fileContent);
  42.             } catch (IOException e) {
  43.                 e.printStackTrace();
  44.             }
  45.  
  46.         }else if("/css/bootstrap.min.css".equals(url)){
  47.             try {
  48.                 byte[]fileContent=Files.readAllBytes(Paths.get(staticResourcesFolder+"\\css\\bootstrap.min.css"));
  49.                 this.httpResponse.setStatusCode(HttpStatus.OK);
  50.                 this.httpResponse.addHeader("Content-Type", "text/css");
  51.                  this.httpResponse.setContent(fileContent);
  52.                 return httpResponse.getBytes();
  53.             } catch (IOException e) {
  54.                 e.printStackTrace();
  55.             }
  56.         }
  57.         return NotFound("<h1>Requested url is not found!</h1>".getBytes());
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement