コード例 #1
0
        public IActionResult Login(UserModel um)
        {
            var users = userService.GetAllUsers();

            foreach (var user in users)
            {
                if (um.Login == user.Login)
                {
                    if (um.Password == user.Password)
                    {
                        activeUser = user;
                        var data = Encoding.UTF8.GetBytes($"{um.Login},{um.Password}");
                        this.HttpContext.Session.Set("user", data);
                    }
                }
            }
            if (activeUser != null)
            {
                um = activeUser;
            }
            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(Login());
        }
コード例 #2
0
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        _settings = _appSettings !.Value;
        var errors = new List <string>();

        MainLayout !.CloseMenu();
        _user = await _authenticationService !.LoggedInUserAsync();
        if (string.IsNullOrWhiteSpace(OfferIdString) || !int.TryParse(OfferIdString, out var offerid) || offerid <= 0)
        {
            errors.Add(string.Format(Strings.Invalid, "offer id"));
        }
        else
        {
            _offer = await _offerService !.ReadAsync(offerid);
            if (_offer is not null)
            {
                _quantity = _offer.Quantity;
            }
            else
            {
                errors.Add(string.Format(Strings.NotFound, "offer", "id", offerid));
            }
        }
        _errors = errors.ToArray();
    }
コード例 #3
0
ファイル: CreateOffer.razor.cs プロジェクト: vjkrammes/Beans
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        MainLayout !.CloseMenu();
        _user        = await _authenticationService !.LoggedInUserAsync();
        _oldestFirst = _settings !.Value.OldestFirst;
        var beans = (await _beanService !.GetAsync()).ToList();

        _beans = new();
        foreach (var bean in beans)
        {
            var model = new SellBeanModel
            {
                Id         = bean.Id,
                Name       = bean.Name,
                Price      = bean.Price,
                MyHoldings = await _holdingService !.BeansHeldByUserAndBeanAsync(_user !.Id, bean.Id),
                Selected   = false
            };
            _beans.Add(model);
        }
        _selectedBean = _beans.FirstOrDefault();
        await LoadHoldings();

        _quantity = 0;
        _price    = 0M;
        _days     = 30;
        StateHasChanged();
    }
コード例 #4
0
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        MainLayout !.CloseMenu();
        _user = (await _authenticationService !.LoggedInUserAsync()) !;
        await LoadNotices(_user?.Id ?? 0);
    }
コード例 #5
0
        public IActionResult Logout()
        {
            activeUser = null;
            var data = Encoding.UTF8.GetBytes("");

            this.HttpContext.Session.Set("user", data);
            return(RedirectToAction("Login", "Home"));
        }
コード例 #6
0
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        MainLayout !.CloseMenu();
        _user     = await _authenticationService !.LoggedInUserAsync();
        _settings = await _settingsService !.SettingsAsync();
    }
