mirror of
https://github.com/bringout/oca-ocb-security.git
synced 2026-04-22 20:12:04 +02:00
19.0 vanilla
This commit is contained in:
parent
20ddc1b4a3
commit
c0efcc53f5
1162 changed files with 125577 additions and 105287 deletions
|
|
@ -17,7 +17,8 @@ from odoo.addons.auth_totp.models.totp import ALGORITHM, DIGITS, TIMESTEP
|
|||
|
||||
compress = functools.partial(re.sub, r'\s', '')
|
||||
|
||||
class TOTPWizard(models.TransientModel):
|
||||
|
||||
class Auth_TotpWizard(models.TransientModel):
|
||||
_name = 'auth_totp.wizard'
|
||||
_description = "2-Factor Setup Wizard"
|
||||
|
||||
|
|
@ -28,7 +29,7 @@ class TOTPWizard(models.TransientModel):
|
|||
attachment=False, store=True, readonly=True,
|
||||
compute='_compute_qrcode',
|
||||
)
|
||||
code = fields.Char(string="Verification Code", size=7)
|
||||
code = fields.Char(string="Verification Code", size=7, store=False)
|
||||
|
||||
@api.depends('user_id.login', 'user_id.company_id.display_name', 'secret')
|
||||
def _compute_qrcode(self):
|
||||
|
|
@ -57,7 +58,7 @@ class TOTPWizard(models.TransientModel):
|
|||
@check_identity
|
||||
def enable(self):
|
||||
try:
|
||||
c = int(compress(self.code))
|
||||
c = int(compress(self.env.context.get('code', '')))
|
||||
except ValueError:
|
||||
raise UserError(_("The verification code should only contain numbers"))
|
||||
if self.user_id._totp_try_setting(self.secret, c):
|
||||
|
|
@ -72,9 +73,3 @@ class TOTPWizard(models.TransientModel):
|
|||
}
|
||||
}
|
||||
raise UserError(_('Verification failed, please double-check the 6-digit code'))
|
||||
|
||||
def create(self, vals_list):
|
||||
rule = self.env.ref('auth_totp.rule_auth_totp_wizard', raise_if_not_found=False)
|
||||
if rule and rule.sudo().groups:
|
||||
rule.sudo().groups = False
|
||||
return super().create(vals_list)
|
||||
|
|
|
|||
|
|
@ -6,33 +6,13 @@
|
|||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<div class="o_auth_totp_enable_2FA container">
|
||||
<div class="o_auth_totp_enable_2FA text-center ps-0">
|
||||
<div class="mb-3 w-100">
|
||||
<h3 class="fw-bold">Authenticator App Setup</h3>
|
||||
<ul>
|
||||
<div class="d-md-none d-block">
|
||||
<li>
|
||||
<field class="text-wrap" name="url" widget="url" options="{'website_path': True}"
|
||||
text="Click on this link to open your authenticator app"/></li>
|
||||
</div>
|
||||
<li>
|
||||
<div class="d-flex align-items-center flex-wrap">
|
||||
<span class="d-md-none d-block">Or install an authenticator app</span>
|
||||
<span class="d-none d-md-block">Install an authenticator app on your mobile device</span>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<span class="text-muted">Popular ones include Authy, Google Authenticator or the Microsoft Authenticator.</span>
|
||||
<li>Look for an "Add an account" button</li>
|
||||
<li>
|
||||
<span class="d-none d-md-block">When requested to do so, scan the barcode below</span>
|
||||
<span class="d-block d-md-none">When requested to do so, copy the key below</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Desktop version -->
|
||||
<div class="text-center d-none d-md-block">
|
||||
<field name="qrcode" readonly="True" widget="image" options="{'no_reload': true }" />
|
||||
<h3 class="fw-bold d-none d-md-block">Scan this barcode in your Authenticator app</h3>
|
||||
<div class="d-none d-md-block">
|
||||
<field name="qrcode" readonly="True" widget="image" options="{'reload': false }"/>
|
||||
|
||||
<h3 class="fw-bold"><a data-bs-toggle="collapse"
|
||||
href="#collapseTotpSecret" role="button" aria-expanded="false"
|
||||
|
|
@ -43,24 +23,20 @@
|
|||
</div>
|
||||
|
||||
<!-- Mobile Version -->
|
||||
<div class="text-center d-block d-md-none">
|
||||
<h3 class="fw-bold d-block d-md-none">Add this key in your Authenticator app</h3>
|
||||
<div class="d-block d-md-none">
|
||||
<field name="secret" widget="CopyClipboardChar" readonly="1" class="mb-3 ps-3"/>
|
||||
</div>
|
||||
|
||||
<h3 class="fw-bold">Enter your six-digit code below</h3>
|
||||
<div class="mt-2">
|
||||
<label for="code" class="px-0">Verification Code</label>
|
||||
<div class="d-flex align-items-center">
|
||||
<field required="True" name="code" autocomplete="off" class="o_field_highlight px-0 me-2" placeholder="e.g. 123456"/>
|
||||
</div>
|
||||
</div>
|
||||
<h3 class="fw-bold">Write the code given by your app</h3>
|
||||
<field required="True" name="code" autocomplete="off" class="o_field_highlight w-50 w-sm-25" placeholder="Verification code"/>
|
||||
</div>
|
||||
</div>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button type="object" name="enable" class="btn btn-primary"
|
||||
string="Activate" data-hotkey="q"/>
|
||||
<button string="Cancel" special="cancel" data-hotkey="z"/>
|
||||
<button type="object" name="enable" class="btn btn-primary" context="{'code': code}"
|
||||
string="Enable Two-Factor Authentication" data-hotkey="q"/>
|
||||
<button string="Discard" special="cancel" data-hotkey="x"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue