Implement basic login demo
This commit is contained in:
parent
569f0ea235
commit
c0d8243016
13
.idea/compiler.xml
Normal file
13
.idea/compiler.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="Commenting-Server" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
20
.idea/jarRepositories.xml
Normal file
20
.idea/jarRepositories.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Commenting-Server.iml" filepath="$PROJECT_DIR$/Commenting-Server.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
67
pom.xml
67
pom.xml
@ -5,12 +5,77 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>net.mindoverflow.comments</groupId>
|
||||
<artifactId>Commenting-Server</artifactId>
|
||||
<artifactId>CommentingServer</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>2.0.0-alpha1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ro.pippo</groupId>
|
||||
<artifactId>pippo-core</artifactId>
|
||||
<version>1.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ro.pippo</groupId>
|
||||
<artifactId>pippo-freemarker</artifactId>
|
||||
<version>1.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ro.pippo</groupId>
|
||||
<artifactId>pippo-controller</artifactId>
|
||||
<version>1.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ro.pippo</groupId>
|
||||
<artifactId>pippo-jetty</artifactId>
|
||||
<version>1.13.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<release>11</release>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>create-my-bundle</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>net.mindoverflow.comments.CommentingServer</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,14 @@
|
||||
package net.mindoverflow.comments;
|
||||
|
||||
import ro.pippo.core.Pippo;
|
||||
|
||||
public class CommentingServer
|
||||
{
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
final Pippo pippo = new Pippo(new WebServer());
|
||||
pippo.start();
|
||||
|
||||
}
|
||||
}
|
63
src/main/java/net/mindoverflow/comments/WebServer.java
Normal file
63
src/main/java/net/mindoverflow/comments/WebServer.java
Normal file
@ -0,0 +1,63 @@
|
||||
package net.mindoverflow.comments;
|
||||
|
||||
import ro.pippo.core.Application;
|
||||
import ro.pippo.core.route.TrailingSlashHandler;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
public class WebServer extends Application
|
||||
{
|
||||
|
||||
String username = "lollo";
|
||||
String userpass = "password";
|
||||
|
||||
@Override
|
||||
public void onInit()
|
||||
{
|
||||
|
||||
POST("/login", routeContext -> {
|
||||
System.out.println("POST");
|
||||
|
||||
String name = routeContext.getParameter("username").toString();
|
||||
System.out.println(name);
|
||||
|
||||
String password = routeContext.getParameter("password").toString();
|
||||
System.out.println(password);
|
||||
|
||||
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
|
||||
if(name.isEmpty())
|
||||
{
|
||||
model.put("errorMessage", "Empty username!");
|
||||
}
|
||||
else if (password.isEmpty())
|
||||
{
|
||||
model.put("errorMessage", "Empty password!");
|
||||
}
|
||||
else if(!name.equals(username) || !password.equals(userpass))
|
||||
{
|
||||
model.put("errorMessage", "Wrong username or password!");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
model.put("errorMessage", "Logged in!");
|
||||
}
|
||||
|
||||
|
||||
routeContext.render("login", model);
|
||||
|
||||
});
|
||||
|
||||
GET("/login", routeContext ->
|
||||
{
|
||||
System.out.println("GET");
|
||||
|
||||
routeContext.render("login");
|
||||
});
|
||||
|
||||
ANY("/.*", new TrailingSlashHandler(false)); // remove trailing slash
|
||||
}
|
||||
}
|
0
src/main/resources/META-INF/MANIFEST.MF
Normal file
0
src/main/resources/META-INF/MANIFEST.MF
Normal file
14
src/main/resources/templates/login.ftl
Normal file
14
src/main/resources/templates/login.ftl
Normal file
@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Login Form</h1>
|
||||
<div><#if errorMessage??>${errorMessage}</#if></div>
|
||||
<form accept-charset="UTF-8" role="form" method="post" action="/login">
|
||||
<input placeholder="Username" name="username">
|
||||
<input placeholder="Password" name="password" type="password">
|
||||
<input class="btn btn-success btn-block" type="submit" value="Login">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user