Skip to content

Commit

Permalink
tune design a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Jul 30, 2024
1 parent 59dada6 commit d8b1907
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
7 changes: 5 additions & 2 deletions app/controllers/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ public Result firstStep(@Required @Email String username, @Required String passw

String otpLabel = otpCodeService.generateOtpLabel();
String otpCode = otpCodeService.generateOtpCode();
otpCodeService.sendOtpCode(username, otpCode);
String sentTo = otpCodeService.sendOtpCode(username, otpCode);

session.put("login.username", username);
session.put("login.otpLabel", otpLabel);
session.put("login.otpCode", otpCode);

log.info("Generated OTP code {} for {}, label: {}", otpCode, username, otpLabel);
return new View("login/otpCodeForm.html").with("otpLabel", otpLabel);
return new View("login/otpCodeForm.html")
.with("username", username)
.with("otpLabel", otpLabel)
.with("sentTo", sentTo);
}

public Result secondStep(String otpCode) {
Expand Down
5 changes: 2 additions & 3 deletions app/services/OtpCodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ private int randomDigit() {
return (int) (Math.random() * 10);
}

public void sendOtpCode(String username, String otpCode) throws Exception {
public String sendOtpCode(String username, String otpCode) throws Exception {
Email mail = new SimpleEmail();
mail.setCharset("UTF-8");
//mail.setHostName(config.domain());
//String domain = config.domain();
mail.setFrom("[email protected]");
mail.setMsg("Хочешь залогиниться? Введи этот код: " + otpCode);
mail.setSubject("Логин в суперсервис");
mail.addTo(username); // usernames are emails
Mail.send(mail);
return username;
}
}
7 changes: 6 additions & 1 deletion app/views/login/otpCodeForm.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#{extends 'main.html'/}

Hello ${username}, please enter OTP Code
<h1>Confirm your identity</h1>

<div style="margin: 1vh 0">
Hello ${username},<br>
please enter OTP Code that we sent to ${sentTo}.
</div>

#{form '/login/second-step'}
<label> ${otpLabel}-
Expand Down
12 changes: 12 additions & 0 deletions app/views/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
body, html {
height: 100%;
min-height: 100%;
background: #eee url(/public/images/bg.png);
}
.container {
background-color: white;
margin: 20vh auto;
padding: 2vh 2vw;
}
</style>
</head>
<body>

Expand Down
Binary file added public/images/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d8b1907

Please sign in to comment.