Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public byte[] identifyUrl(String url) {
- String resourcesFolder = System.getProperty("user.dir") + "\\src\\resources";
- String staticResourcesFolder = resourcesFolder + "\\assets";
- String dynamicResourcesFolder = resourcesFolder + "\\pages";
- if ("/login".equals(url)) {
- } else if ("/register".equals(url)) {
- String email = httpRequest.getBodyParameters().get("email");
- String password = httpRequest.getBodyParameters().get("pwd");
- String confirmedPassword = httpRequest.getBodyParameters().get("cpwd");
- User existingUser=findUserByEmail(email);
- if(existingUser!=null){
- return BadRequest("There is already registered user with this email".getBytes());
- }
- if (!password.equals(confirmedPassword)) {
- return BadRequest("Passwords mismatched!".getBytes());
- }
- try (BufferedWriter bw = new BufferedWriter(new FileWriter(pathToDatabase))) {
- bw.write(UUID.randomUUID().toString()+"|"+email+"|"+password+System.lineSeparator());
- } catch (IOException e) {
- e.printStackTrace();
- }
- httpResponse.addHeader("Location", "resources/assets/html/login.html");
- return Redirect(new byte[0]);
- } else if ("/index".equals(url) || "/".equals(url)) {
- try {
- byte[] fileContent = Files.readAllBytes(Paths.get(staticResourcesFolder + "\\html\\index.html"));
- return Ok(fileContent);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }else if("/register.html".equals(url)) {
- try {
- byte[] fileContent = Files.readAllBytes(Paths.get(staticResourcesFolder + "\\html\\register.html"));
- return Ok(fileContent);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }else if("/css/bootstrap.min.css".equals(url)){
- try {
- byte[]fileContent=Files.readAllBytes(Paths.get(staticResourcesFolder+"\\css\\bootstrap.min.css"));
- this.httpResponse.setStatusCode(HttpStatus.OK);
- this.httpResponse.addHeader("Content-Type", "text/css");
- this.httpResponse.setContent(fileContent);
- return httpResponse.getBytes();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return NotFound("<h1>Requested url is not found!</h1>".getBytes());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement