| |
---|
| | import javax.ws.rs.*; |
---|
| | import javax.ws.rs.core.MediaType; |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.Collection; |
---|
| | import java.util.regex.Pattern; |
---|
| | |
---|
| | @Component |
---|
| | @Path("/accounts") |
---|
| | public class AccountsRest { |
---|
| |
---|
| | accountJsonList.add(newAccountJson); |
---|
| | } |
---|
| | } |
---|
| | // 全アカウントの取得 |
---|
| | else{ |
---|
| | else { |
---|
| | for (var account : accounts.getAllAccounts()) { |
---|
| | var newAccountJson = new AccountJson(account); |
---|
| | accountJsonList.add(newAccountJson); |
---|
| | } |
---|
| |
---|
| | @POST |
---|
| | @Produces(MediaType.APPLICATION_JSON) |
---|
| | public int createAccount(@FormParam("name") String name, @FormParam("email") String email, @FormParam("password") String password) { |
---|
| | |
---|
| | // password: 最低8文字以上の入力 |
---|
| | var passMinLen = 8; |
---|
| | if (password.length() < passMinLen) throw new WebApplicationException(401); |
---|
| | // パスワード, メアドが正しく入力されているかチェック |
---|
| | if (!isCorrectPassword(password) || !isCorrectEmailAddress(email)) |
---|
| | throw new WebApplicationException(401); |
---|
| | |
---|
| | // すでに同じメールアドレスが存在しているか |
---|
| | var existAccount = accounts.getAccountByEmail(email); |
---|
| | if (existAccount != null) throw new WebApplicationException(400); |
---|
| |
---|
| | var newAccount = accounts.registerAccount(name, email, password); |
---|
| | |
---|
| | return newAccount.getUid(); |
---|
| | } |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | //----------------------------------------------------------------- |
---|
| | // 正しいメールアドレスが登録されているか判定 |
---|
| | //----------------------------------------------------------------- |
---|
| | |
---|
| | /** |
---|
| | * @param emailAddress メアド |
---|
| | */ |
---|
| | @SuppressWarnings("{unchecked}") // 正規表現の警告無視 |
---|
| | private boolean isCorrectEmailAddress(String emailAddress) { |
---|
| | |
---|
| | var aText = "[a-zA-Z0-9_!#¥¥$¥¥%&'*+/=?¥¥^`{}~|¥¥-]+"; |
---|
| | var dotAtom = aText + "(?:\\." + aText + "+)*"; |
---|
| | var regularExpression = "^" + dotAtom + "@" + dotAtom + "$"; |
---|
| | |
---|
| | var pattern = Pattern.compile(regularExpression); |
---|
| | var matcher = pattern.matcher(emailAddress); |
---|
| | |
---|
| | return matcher.find(); |
---|
| | } |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | // 正しいパスワードが入力されているかチェック |
---|
| | //----------------------------------------------------------------- |
---|
| | |
---|
| | /** |
---|
| | * @param password パスワード |
---|
| | */ |
---|
| | private boolean isCorrectPassword(String password) { |
---|
| | // password: 最低8文字以上の入力 |
---|
| | var passMinLen = 8; |
---|
| | return (passMinLen <= password.length()); |
---|
| | } |
---|
| | //----------------------------------------------------------------- |
---|
| | |
---|
| | } |
---|
| | |
---|
| | |
\が重複しているとwarnを吐きますが, 無視してください.
Feature/email address expressions checker
2310aa4
intomaster
fromfeature/email_address_expressions_checker
on 21 May 2021