123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System.Threading.Tasks;
- using HyperCube.Models;
- using HyperCube;
- namespace HyperCube.Pages
- {
- public partial class Wallet
- {
- private AccountModel account = new();
- string myBalance = "";
- protected override async Task OnInitializedAsync()
- {
- account = await GetCurrentAcc();
- if (Blockchain.GetMain() != null)
- myBalance = await account.GetBalance();
- }
- private async Task<AccountModel> GetCurrentAcc()
- {
- AccountModel account = new();
- var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
- var user = authState.User;
- if (user.Identity.IsAuthenticated)
- {
- var currentUser = await UserManager.GetUserAsync(user);
- var acc = AccountModel.Find(currentUser.Id);
- if (acc != null)
- account = acc;
- account.LoadRoles();
- return account;
- }
- return null;
- }
- bool admin
- {
- get { return account.Roles.Contains(Role.Admin); }
- set
- {
- if (!account.Roles.Contains(Role.Admin))
- {
- account.AddRole(Role.Admin);
- InsertRole(Role.Admin);
- }
- else
- {
- account.RemoveRole(Role.Admin);
- DeleteRole(Role.Admin);
- }
- }
- }
- bool initiator
- {
- get { return account.Roles.Contains(Role.Initiator); }
- set
- {
- if (!account.Roles.Contains(Role.Initiator))
- {
- account.AddRole(Role.Initiator);
- InsertRole(Role.Initiator);
- }
- else
- {
- account.RemoveRole(Role.Initiator);
- DeleteRole(Role.Initiator);
- }
- }
- }
- bool verifier
- {
- get { return account.Roles.Contains(Role.Verifier); }
- set
- {
- if (!account.Roles.Contains(Role.Verifier))
- {
- account.AddRole(Role.Verifier);
- InsertRole(Role.Verifier);
- }
- else
- {
- account.RemoveRole(Role.Verifier);
- DeleteRole(Role.Verifier);
- }
- }
- }
- bool requester
- {
- get { return account.Roles.Contains(Role.Requester); }
- set
- {
- if (!account.Roles.Contains(Role.Requester))
- {
- account.AddRole(Role.Requester);
- InsertRole(Role.Requester);
- }
- else
- {
- account.RemoveRole(Role.Requester);
- DeleteRole(Role.Requester);
- }
- }
- }
- void InsertRole(Role role)
- {
- MySQLConnector.Instance().SQLInsert($"insert into account_roles (account_uuid, role_id) values ('{account.UUID}', {(int)role})");
- }
- void DeleteRole(Role role)
- {
- MySQLConnector.Instance().SQLInsert($"delete from account_roles where account_uuid = '{account.UUID}' and role_id={(int)role}");
- }
- }
- }
|