Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

UI changes #30

Open
wants to merge 5 commits into
base: 17.0-develop
Choose a base branch
from
Open
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
21 changes: 13 additions & 8 deletions g2p_auth_id_oidc/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import logging
import traceback
from datetime import datetime

from werkzeug.exceptions import BadRequest

Expand All @@ -19,7 +18,6 @@ class RegIdOidcController(http.Controller):
@fragment_to_query_string
def g2p_reg_id_authenticate(self, **kw):
state = json.loads(kw["state"])

dbname = state["d"]
if not http.db_filter([dbname]):
return BadRequest("DB cannot be empty")
Expand All @@ -31,7 +29,6 @@ def g2p_reg_id_authenticate(self, **kw):
"authentication_status": False,
"error_exception": None,
}

try:
oauth_provider = request.env["auth.oauth.provider"].sudo().browse(provider)
reg_id = request.env["g2p.reg.id"].browse(reg_id_id)
Expand All @@ -41,15 +38,23 @@ def g2p_reg_id_authenticate(self, **kw):
raise BadRequest("Oauth2 Provider not supported!")

oauth_provider.oidc_get_tokens(kw)
reg_id.authentication_status = "authenticated"
reg_id.last_authentication_time = datetime.now()
reg_id.last_authentication_user_id = request.env.user.id
validation = oauth_provider.oidc_get_validation_dict(kw)
oauth_provider.oidc_signin_generate_user_values(
validation, kw, oauth_partner=reg_id.partner_id, oauth_user=None, create_user=False
)
response_values["authentication_status"] = True
response_values["validation"] = validation
if validation["user_id"] and reg_id.value == validation["user_id"]:
reg_id.partner_id.update({"reg_ids": validation["reg_ids"]})
response_values["authentication_status"] = True
reg_id.last_authentication_user_id = request.env.user.id
reg_id.description = None
response_values["validation"] = validation
else:
reg_id.update(
{
"authentication_status": "not_authenticated",
"description": "ID value does not match",
}
)
except Exception:
_logger.exception("Encountered error while authenticating Reg Id.")
response_values["error_exception"] = traceback.format_exc()
Expand Down
13 changes: 12 additions & 1 deletion g2p_auth_id_oidc/models/g2p_auth_id_oidc_provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from datetime import datetime

from odoo import fields, models

