Skip to content

Commit

Permalink
Merge pull request #9 from joshika39/feautre/adding-frontend-display-…
Browse files Browse the repository at this point in the history
…for-verification

Feautre/adding frontend display for verification
  • Loading branch information
joshika39 authored Apr 20, 2024
2 parents 20cea66 + f03d841 commit 2a21369
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
7 changes: 4 additions & 3 deletions backend/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

PASSWORD = os.getenv('PASS')
SELF_URL = os.getenv('SELF_URL')
FRONTEND_URL = os.getenv('FRONTEND_URL')

if not SELF_URL:
raise ValueError('SELF_URL not found in .env file')
Expand All @@ -27,7 +28,7 @@ def convert_to_base64(message: str):

user_config = UserConfig(
'ヘゲディス・ジョシュア',
'jhegedus9@gmail.com',
'josh.hegedus@outlook.com',
PASSWORD,
'開発者',
'Joshua Hegedus',
Expand All @@ -43,9 +44,9 @@ def convert_to_base64(message: str):

signer = Signer(
user_config,
SMTPConfig(),
SMTPConfig(smtp_server='smtp-mail.outlook.com'),
os.path.join('backend', 'email.html'),
SELF_URL,
FRONTEND_URL,
SignatureType.SIMPLE
)

Expand Down
6 changes: 4 additions & 2 deletions backend/sig-simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
<hr>

<p class="has-subtext"><a
href="{{ self_url }}/verify/email?email={{ email }}&ps_message={{ message }}&ps_signature={{ signature }}"
target="_blank"
href="{{ verify_url }}/email/verify?email={{ email }}&message={{ sig_message }}&signature={{ signature }}"
title="{{ verified_title }}">このメールはデジタル署名されました</a>
</p>
<p class="subtext"><i>これを使ってメールを署名しました:
<b>{{ sig_message }}</b>
</i></p>

<p class="has-subtext"><a
href="{{ self_url }}/verify/email?email={{ email }}&ps_message={{ message }}&ps_signature={{ signature }}"
target="_blank"
href="{{ verify_url }}/email/verify?email={{ email }}&message={{ sig_message }}&signature={{ signature }}"
title="{{ verified_title }}">This email is digitally signed</a>
</p>
<p class="subtext"><i>This was used to sign the email:
Expand Down
11 changes: 6 additions & 5 deletions backend/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ def __init__(
user: UserConfig,
smtp_config: SMTPConfig,
signature_file: str,
self_url: str,
verify_url: str,
signature_type: SignatureType = SignatureType.SIMPLE,
):
self.__smtp_config = smtp_config
self.__signature_file = signature_file
self.__signature_type = signature_type
self.__user = user
self.__rsa = RSA(user.email)
self.__self_url = self_url
self.__verify_url = verify_url

def inject_rsa_signature(self, funny_quote: str = ""):
"""
Expand Down Expand Up @@ -284,7 +284,7 @@ def __generate_complex_signature(self, body: str) -> Signature:

return Signature(template, verifications['data'])

def __generate_simple_signature(self, body: str) -> Signature:
def __generate_simple_signature(self, body: str, subject: str) -> Signature:
verifications = self.inject_rsa_signature()
simple_template = os.path.join('backend', 'sig-simple.html')
with open(simple_template, 'r') as f:
Expand All @@ -302,7 +302,8 @@ def __generate_simple_signature(self, body: str) -> Signature:
"latin_role": self.__user.latin_role,
'signature': verifications['verified_title'],
'sig_message': verifications['sig_message'],
'self_url': self.__self_url
'verify_url': self.__verify_url,
'subject': subject
}
all_fields = create_fields(self.__user.name, self.__user.email, self.__user.role)
all_fields.update(verifications)
Expand Down Expand Up @@ -347,7 +348,7 @@ def send_email(self, email: EmailConfig) -> SignerResponse:
if self.__signature_type == SignatureType.COMPLEX:
signature = self.__generate_complex_signature(email.message_body)
else:
signature = self.__generate_simple_signature(email.message_body)
signature = self.__generate_simple_signature(email.message_body, email.subject)

html_content = clean_up_html(signature.content)
if ENV == 'dev':
Expand Down

0 comments on commit 2a21369

Please sign in to comment.