コード例 #7
0
ファイル: TempBanCommand.cs プロジェクト: mwerschy/Silk
        public async Task TempBan(
            CommandContext ctx, DiscordMember user, string duration,
            [RemainingText] string reason = "Not provided.")
        {
            SilkDbContext       db          = DbFactory.CreateDbContext();
            DiscordMember       bot         = ctx.Guild.CurrentMember;
            DateTime            now         = DateTime.Now;
            TimeSpan            banDuration = GetTimeFromInput(duration);
            BanFailureReason?   banFailed   = CanBan(bot, ctx.Member, user);
            DiscordEmbedBuilder embed       =
                new DiscordEmbedBuilder().WithAuthor(bot.Username, ctx.GetBotUrl(), ctx.Client.CurrentUser.AvatarUrl);

            if (banFailed is not null)
            {
                await SendFailureMessage(ctx, user, embed, banFailed);
            }
            else
            {
                DiscordEmbedBuilder banEmbed = new DiscordEmbedBuilder()
                                               .WithAuthor(ctx.User.Username, ctx.User.GetUrl(), ctx.User.AvatarUrl)
                                               .WithDescription($"You've been temporarily banned from {ctx.Guild.Name} for {duration} days.")
                                               .AddField("Reason:", reason);

                await user.SendMessageAsync(embed : banEmbed);

                await ctx.Guild.BanMemberAsync(user, 0, reason);

                GuildModel guild = db.Guilds.First(g => g.Id == ctx.Guild.Id);

                UserModel?bannedUser         = db.Users.FirstOrDefault(u => u.Id == user.Id);
                string    formattedBanReason = InfractionFormatHandler.ParseInfractionFormat("temporarily banned",
                                                                                             banDuration.TotalDays + " days", user.Mention, reason, guild.Configuration.InfractionFormat ?? defaultFormat);
                UserInfractionModel infraction = CreateInfraction(formattedBanReason, ctx.User.Id, now);
                if (bannedUser is null)
                {
                    bannedUser = new UserModel
                    {
                        Infractions = new List <UserInfractionModel>()
                    };
                    db.Users.Add(bannedUser);
                    bannedUser.Infractions.Add(infraction);
                }

                if (guild.Configuration.GeneralLoggingChannel != default)
                {
                    embed.WithDescription(formattedBanReason);
                    embed.WithColor(DiscordColor.Green);
                    await ctx.Guild.GetChannel(guild.Configuration.GeneralLoggingChannel).SendMessageAsync(embed: embed);
                }

                EventService.Events.Add(new TimedInfraction(user.Id, ctx.Guild.Id, DateTime.Now.Add(banDuration),
                                                            reason, e => _ = OnBanExpiration((TimedInfraction)e)));
            }
        }
コード例 #8
0
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        MainLayout !.CloseMenu();
        _user = await _authenticationService !.LoggedInUserAsync();
        await LoadBeans();
        await LoadHoldings();

        StateHasChanged();
    }
コード例 #9
0
 public OrderModel(
     int id,
     OrderStatusModel status,
     DateTime orderTime,
     MarketplaceItemModel itemId,
     UserModel?recipient
     ) : base(id, status, orderTime)
 {
     Recipient = recipient;
     Item      = itemId;
 }
コード例 #10
0
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        MainLayout !.CloseMenu();
        _user = (await _authenticationService !.LoggedInUserAsync()) !;
        await LoadMyOffers(_user.Id);

        _offers  = (await _offerService !.GetOtherOffersAsync(_user.Id)).ToList();
        _mySales = (await _saleService !.GetForUserAsync(_user.Id)).ToList();
        StateHasChanged();
    }
