-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
47 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,37 @@ | ||
package app | ||
|
||
import ( | ||
"encoding/base64" | ||
|
||
"github.com/passwall/passwall-server/internal/storage" | ||
"github.com/passwall/passwall-server/model" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// CreateEmail creates a new bank account and saves it to the store | ||
func CreateEmail(s storage.Store, dto *model.EmailDTO, schema string) (*model.Email, error) { | ||
rawModel := model.ToEmail(dto) | ||
encModel := EncryptModel(rawModel) | ||
|
||
rawPass := dto.Password | ||
dto.Password = base64.StdEncoding.EncodeToString(Encrypt(dto.Password, viper.GetString("server.passphrase"))) | ||
|
||
createdEmail, err := s.Emails().Save(model.ToEmail(dto), schema) | ||
createdEmail, err := s.Emails().Save(encModel.(*model.Email), schema) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
createdEmail.Password = rawPass | ||
|
||
return createdEmail, nil | ||
} | ||
|
||
// UpdateEmail updates the account with the dto and applies the changes in the store | ||
func UpdateEmail(s storage.Store, email *model.Email, emailDTO *model.EmailDTO, schema string) (*model.Email, error) { | ||
func UpdateEmail(s storage.Store, email *model.Email, dto *model.EmailDTO, schema string) (*model.Email, error) { | ||
rawModel := model.ToEmail(dto) | ||
encModel := EncryptModel(rawModel).(*model.Email) | ||
|
||
rawPass := emailDTO.Password | ||
emailDTO.Password = base64.StdEncoding.EncodeToString(Encrypt(emailDTO.Password, viper.GetString("server.passphrase"))) | ||
|
||
email.ID = uint(email.ID) | ||
email.Title = emailDTO.Title | ||
email.Email = emailDTO.Email | ||
email.Password = emailDTO.Password | ||
email.Title = encModel.Title | ||
email.Email = encModel.Email | ||
email.Password = encModel.Password | ||
|
||
updatedEmail, err := s.Emails().Save(email, schema) | ||
if err != nil { | ||
|
||
return nil, err | ||
} | ||
|
||
updatedEmail.Password = rawPass | ||
return updatedEmail, nil | ||
} | ||
|
||
// DecryptEmailPassword decrypts password | ||
func DecryptEmailPassword(s storage.Store, account *model.Email) (*model.Email, error) { | ||
passByte, _ := base64.StdEncoding.DecodeString(account.Password) | ||
account.Password = string(Decrypt(string(passByte[:]), viper.GetString("server.passphrase"))) | ||
|
||
return account, nil | ||
} | ||
|
||
// DecryptEmailPasswords ... | ||
// TODO: convert to pointers | ||
func DecryptEmailPasswords(emails []model.Email) []model.Email { | ||
for i := range emails { | ||
if emails[i].Password == "" { | ||
continue | ||
} | ||
passByte, _ := base64.StdEncoding.DecodeString(emails[i].Password) | ||
passB64 := string(Decrypt(string(passByte[:]), viper.GetString("server.passphrase"))) | ||
emails[i].Password = passB64 | ||
} | ||
return emails | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters