-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
edaa61d
commit 27d34e0
Showing
10 changed files
with
150 additions
and
3 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
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
56 changes: 56 additions & 0 deletions
56
WonderLab/ViewModels/Dialog/Auth/YggdrasilAuthDialogViewModel.cs
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Avalonia.Controls.Notifications; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using CommunityToolkit.Mvvm.Messaging; | ||
using DialogHostAvalonia; | ||
using System.Linq; | ||
using WonderLab.Infrastructure.Models.Messaging; | ||
using WonderLab.Services.Accounts; | ||
|
||
namespace WonderLab.ViewModels.Dialog.Auth; | ||
|
||
public sealed partial class YggdrasilAuthDialogViewModel : ObservableObject { | ||
private readonly AccountService _accountService; | ||
|
||
[ObservableProperty] private bool _isUseLittleSkin; | ||
|
||
[ObservableProperty] | ||
[NotifyCanExecuteChangedFor(nameof(SaveCommand))] | ||
private string _email; | ||
|
||
[ObservableProperty] | ||
[NotifyCanExecuteChangedFor(nameof(SaveCommand))] | ||
private string _password; | ||
|
||
[ObservableProperty] | ||
[NotifyCanExecuteChangedFor(nameof(SaveCommand))] | ||
private string _yggdrasilServerUrl; | ||
|
||
public YggdrasilAuthDialogViewModel(AccountService accountService) { | ||
_accountService = accountService; | ||
} | ||
|
||
private bool CanSave() => !string.IsNullOrEmpty(Email) && !string.IsNullOrEmpty(Password) && !string.IsNullOrEmpty(YggdrasilServerUrl); | ||
|
||
partial void OnIsUseLittleSkinChanged(bool value) { | ||
YggdrasilServerUrl = value ? "https://littleskin.cn/api/yggdrasil" : string.Empty; | ||
} | ||
|
||
[RelayCommand] | ||
private void Close() { | ||
DialogHost.Close("PART_DialogHost"); | ||
} | ||
|
||
[RelayCommand(CanExecute = nameof(CanSave))] | ||
private void Save() { | ||
var accounts = _accountService.CreateYggdrasilAccounts(Email, Password, YggdrasilServerUrl) | ||
.ToList(); | ||
|
||
Close(); | ||
|
||
if (accounts is { Count: 0 }) { | ||
WeakReferenceMessenger.Default.Send(new NotificationMessage($"已存在用户名为的离线账户!", NotificationType.Warning)); | ||
return; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="WonderLab.Views.Dialog.Auth.YggdrasilAuthDialog"> | ||
<Grid Margin="16 24 16 0" | ||
RowDefinitions="Auto, Auto, Auto"> | ||
<TextBlock Classes="Subtitle" | ||
Text="创建新账户"/> | ||
|
||
<StackPanel Grid.Row="1" | ||
Spacing="8" | ||
MinWidth="550" | ||
Margin="0 16 0 24"> | ||
<TextBox Watermark="Yggdrasil 服务器地址(例:https://littleskin.cn/api/yggdrasil)" | ||
IsEnabled="{Binding IsUseLittleSkin, Converter={StaticResource BooleanReverseConverter}}" | ||
Text="{Binding YggdrasilServerUrl}"/> | ||
|
||
<TextBox Watermark="电子邮箱" | ||
Text="{Binding Email}"/> | ||
|
||
<TextBox Watermark="密码" | ||
Text="{Binding UserName}"/> | ||
|
||
<CheckBox FontSize="14" | ||
FontWeight="Regular" | ||
IsChecked="{Binding IsUseLittleSkin}" | ||
Content="使用 LittleSkin 进行验证"/> | ||
</StackPanel> | ||
|
||
<Border Grid.Row="2" | ||
Padding="16" | ||
Margin="-16 0" | ||
CornerRadius="0 0 12 12" | ||
BorderThickness="0 1.5 0 0" | ||
Background="{DynamicResource ContentColor2}" | ||
BorderBrush="{DynamicResource ContentColor3}"> | ||
<Grid HorizontalAlignment="Right" | ||
ColumnDefinitions="Auto, Auto"> | ||
<Button Grid.Column="0" | ||
Margin="0 0 8 0" | ||
Content="取消" | ||
Command="{Binding CloseCommand}"/> | ||
|
||
<Button Grid.Column="1" | ||
Content="保存" | ||
Command="{Binding SaveCommand}"/> | ||
</Grid> | ||
</Border> | ||
</Grid> | ||
</UserControl> |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace WonderLab.Views.Dialog.Auth; | ||
|
||
public partial class YggdrasilAuthDialog : UserControl | ||
{ | ||
public YggdrasilAuthDialog() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
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