sticapi_client 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sticapi_client/sticapi_devise_strategy.rb +14 -3
- data/lib/sticapi_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 96923b65d26e328930491c4a94a14d34e70a56322cbfd192c5f3120d2e8d5691
|
|
4
|
+
data.tar.gz: 8963340be8db1c64c43b9ca8fee6b06711e6a6648c3d37cf429778cc38cd3183
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '04593a147f4e05765d4d726c988aeb0cbedd37b2804f3482a8249e99254bf7f601cd21e6626372afce3ab1c03e8d4f77e5c1844b52128c6b4fbe740c3a724dfa'
|
|
7
|
+
data.tar.gz: 0ca9e42d7dc19c74a88a87a73bc31e391d057ddf2a4b33240ab317c7883733cbd3462ed07b019a9a6b3bec4684dcd408ed632c41198c54f0573d4593d3ea7ace
|
|
@@ -38,17 +38,28 @@ module Devise
|
|
|
38
38
|
data = Sticapi::SticapiClient.instance.sticapi_request("/users/log_in", data: token)
|
|
39
39
|
|
|
40
40
|
if data && data['user']
|
|
41
|
-
|
|
41
|
+
# 1. Busca o usuário ou cria uma nova instância se não existir
|
|
42
|
+
user = User.find_by(username: data['user']['username'])
|
|
43
|
+
is_new_user = user.nil?
|
|
44
|
+
|
|
45
|
+
if is_new_user
|
|
42
46
|
user = User.new
|
|
43
47
|
user.name = data['user']['name'] if user.respond_to? :name
|
|
44
48
|
user.username = data['user']['username'] if user.respond_to? :username
|
|
45
49
|
user.email = data['user']['email']
|
|
46
50
|
user.cpf = data['user']['cpf'] if user.respond_to? :cpf
|
|
51
|
+
|
|
52
|
+
# Define a senha APENAS para novos usuários criados localmente
|
|
53
|
+
user.password = params[:user][:password] if user.respond_to? :password
|
|
54
|
+
user.password_confirmation = params[:user][:password] if user.respond_to? :password_confirmation
|
|
47
55
|
end
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
|
|
57
|
+
# 2. Atualiza outros dados que podem mudar dinamicamente da API externa, sem tocar na senha
|
|
50
58
|
user.unities = data['user']['unities'] if user.respond_to? :unities
|
|
51
59
|
user.skip_confirmation! if user.respond_to? 'skip_confirmation!'
|
|
60
|
+
|
|
61
|
+
# 3. Se for um usuário antigo, você pode apenas salvar se os dados mudaram,
|
|
62
|
+
# ou forçar o save se unities mudou. Como a senha não muda, o encrypted_password continua igual!
|
|
52
63
|
if user.save
|
|
53
64
|
remember_me(user)
|
|
54
65
|
success!(user)
|