Expand Down Expand Up @@ -59,7 +60,17 @@ def oidc_signin_process_reg_ids(self, validation, params, oauth_partner=None, **
if oauth_partner:
for reg_id in oauth_partner.reg_ids:
if reg_id.id_type.id == id_type_id:
reg_id.value = value
reg_ids.append(
(
1,
reg_id.id,
{
"value": value,
"authentication_status": "authenticated",
"last_authentication_time": datetime.now(),
},
)
)
append = False
break
if append:
Expand Down
90 changes: 90 additions & 0 deletions g2p_auth_id_oidc/static/src/css/g2p_authentication_response.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.auth_response {
width: 600px;
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 20px;
position: relative;
margin: 100px auto;
}

.modal-header {
text-align: center;
margin-bottom: 20px;
}

.success-message {
font-size: 26px;
font-family: "Roboto-Medium";
color: #02bc7d;
}

.error-message {
font-size: 26px;
font-family: "Roboto-Medium";
color: #fe646f;
}

.modal-body {
text-align: center;
background-color: #f5f5f5;
padding: 20px;
border-radius: 4px;
margin-bottom: 20px;
}

.authentication-details {
font-size: 18px;
font-family: "Roboto-Medium";
color: #02bc7d;
margin-bottom: 10px;
}

.detail {
font-size: 16px;
font-family: "Roboto-Regular";
color: #000000;
}

.modal-footer {
text-align: center;
}

.modal-footer button {
padding: 10px 20px;
font-size: 18px;
font-family: "Roboto-Regular";
color: white;
background-color: #000000;
border: none;
border-radius: 4px;
cursor: pointer;
}

.success {
height: 550px;
}

.error {
height: 400px;
}

.success .modal-body,
.error .modal-body {
height: auto;
}

.success-icon {
display: block;
margin: 10px auto;
width: 50px; /* Adjust the size as needed */
height: 50px;
}

.success-icon,
.error-icon {
display: block;
margin: 10px auto;
width: 50px; /* Adjust the size as needed */
height: 50px;
}
24 changes: 24 additions & 0 deletions g2p_auth_id_oidc/static/src/css/g2p_reg_id_base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* CSS for the Authenticated Button */

.g2p_reg_id_authenticate_button_class {
background-color: #2196f3;
color: #ffffff;
font-family: "Roboto", sans-serif;
font-weight: 500;
font-size: 14px;
height: 28px;
width: 104px;
border: none;
border-radius: 4px;
cursor: pointer;
text-align: center;
line-height: 28px;
}

.g2p_reg_id_authenticate_button_class:hover {
background-color: #1976d2;
}

.g2p_reg_id_authenticate_button_class:active {
background-color: #0d47a1;
}
Binary file added g2p_auth_id_oidc/static/src/img/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added g2p_auth_id_oidc/static/src/img/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added g2p_auth_id_oidc/static/src/img/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions g2p_auth_id_oidc/static/src/js/authentication_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import {registry} from "@web/core/registry";

export class RegIdAuthStatus extends Component {
setup() {
// TODO: get these fields from options from view
this.statusClass = "";
this.buttonClass = "";
this.showWidget = Boolean(this.props.record.data.auth_oauth_provider_id);
this.statusSelectionObject = Object.fromEntries(
this.props.record.fields.authentication_status.selection
Expand Down
5 changes: 3 additions & 2 deletions g2p_auth_id_oidc/static/src/xml/authentication_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<templates xml:space="preserve">
<t t-name="g2p_auth_id_oidc.reg_id_auth_status">
<t t-if="showWidget">
<link rel="stylesheet" href="/g2p_auth_id_oidc/static/src/css/g2p_reg_id_base.css" />
<div>
<div t-att-class="statusClass">
<div class="statusClass">
<t t-out="renderStatus()" />
</div>
<button t-att-class="buttonClass" t-on-click="authenticateButtonClick">
<button class="g2p_reg_id_authenticate_button_class" t-on-click="authenticateButtonClick">
Authenticate
</button>
</div>
Expand Down
3 changes: 2 additions & 1 deletion g2p_auth_id_oidc/views/group.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='reg_ids']/tree" position="inside">
<field name="auth_oauth_provider_id" column_invisible="1" />
<field name="last_authentication_time" readonly="1" />
<field name="last_authentication_user_id" readonly="1" />
<field
name="authentication_status"
string=""
widget="g2p_auth_id_oidc.reg_id_auth_status"
readonly="1"
options="{'statusClass': '', 'buttonClass': ''}"
/>
</xpath>
</field>
Expand Down
3 changes: 2 additions & 1 deletion g2p_auth_id_oidc/views/individual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='reg_ids']/tree" position="inside">
<field name="auth_oauth_provider_id" column_invisible="1" />
<field name="last_authentication_time" readonly="1" />
<field name="last_authentication_user_id" readonly="1" />
<field
name="authentication_status"
string=""
widget="g2p_auth_id_oidc.reg_id_auth_status"
readonly="1"
options="{'statusClass': '', 'buttonClass': ''}"
/>
</xpath>
</field>
Expand Down
56 changes: 48 additions & 8 deletions g2p_auth_id_oidc/views/templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,59 @@
<template id="g2p_reg_id_authenticate" name="Authenticate">
<t t-call="web.layout">
<t t-set="title">Authenticate</t>
<div class="card" id="auth_response">
<link rel="stylesheet" href="/g2p_auth_id_oidc/static/src/css/g2p_authentication_response.css" />
<div class="auth_response" id="auth_response">
<t t-if="authentication_status">
<h2>Authentication Success</h2>
<p>Authentication Response: <t t-out="validation" /></p>
<div class="modal-header">
<h2 class="success-message">Authentication Success</h2>
<img
src="/g2p_auth_id_oidc/static/src/img/success.png"
alt="Success"
class="success-icon"
/>
</div>
<div class="modal-body">
<div class="authentication-details">
<!-- Display the Name -->
<p class="detail">Name: <t t-esc="validation.get('name')" /></p>

<!-- Display the Registration ID (Assuming it's in reg_ids[0]['value']) -->
<p class="detail">Reg ID: <t
t-esc="validation.get('reg_ids')[0][2]['value'] if validation.get('reg_ids') else ''"
/>
</p>

<!-- Display the Email -->
<p class="detail">Email: <t t-esc="validation.get('email')" /></p>

<!-- Display the Phone Number -->
<p class="detail">Phone Number: <t t-esc="validation.get('phone')" /></p>
</div>
</div>
<div class="modal-footer">
<button onclick="window.close()">OK</button>
</div>
</t>
<t t-else="">
<p>Encountered error while authenticating Reg Id.</p>
<t t-if="debug">
<p><t t-out="error_exception" /></p>
</t>
<div class="modal-header">
<h2 class="error-message">Authentication Error</h2>
<img
src="/g2p_auth_id_oidc/static/src/img/error.png"
alt="Error"
class="error-icon"
/>
</div>
<div class="modal-body">
<p class="detail">Encountered error while authenticating Reg Id.</p>
<t t-if="debug">
<p class="detail"><t t-out="error_exception" /></p>
</t>
</div>
<div class="modal-footer">
<button onclick="window.close()">CLOSE</button>
</div>
</t>
</div>
<button onclick="window.close()">Ok</button>
</t>
</template>
</odoo>
Loading