summaryrefslogtreecommitdiff
path: root/addons/auth_totp/views
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/auth_totp/views
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/auth_totp/views')
-rw-r--r--addons/auth_totp/views/templates.xml45
-rw-r--r--addons/auth_totp/views/user_preferences.xml142
2 files changed, 187 insertions, 0 deletions
diff --git a/addons/auth_totp/views/templates.xml b/addons/auth_totp/views/templates.xml
new file mode 100644
index 00000000..100dbbc4
--- /dev/null
+++ b/addons/auth_totp/views/templates.xml
@@ -0,0 +1,45 @@
+<odoo>
+ <template id="assets_tests" inherit_id="web.assets_tests">
+ <xpath expr="." position="inside">
+ <script type="text/javascript" src="/auth_totp/static/tests/totp_flow.js"></script>
+ </xpath>
+ </template>
+ <template id="auth_totp_form">
+ <t t-call="web.login_layout">
+ <t t-set="disable_footer">1</t>
+ <div class="oe_login_form">
+ <h5 class="card-title">Two-factor Authentication</h5>
+ <form method="POST" action="" class="">
+ <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
+ <input type="hidden" name="redirect" t-att-value="redirect"/>
+ <div class="form-group">
+ <label for="totp_token">Authentication Code (6 digits)</label>
+ <input id="totp_token" name="totp_token" class="form-control mb-2"
+ autofocus="autofocus" required="required"/>
+ </div>
+ <p class="alert alert-danger" t-if="error" role="alert">
+ <t t-esc="error"/>
+ </p>
+ <div t-attf-class="clearfix oe_login_buttons text-center mb-1">
+ <button type="submit" class="btn btn-primary btn-block">
+ Verify
+ </button>
+ </div>
+ <div class="small mb-2 mt-2 text-muted">
+ <i class="fa fa-2x fa-mobile pull-left"/>
+ Open the two-factor authentication app on your
+ device to obtain a code and verify your identity
+ </div>
+ </form>
+ </div>
+ <div class="text-center pb-2 border-top">
+ <form method="POST" action="/web/session/logout" class="form-inline">
+ <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
+ <button type="submit" class="btn btn-link btn-sm mb-2">
+ Cancel
+ </button>
+ </form>
+ </div>
+ </t>
+ </template>
+</odoo>
diff --git a/addons/auth_totp/views/user_preferences.xml b/addons/auth_totp/views/user_preferences.xml
new file mode 100644
index 00000000..81c7336a
--- /dev/null
+++ b/addons/auth_totp/views/user_preferences.xml
@@ -0,0 +1,142 @@
+<odoo>
+ <record model="ir.ui.view" id="view_totp_list">
+ <field name="name">users list: add totp status</field>
+ <field name="model">res.users</field>
+ <field name="inherit_id" ref="base.view_users_tree"/>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="totp_enabled"/>
+ </tree>
+ </field>
+ </record>
+ <record model="ir.ui.view" id="view_totp_form">
+ <field name="name">user form: add totp status</field>
+ <field name="model">res.users</field>
+ <field name="inherit_id" ref="base.view_users_form"/>
+ <field name="arch" type="xml">
+ <xpath expr="//page[@name='references']/group[1]" position="before">
+ <field name="totp_enabled" invisible="1"/>
+ <group attrs="{'invisible': [('totp_enabled', '!=', False)]}">
+ <div>
+ <span class="alert alert-info" role="status">
+ <i class="fa fa-warning"/>
+ Two-factor authentication not enabled
+ </span>
+ </div>
+ </group>
+ <group attrs="{'invisible': [('totp_enabled', '=', False)]}">
+ <div>
+ <span class="text-success">
+ <i class="fa fa-check-circle"/>
+ Two-factor authentication enabled
+ </span>
+ </div>
+ </group>
+ </xpath>
+ </field>
+ </record>
+
+ <record model="ir.actions.server" id="action_disable_totp">
+ <field name="name">Disable TOTP on users</field>
+ <field name="model_id" ref="base.model_res_users"/>
+ <field name="binding_model_id" ref="base.model_res_users"/>
+ <field name="binding_view_types">list</field>
+ <field name="state">code</field>
+ <field name="code">
+ action = records.totp_disable()
+ </field>
+ <field name="groups_id" eval="[(4, ref('base.group_erp_manager'), 0)]"/>
+ </record>
+
+ <record model="ir.ui.view" id="view_totp_wizard">
+ <field name="name">auth_totp wizard</field>
+ <field name="model">auth_totp.wizard</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet>
+ <div class="row container">
+ <div class="mb-3">
+ <h3 class="font-weight-bold">Scan this barcode with your app</h3>
+ <div>
+ Scan the image below with the authenticator app on your phone.<br/>
+ If you cannot scan the barcode, here are some alternative options:
+ <ul>
+ <li><field class="text-wrap" name="url" widget="url"
+ options="{'website_path': True}"
+ text="Click on this link to open your authenticator app"/></li>
+
+ <li>Or enter the secret code manually:
+ <a data-toggle="collapse"
+ href="#collapseTotpSecret" role="button" aria-expanded="false"
+ aria-controls="collapseTotpSecret">show the code</a>
+ </li>
+ </ul>
+ <!-- code outside list to have more horiz space on mobile -->
+ <div class="collapse col-12 col-md-6" id="collapseTotpSecret">
+ <div class="card card-body">
+ <h3>Your two-factor secret:</h3>
+ <code class="text-center"><field name="secret"/></code>
+ </div>
+ </div>
+ </div>
+
+ <field class="offset-1" name="qrcode" readonly="True" widget="image"/>
+
+ <h3 class="font-weight-bold">Enter the 6-digit code from your app</h3>
+ <div class="text-justify col-10 col-lg-6 px-0">
+ After scanning the barcode, the app will display a 6-digit code that you
+ should enter below. Don't worry if the code changes in the app,
+ it stays valid a bit longer.
+ </div>
+ <div class="mt-2">
+ <label for="code" class="col-4 col-md-12 px-0">Verification Code</label>
+ <field required="True" name="code" class="col-10 col-md-6 px-0"/>
+ </div>
+
+ </div>
+ </div>
+ </sheet>
+ <footer>
+ <button type="object" name="enable" class="btn btn-primary"
+ string="Enable two-factor authentication"/>
+ <button string="Cancel" special="cancel"/>
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record model="ir.ui.view" id="view_totp_field">
+ <field name="name">users preference: totp</field>
+ <field name="model">res.users</field>
+ <field name="inherit_id" ref="base.view_users_form_simple_modif"/>
+ <field name="arch" type="xml">
+ <button name="preference_change_password" position="after">
+ <field name="totp_enabled" invisible="1"/>
+ <group attrs="{'invisible': [('totp_enabled', '!=', False)]}">
+ <div>
+ <span class="alert alert-info" role="status">
+ <i class="fa fa-warning"/>
+ Two-factor authentication not enabled
+ <a href="https://www.odoo.com/documentation/14.0/applications/general/auth/2fa.html"
+ title="What is this?" class="o_doc_link" target="_blank"></a>
+ </span>
+ <button name="totp_enable_wizard" type="object" string="Enable two-factor authentication"
+ class="btn btn-info mx-3"/>
+ </div>
+ </group>
+ <group attrs="{'invisible': [('totp_enabled', '=', False)]}">
+ <div>
+ <span class="text-success">
+ <i class="fa fa-check-circle"/>
+ Two-factor authentication enabled
+ <a href="https://www.odoo.com/documentation/14.0/applications/general/auth/2fa.html"
+ title="What is this?" class="o_doc_link" target="_blank"></a>
+ </span>
+ <button name="totp_disable" type="object" string="(Disable two-factor authentication)"
+ class="btn btn-link text-muted"/>
+ </div>
+ </group>
+ </button>
+ </field>
+ </record>
+</odoo>