Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.
Open

hgg #27

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Twilio API credentials
# (find here https://www.twilio.com/console)
export TWILIO_ACCOUNT_SID=
export TWILIO_AUTH_TOKEN=
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=

# Verification Service SID
# (create one here https://www.twilio.com/console/verify/services)
export VERIFICATION_SID=
VERIFICATION_SID=
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ After the above requirements have been met:
```
See [Twilio Account Settings](#twilio-account-settings) to locate the necessary environment variables.

If you are using a UNIX operating system, load the environment variables before the application starts.

```bash
source .env
```

_If you are using a different operating system, make sure that all the variables from the `.env` file are loaded into your environment._

3. Build the project

```bash
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<version>2.0.0-beta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import com.twilio.exception.ApiException;
import com.twilio.rest.verify.v2.service.Verification;
import com.twilio.rest.verify.v2.service.VerificationCheck;
import io.github.cdimascio.dotenv.Dotenv;

public class TwilioVerification implements VerificationService {

private static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
private static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
private static final String VERIFICATION_SID = System.getenv("VERIFICATION_SID");
public class TwilioVerification implements VerificationService {
private static Dotenv env = Dotenv.configure().ignoreIfMissing().load();
private static final String ACCOUNT_SID = env.get("TWILIO_ACCOUNT_SID");
private static final String AUTH_TOKEN = env.get("TWILIO_AUTH_TOKEN");
private static final String VERIFICATION_SID = env.get("VERIFICATION_SID");

public TwilioVerification() {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Import required java libraries
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

// Extend HttpServlet class
public class ErrorHandler extends HttpServlet {

// Method to handle GET method request.
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher("/error.html").forward(request, response);
}

// Method to handle POST method request.
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
23 changes: 23 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<servlet>
<servlet-name>ErrorHandler</servlet-name>
<servlet-class>ErrorHandler</servlet-class>
</servlet>

<!-- servlet mappings -->
<servlet-mapping>
<servlet-name>ErrorHandler</servlet-name>
<url-pattern>/ErrorHandler</url-pattern>
</servlet-mapping>

<error-page>
<error-code>404</error-code>
<location>/ErrorHandler</location>
</error-page>

<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/ErrorHandler</location>
</error-page>
</web-app>
9 changes: 9 additions & 0 deletions src/main/webapp/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>

<html>
<body>
<h1>Something went wrong! </h1>
<h2>Our Engineers are on it</h2>
<a href="/">Go Home</a>
</body>
</html>