コード例 #11
0
    private async Task BuyClick(bool small, int id)
    {
        _errors = Array.Empty <string>();
        var errors = new List <string>();

        if (id > 0)
        {
            var inputname      = IdCreator(small ? _smallBuyQuantity : _largeBuyQuantity, id);
            var quantitystring = await _jSRuntime !.InvokeAsync <string>("beans.getValue", inputname);
            if (string.IsNullOrWhiteSpace(quantitystring) || !long.TryParse(quantitystring, out var quantity) || quantity <= 0)
            {
                errors.Add(string.Format(Strings.Invalid, "quantity"));
            }
            else
            {
                var bean = _beans !.SingleOrDefault(x => x.Id == id);
                if (bean is null)
                {
                    errors.Add(String.Format(Strings.NotFound, "bean", "id", id));
                }
                else
                {
                    if (quantity > bean.Outstanding)
                    {
                        errors.Add(string.Format(Strings.NotEnoughBeans, bean.Name));
                    }
                    else if (quantity * bean.Price > _user !.Balance)
                    {
                        errors.Add(string.Format(Strings.NSF, bean.Name, bean.Price.ToCurrency(2)));
                    }
                    else
                    {
                        var result = await _beanService !.BuyFromExchangeAsync(_user.Id, id, quantity);
                        if (result.Successful)
                        {
                            await _jSRuntime !.InvokeVoidAsync("beans.clearValue", inputname);
                            var   parameters = new DialogParameters
                            {
                                { "Title", "Purchase Complete" },
                                { "Message", string.Format(Strings.PurchaseComplete, quantity, bean.Name) }
                            };
                            await _dialogService !.Show <GenericDialog>(string.Empty, parameters).Result;
                            _user = await _authenticationService !.LoggedInUserAsync();
                            await LoadBeans();
                            await LoadHoldings();
                        }
                        else
                        {
                            errors.AddRange(result.Errors());
                        }
                    }
                }
コード例 #12
0
ファイル: OfferModel.cs プロジェクト: vjkrammes/Beans
 public OfferModel() : base()
 {
     Id             = 0;
     UserId         = 0;
     BeanId         = 0;
     Quantity       = 0;
     Price          = 0M;
     Buy            = false;
     OfferDate      = default;
     ExpirationDate = default;
     Bean           = null;
     User           = null;
 }
コード例 #13
0
        public async Task Cases(CommandContext ctx, DiscordUser user)
        {
            var mBuilder = new DiscordMessageBuilder();
            var eBuilder = new DiscordEmbedBuilder();

            UserModel?userModel = await _dbService.GetGuildUserAsync(ctx.Guild.Id, user.Id);

            if (userModel is null || !userModel.Infractions.Any())
            {
                mBuilder.WithReply(ctx.Message.Id);
                mBuilder.WithContent("User has no cases!");
                await ctx.RespondAsync(mBuilder);
            }
        }
コード例 #14
0
    protected async override Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        MainLayout !.CloseMenu();
        _user = await _authenticationService !.LoggedInUserAsync() !;
        _holdingDictionary = new();
        _beans             = new();
        var beanids = (await _beanService !.BeanIdsAsync()).OrderBy(x => x).ToList();

        if (beanids is not null && beanids.Any())
        {
            foreach (var id in beanids)
            {
                _beans.Add((await _beanService !.ReadAsync(id)) !);
                var holdings = (await _holdingService !.GetForBeanAsync(_user !.Id, id)).ToList();
                if (holdings is not null && holdings.Any())
                {
                    _holdingDictionary.Add(id, holdings);
                }
            }
        }
        if (string.IsNullOrWhiteSpace(BeanIdString) || !int.TryParse(BeanIdString, out var beanid) || beanid <= 0)
        {
            beanid = _holdingDictionary.Keys.First();
        }
        _currentBean     = beanid;
        _currentBeanName = _beans.Single(x => x.Id == _currentBean).Name;
        if (_holdingDictionary.ContainsKey(beanid))
        {
            _holdings = _holdingDictionary[beanid];
        }
        else
        {
            _holdings = _holdingDictionary.Any() ? _holdingDictionary[_holdingDictionary.Keys.First()] : new();
        }
    }
コード例 #15
0
ファイル: Profile.razor.cs プロジェクト: vjkrammes/Beans
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        MainLayout !.CloseMenu();
        _user     = (await _authenticationService !.LoggedInUserAsync()) !;
        _holdings = new();
        var beans = await _beanService !.GetAsync();

        foreach (var bean in beans)
        {
            var holdings = await _holdingService !.GetForBeanAsync(_user.Id, bean.Id);
            if (holdings.Any())
            {
                _holdings.Add(new(bean, holdings));
            }
        }
        _offers        = (await _offerService !.GetForUserAsync(_user.Id)).ToList();
        _sales         = (await _saleService !.GetForUserAsync(_user.Id, _days)).ToList();
        _holdingsValue = await _holdingService !.TotalValueAsync(_user.Id);
        _holdingsCost  = await _holdingService !.TotalCostAsync(_user.Id);
        _return        = _holdingsValue - _holdingsCost;
        _returnPercent = _holdingsCost == 0M ? 0.0 : (double)(_return / _holdingsCost);
    }
コード例 #16
0
        public async Task <IActionResult> GetAsync(int userId)
        {
            UserModel?res = await UserTable.GetUserById(_dbConnection, userId);

            return(res == null?NotFound() : (IActionResult)Ok(res));
        }
コード例 #17
0
 public bool Equals(UserModel?model) => model is not null && model.Id == Id;
コード例 #18
0
 public int CompareTo(UserModel?other) => Email.CompareTo(other?.Email);