Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen committed Oct 27, 2024
1 parent c327177 commit f7d274c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .env.local.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
POSTGRES_PASSWORD='flexwork123'
JWT_BASE64_SECRET='anhsREVnM1hDbTdSQnhHMGpQMW80eHFoZmV5blIxZG9QMVBlT0RIUVZlY3RpcHBqZHlqbGZraGU2NW8zekR6dk9VbkJYckI3VUh0eTJjckhpZnNsVjQ1c1VX'
spring.mail.host=smtp.gmail.com
[email protected]
spring.mail.port=587
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.port=587
spring.mail.password=fhbq nfoj baku hszc
spring.mail.properties.mail.smtp.auth=true
[email protected]
flexwork.mail.base-url=http://localhost:3000
43 changes: 43 additions & 0 deletions scripts/smtp_config.sh → scripts/mail_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,45 @@ read -p "Enter your password: " smtp_password
# Ask if SMTP requires STARTTLS
read -p "Does SMTP require STARTTLS (y/n)? " requires_starttls

# Prompt the user to enter the email address that will be used to send emails
email_regex="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"

# Loop until a valid email is entered
while true; do
read -p "Please enter the email address that will be used as the sender for outgoing emails: " sender_email

# Validate email format
if [[ $sender_email =~ $email_regex ]]; then
break # Exit the loop if the email is valid
else
echo "Invalid email address. Please enter a valid email."
fi
done


# Prompt the user to enter the base url for email template

# Regular expression for validating a URL with optional port, allowing localhost and IPs
url_regex="^(https?://)(localhost|([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}|([0-9]{1,3}\.){3}[0-9]{1,3})(:[0-9]{1,5})?(/.*)?$"

# Loop until a valid URL is entered
while true; do
read -p "Please enter the base URL that will be used for the email template: " base_url_email

# Validate URL format
if [[ $base_url_email =~ $url_regex ]]; then
break # Exit the loop if the URL is valid
else
echo "Invalid URL. Please enter a valid URL."
echo "Examples of valid URLs:"
echo "- https://example.com"
echo "- http://localhost:3000"
echo "- http://192.168.1.1:8080/path"
fi
done

# Continue with the rest of the script here


# Define the output script that will store the sensitive data
output_script=".env.local"
Expand Down Expand Up @@ -50,13 +89,17 @@ add_or_update_env_var() {
fi
}



# Add or update entries
add_or_update_env_var "spring.mail.host" "$smtp_host"
add_or_update_env_var "spring.mail.port" "$smtp_port"
add_or_update_env_var "spring.mail.properties.mail.smtp.port" "$smtp_port"
add_or_update_env_var "spring.mail.username" "$smtp_username"
add_or_update_env_var "spring.mail.password" "$smtp_password"
add_or_update_env_var "spring.mail.properties.mail.smtp.auth" "true"
add_or_update_env_var "flexwork.mail.from" $sender_email
add_or_update_env_var "flexwork.mail.base-url" $base_url_email

# Add STARTTLS settings if required
if [[ "$requires_starttls" == "y" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class User extends AbstractAuditingEntity<Long> implements Serializable {

public LocalDateTime getLastLoginTime() {
if (lastLoginTime == null) return null;
ZoneId userZone = ZoneId.of(timezone);
ZoneId userZone = (timezone != null) ? ZoneId.of(timezone) : ZoneId.of("America/Los_Angeles");
return lastLoginTime.atZone(ZoneOffset.UTC).withZoneSameInstant(userZone).toLocalDateTime();
}
}
2 changes: 1 addition & 1 deletion server/src/main/resources/config/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ server:
flexwork:
mail:
from: [email protected]
base-url: http://127.0.0.1:8080
base-url: http://127.0.0.1:3000
# CORS is only enabled by default with the "dev" profile
cors:
# Allow Ionic for JHipster by default (* no longer allowed in Spring Boot 2.4+)
Expand Down
6 changes: 3 additions & 3 deletions server/src/main/resources/config/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ server:

flexwork:
mail:
from: <Replace_Me>
base-url: <Replace_Me>
from: <Should be set externally>
base-url: <Should be set externally>
security:
authentication:
jwt:
# This token must be encoded using Base64 and be at least 256 bits long (you can type `openssl rand -base64 64` on your command line to generate a 512 bits one)
# As this is the PRODUCTION configuration, you MUST change the default key, and store it securely:
# - In the Consul configserver
# - In a separate `application-prod.yml` file, in the same folder as your executable JAR file
base64-secret: <Replace-me>
base64-secret: <Should be set externally>
# Token is valid 24 hours
token-validity-in-seconds: 86400
token-validity-in-seconds-for-remember-me: 2592000

0 comments on commit f7d274c

Please sign in to comment.