-
Notifications
You must be signed in to change notification settings - Fork 0
Develop #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Develop #5
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| using System.IO; | ||
| using System.Security.Cryptography; | ||
| using System.Text; | ||
|
|
||
| namespace FinTrack.Core | ||
| { | ||
| public class SecureTokenStorage | ||
| { | ||
| private readonly string _filePath; | ||
|
|
||
| private static readonly byte[] s_entropy = Encoding.UTF8.GetBytes("E5A3B8B8_4A8C_4F1D_9F0B_2B3A7F9C1D0E"); // [TEST] | ||
|
|
||
| public SecureTokenStorage() | ||
| { | ||
| var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); | ||
| var appFolder = Path.Combine(appDataPath, "FinTrack"); | ||
| Directory.CreateDirectory(appFolder); | ||
| _filePath = Path.Combine(appFolder, "user.token"); | ||
| } | ||
|
|
||
| public void SaveToken(string token) | ||
| { | ||
| if (string.IsNullOrEmpty(token)) | ||
| throw new ArgumentException("Token cannot be null or empty.", nameof(token)); | ||
|
|
||
| try | ||
| { | ||
| var encryptedToken = ProtectedData.Protect(Encoding.UTF8.GetBytes(token), s_entropy, DataProtectionScope.CurrentUser); | ||
| File.WriteAllBytes(_filePath, encryptedToken); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine($"Error saving token: {ex.Message}"); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| public string? GetToken() | ||
| { | ||
| if (!File.Exists(_filePath)) | ||
| return null; | ||
|
|
||
| try | ||
| { | ||
| var encryptedBytes = File.ReadAllBytes(_filePath); | ||
| var tokenBytes = ProtectedData.Unprotect(encryptedBytes, s_entropy, DataProtectionScope.CurrentUser); | ||
| return Encoding.UTF8.GetString(tokenBytes); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine($"Error retrieving token: {ex.Message}"); | ||
| ClearToken(); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| public void ClearToken() | ||
| { | ||
| if (File.Exists(_filePath)) | ||
| { | ||
| try | ||
| { | ||
| File.Delete(_filePath); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine($"Error clearing token: {ex.Message}"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using CommunityToolkit.Mvvm.ComponentModel; | ||
|
|
||
| namespace FinTrack.ViewModels | ||
| { | ||
| public partial class HomeViewModel : ObservableObject | ||
| { | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -28,6 +28,19 @@ public partial class LoginViewModel : ObservableObject | |
| public LoginViewModel() | ||
| { | ||
| _authService = new AuthService(); | ||
|
|
||
| RegisteredTokenLogin(); | ||
| } | ||
|
|
||
| private void RegisteredTokenLogin() | ||
| { | ||
| SecureTokenStorage secureTokenStorage = new SecureTokenStorage(); | ||
| string? token = secureTokenStorage.GetToken(); | ||
| if (!string.IsNullOrEmpty(token)) | ||
| { | ||
| SessionManager.SetToken(token); | ||
| MessageBox.Show("Giriş başarılı! Token kullanıldı.", "Bilgi", MessageBoxButton.OK, MessageBoxImage.Information); | ||
|
||
| } | ||
| } | ||
|
|
||
| [RelayCommand] | ||
|
|
@@ -45,7 +58,12 @@ private async Task Login_LoginView_Button() | |
| MessageBox.Show("Giriş başarısız oldu. Lütfen e-posta ve şifrenizi kontrol edin.", "Hata", MessageBoxButton.OK, MessageBoxImage.Error); | ||
| return; | ||
| } | ||
|
|
||
| SessionManager.SetToken(token); | ||
|
|
||
| SecureTokenStorage secureTokenStorage = new SecureTokenStorage(); | ||
| secureTokenStorage.SaveToken(token); | ||
|
|
||
| MessageBox.Show("Giriş başarılı!", "Bilgi", MessageBoxButton.OK, MessageBoxImage.Information); | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider replacing Console.WriteLine with a proper logging framework to improve error tracking and maintainability in production environments.