mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 21:46:22 +00:00
Merge branch 'issue-8342' into 'rails'
feat: implementar campo de tipo password #8342 Closes #8204, #1944, #1943, #1942, #1940, #1939, #1938, and #1515 See merge request sutty/sutty!109
This commit is contained in:
commit
e65b563229
6 changed files with 47 additions and 1 deletions
25
app/models/metadata_password.rb
Normal file
25
app/models/metadata_password.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Almacena una contraseña
|
||||||
|
class MetadataPassword < MetadataString
|
||||||
|
# Las contraseñas no son indexables
|
||||||
|
#
|
||||||
|
# @return [boolean]
|
||||||
|
def indexable?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
alias_method :original_sanitize, :sanitize
|
||||||
|
|
||||||
|
# Sanitizar la string y generar un hash Bcrypt
|
||||||
|
#
|
||||||
|
# @param :string [String]
|
||||||
|
# @return [String]
|
||||||
|
def sanitize(string)
|
||||||
|
string = original_sanitize string
|
||||||
|
|
||||||
|
::BCrypt::Password.create(string).to_s
|
||||||
|
end
|
||||||
|
end
|
|
@ -134,7 +134,11 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
|
||||||
# En caso de que algún campo necesite realizar acciones antes de ser
|
# En caso de que algún campo necesite realizar acciones antes de ser
|
||||||
# guardado
|
# guardado
|
||||||
def save
|
def save
|
||||||
return true unless changed?
|
if !changed?
|
||||||
|
self[:value] = document_value if private?
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
self[:value] = sanitize value
|
self[:value] = sanitize value
|
||||||
self[:value] = encrypt(value) if private?
|
self[:value] = encrypt(value) if private?
|
||||||
|
|
6
app/views/posts/attribute_ro/_password.haml
Normal file
6
app/views/posts/attribute_ro/_password.haml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
%tr{ id: attribute }
|
||||||
|
%th= post_label_t(attribute, post: post)
|
||||||
|
%td{ dir: dir, lang: locale }
|
||||||
|
= metadata.value
|
||||||
|
%br/
|
||||||
|
%small= t('.safety')
|
7
app/views/posts/attributes/_password.haml
Normal file
7
app/views/posts/attributes/_password.haml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
.form-group
|
||||||
|
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
|
||||||
|
= password_field base, attribute, value: metadata.value,
|
||||||
|
dir: dir, lang: locale,
|
||||||
|
**field_options(attribute, metadata)
|
||||||
|
= render 'posts/attribute_feedback',
|
||||||
|
post: post, attribute: attribute, metadata: metadata
|
|
@ -443,6 +443,8 @@ en:
|
||||||
attribute_ro:
|
attribute_ro:
|
||||||
file:
|
file:
|
||||||
download: Download file
|
download: Download file
|
||||||
|
password:
|
||||||
|
safety: Passwords are stored safely
|
||||||
show:
|
show:
|
||||||
front_matter: Post metadata
|
front_matter: Post metadata
|
||||||
submit:
|
submit:
|
||||||
|
|
|
@ -451,6 +451,8 @@ es:
|
||||||
attribute_ro:
|
attribute_ro:
|
||||||
file:
|
file:
|
||||||
download: Descargar archivo
|
download: Descargar archivo
|
||||||
|
password:
|
||||||
|
safety: Las contraseñas se almacenan de forma segura
|
||||||
show:
|
show:
|
||||||
front_matter: Metadatos del artículo
|
front_matter: Metadatos del artículo
|
||||||
submit:
|
submit:
|
||||||
|
|
Loading…
Reference in a new issue